require 'subj_models/concerns/comprising_external_id' require 'subj_models/services/values_checker' module SubjModels module OfficeContact include SubjModels::TypesSupport::ContactTypes include SubjModels::ValuesChecker def self.included(including_class) including_class.class_eval do include SubjModels::ComprisingExternalId enum contact_type: CONTACT_TYPES belongs_to :office belongs_to :manager validates :contact_type, inclusion: { in: contact_types.keys } scope :is_phone, -> { where(contact_type: PHONE) } scope :is_skype, -> { where(contact_type: SKYPE) } scope :is_address, -> { where(contact_type: ADDRESS) } scope :is_email, -> { where(contact_type: EMAIL) } scope :office_id, -> (office_id) { parent_id_scope("office", office_id) } end end def to_s id.to_s # TODO end def contact_type=(value) super(check_string_for_int(value)) end end end