class Eco::API::Common::People::PersonAttributeParser

Class to define a parser/serializer.

def active_when_all?(*attrs)

Helper to build the `active_when` condition.
def active_when_all?(*attrs)
  proc do |source_data|
    keys = data_keys(source_data)
    attrs.all? {|key| keys.include?(key)}
  end
end

def active_when_any?(*attrs)

Helper to build the `active_when` condition.
def active_when_any?(*attrs)
  proc do |source_data|
    keys = data_keys(source_data)
    attrs.any? {|key| keys.include?(key)}
  end
end

def attribute_present(active_when)

the internal attribute is present
By default, an attribute paraser is active if in the entry to parse
def attribute_present(active_when)
  proc do |source_data|
    data_keys(source_data).include?(self.attr) || # rubocop:disable Style/RedundantSelf

      active_when&.call(source_data)
  end
end

def data_keys(source_data)

Returns:
  • (Array) - `keys` of `source_data`

Parameters:
  • source_data (Array, Hash) -- if `Array` those are already the `keys`,
def data_keys(source_data)
  case source_data
  when Array
    source_data
  when Hash
    source_data.keys
  else
    []
  end
end

def def_parser(phase = :internal, active_when: nil, &block)

Parameters:
  • active_when (Proc) -- that expects a list of internal attributes or the internal entry itself.
  • phase (Symbol) -- the phase when this parser should be active.

Other tags:
    Note: -

Other tags:
    See: Eco::Language::Models::ParserSerializer#def_parser -
def def_parser(phase = :internal, active_when: nil, &block)
  @active_when = attribute_present(active_when)
  super(phase, &block)
end

def def_serializer(phase = :person, &block)

Parameters:
  • phase (Symbol) -- the phase when this serializer should be active.
def def_serializer(phase = :person, &block)
  super(phase, &block)
end

def parser_active?(source_data, phase = :any)

Returns:
  • (Boolean) - `true` if there's parser defined and `source_data` activates it.

Parameters:
  • phase (Symbol) -- the phase when this parser should be active.
def parser_active?(source_data, phase = :any)
  (phase == :any || parser_category?(phase)) && @active_when.call(source_data)
end

def required_attrs

Returns:
  • (RequiredAttrs) -

Other tags:
    Note: -
def required_attrs
  @required_attrs ||= @dependencies[:required_attrs]
  #@required_attrs ||= RequiredAttrs.new(attr, :unknown, [attr])

end

def serializer_active?(phase = :any)

Returns:
  • (Boolean) - `true` if there's serializer defined.

Parameters:
  • phase (Symbol) -- the phase when this serializer should be active.
def serializer_active?(phase = :any)
  (phase == :any) || serializer_category?(phase)
end