class Eco::API::Common::People::PersonAttributeParser
Class to define a parser/serializer.
def active_when_all?(*attrs)
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)
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)
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)
-
(Array- `keys` of `source_data`)
Parameters:
-
source_data(Array) -- if `Array` those are already the `keys`,, Hash
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)
-
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)
-
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)
-
(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
-
(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)
-
(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