Class: Eco::API::Common::People::DefaultParsers::PolicyGroupsParser

Inherits:
Loaders::Parser show all
Defined in:
lib/eco/api/common/people/default_parsers/policy_groups_parser.rb

Instance Method Summary collapse

Methods inherited from Loaders::Parser

active_when_all, active_when_any, #attribute, attribute, dependencies, #initialize, parsing_phase, #seralizer, serializing_phase

Methods inherited from Loaders::CaseBase

#name, name_only_once!

Methods inherited from Loaders::Base

<=>, created_at, #initialize, #name, set_created_at!

Methods included from ClassHelpers

#class_resolver, #descendants, #descendants?, #inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #resolve_class, #to_constant

Constructor Details

This class inherits a constructor from Eco::API::Common::Loaders::Parser

Instance Method Details

#parser(hash, deps) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/eco/api/common/people/default_parsers/policy_groups_parser.rb', line 5

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

#serializer(person, deps) ⇒ Object



14
15
16
17
18
19
# File 'lib/eco/api/common/people/default_parsers/policy_groups_parser.rb', line 14

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