* Add Profiles::Update service object * Refactor * Rename Profile.fields to Profile.attributes * Keep sync from user -> profile * And and update comments * Rename Profile.refresh_store_accessors! * Make forwarding getters in user dynamic * Add more explanation * Fix typo * Update service object * Fix return value * Fix specs * Travis, let's be friends again? * Remove Travis change * Add require_dependency in Profile * Refactor * More refactoring * Avoid double sync * Fix specs * Fix mapped attributes sync
42 lines
1.3 KiB
Ruby
42 lines
1.3 KiB
Ruby
class Profile < ApplicationRecord
|
|
belongs_to :user
|
|
|
|
validates :user_id, uniqueness: true
|
|
|
|
# NOTE: @citizen428 This is a temporary mapping so we don't break DEV during
|
|
# profile migration/generalization work.
|
|
MAPPED_ATTRIBUTES = {
|
|
brand_color1: :bg_color_hex,
|
|
brand_color2: :text_color_hex,
|
|
display_email_on_profile: :email_public,
|
|
display_looking_for_work_on_profile: :looking_for_work_publicly,
|
|
git_lab_url: :gitlab_url,
|
|
linked_in_url: :linkedin_url,
|
|
recruiters_can_contact_me_about_job_opportunities: :contact_consent,
|
|
stack_overflow_url: :stackoverflow_url
|
|
}.with_indifferent_access.freeze
|
|
|
|
# Generates typed accessors for all currently defined profile fields.
|
|
def self.refresh_attributes!
|
|
ProfileField.find_each do |field|
|
|
store_attribute :data, field.attribute_name, field.type
|
|
end
|
|
end
|
|
|
|
# Returns an array of all currently defined `store_attribute`s on `data`.
|
|
def self.attributes
|
|
stored_attributes[:data] || []
|
|
end
|
|
|
|
# Forces a reload before returning attributes
|
|
def self.attributes!
|
|
refresh_attributes!
|
|
attributes
|
|
end
|
|
|
|
# NOTE: @citizen428 This is a temporary mapping so we don't break DEV during
|
|
# profile migration/generalization work.
|
|
def self.mapped_attributes
|
|
attributes!.map { |attribute| MAPPED_ATTRIBUTES.fetch(attribute, attribute).to_s }
|
|
end
|
|
end
|