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