lib/eco/api/common/people/person_attribute_parser.rb in eco-helpers-2.6.4 vs lib/eco/api/common/people/person_attribute_parser.rb in eco-helpers-2.7.0
- old
+ new
@@ -1,13 +1,11 @@
module Eco
module API
module Common
module People
-
# Class to define a parser/serializer.
class PersonAttributeParser < Eco::Language::Models::ParserSerializer
-
# @note
# - This was introduced at a later stage and might not be available for certain org-parsers configs
# @return [RequiredAttrs]
def required_attrs
@required_attrs ||= @dependencies[:required_attrs]
@@ -49,51 +47,49 @@
# @return [Boolean] `true` if there's serializer defined.
def serializer_active?(phase = :any)
(phase == :any) || serializer_category?(phase)
end
-
# Helper to build the `active_when` condition.
def active_when_any?(*attrs)
- Proc.new do |source_data|
+ proc do |source_data|
keys = data_keys(source_data)
attrs.any? {|key| keys.include?(key)}
end
end
# Helper to build the `active_when` condition.
def active_when_all?(*attrs)
- Proc.new do |source_data|
+ proc do |source_data|
keys = data_keys(source_data)
attrs.all? {|key| keys.include?(key)}
end
end
private
# By default, an attribute paraser is active if in the entry to parse
# the internal attribute is present
def attribute_present(active_when)
- Proc.new do |source_data|
- data_keys(source_data).include?(self.attr) ||
- (active_when && active_when.call(source_data))
+ proc do |source_data|
+ data_keys(source_data).include?(self.attr) || # rubocop:disable Style/RedundantSelf
+ active_when&.call(source_data)
end
end
# Helper to obtain the current internal named attributes of the data
# @param source_data [Array<String>, Hash] if `Array` those are already the `keys`, if `Hash` it gets the `keys`
# @return [Array<String>] `keys` of `source_data`
def data_keys(source_data)
case source_data
when Array
- keys = source_data
+ source_data
when Hash
- keys = source_data.keys
+ source_data.keys
else
- keys = []
+ []
end
end
-
end
end
end
end
end