Sha256: 1343d296c24b74010f9494773d5b29ed74f9e86d630c32c3e798dfd2d5a82217

Contents?: true

Size: 1.64 KB

Versions: 40

Compression:

Stored size: 1.64 KB

Contents

module Eco
  module API
    module Common
      module People
        class PersonModifier < Eco::Language::Models::Modifier
          WITH_DETAILS = %i[contact details with_details schema with_schema].freeze
          NO_DETAILS   = %i[no_details only_account].freeze

          WITH_ACCOUNT = %i[user account with_account].freeze
          NO_ACCOUNT   = %i[no_account only_details].freeze

          INTERNAL_PERSON = %i[internal v0].freeze
          EXTERNAL_PERSON = %i[external v1].freeze

          def reset_add_account
            self < mode - (WITH_ACCOUNT | NO_ACCOUNT)
          end

          def no_details
            push(:no_details)
          end

          def add_account?
            mode.any? { |m| WITH_ACCOUNT.include?(m) }
          end

          def no_account?
            mode.any? { |m| NO_ACCOUNT.include?(m) }
          end

          def add_details?
            mode.any? { |m| WITH_DETAILS.include?(m) }
          end

          def no_details?
            mode.any? { |m| NO_DETAILS.include?(m) }
          end

          def internal?
            bool = mode.any? { |m| INTERNAL_PERSON.include?(m) }
            bool || !external?
          end

          def external?
            mode.any? { |m| EXTERNAL_PERSON.include?(m) }
          end

          protected

          def resolve_mode
            modifiers = to_a
            modifiers = resolve(modifiers, WITH_DETAILS | NO_DETAILS)
            modifiers = resolve(modifiers, WITH_ACCOUNT | NO_ACCOUNT)
            resolve(modifiers, INTERNAL_PERSON | EXTERNAL_PERSON)
          end
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.20 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.19 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.18 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.17 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.16 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.15 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.14 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.13 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.12 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.11 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.10 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.9 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.8 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.7 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.6 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.5 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.4 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.3 lib/eco/api/common/people/person_modifier.rb
eco-helpers-3.0.2 lib/eco/api/common/people/person_modifier.rb