Sha256: ec059cd92e8bd5139b870e933f1c7df539b9f37db10952a207417f2b414c43c6

Contents?: true

Size: 799 Bytes

Versions: 65

Compression:

Stored size: 799 Bytes

Contents

class Eco::API::Common::People::DefaultParsers::PolicyGroupsParser < Eco::API::Common::Loaders::Parser
  attribute "policy_group_ids"
  parsing_phase     :final

  def parser(hash, deps)
    policy_group_ids = hash["policy_group_ids"] || []
    policy_group_ids.map do |name|
      policy_groups.to_id(name&.downcase.strip)
    end.compact.tap do |pg_names|
      pg_names.push(default_id) if pg_names.empty?
    end
  end

  def serializer(person, deps)
    ids   = person&.account&.policy_group_ids || []
    ids.map do |id|
      policy_groups.to_name(id)
    end.compact
  end

  private

  def default_id
    @default_id    ||= policy_groups.to_id(config.people.default_usergroup)
  end

  def policy_groups
    @policy_groups ||= config.policy_groups
  end

end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
eco-helpers-2.0.42 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.41 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.40 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.39 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.38 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.37 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.36 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.35 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.34 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.33 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.32 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.31 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.30 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.29 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.28 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.27 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.26 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.25 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.24 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.23 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb