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.2.2 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.2.1 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.12 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.11 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.10 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.9 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.8 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.7 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.6 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.5 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.4 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.3 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.2 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.1.1 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.68 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.67 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.66 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.65 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.64 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.63 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb