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.22 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.21 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.19 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.18 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.0.17 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb