Sha256: 2608c25c371096865986c926641672e2f0529ae5f6b19d658f0825de5cac30ca

Contents?: true

Size: 1013 Bytes

Versions: 11

Compression:

Stored size: 1013 Bytes

Contents

require 'subj_models/concerns/comprising_external_id'
require 'subj_models/services/values_checker'

module SubjModels

  module OfficeContactModule

    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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
subj_models-0.5.9 lib/subj_models/office_contact.rb
subj_models-0.5.8 lib/subj_models/office_contact.rb
subj_models-0.5.7 lib/subj_models/office_contact.rb
subj_models-0.5.6 lib/subj_models/office_contact.rb
subj_models-0.5.5 lib/subj_models/office_contact.rb
subj_models-0.5.4 lib/subj_models/office_contact.rb
subj_models-0.5.3 lib/subj_models/office_contact.rb
subj_models-0.5.2 lib/subj_models/office_contact.rb
subj_models-0.5.1 lib/subj_models/office_contact.rb
subj_models-0.4.3 lib/subj_models/office_contact.rb
subj_models-0.4.2 lib/subj_models/office_contact.rb