class AMA::Entity::Mapper::Type::BuiltIn::EnumerableType
Default Enumerable handler
Constants
- INSTANCE
Public Class Methods
new()
click to toggle source
Calls superclass method
AMA::Entity::Mapper::Type::new
# File lib/ama-entity-mapper/type/builtin/enumerable_type.rb, line 16 def initialize super(::Enumerable) attribute!(:_value, parameter!(:T), virtual: true) define_factory define_normalizer define_denormalizer define_enumerator define_injector end
Private Instance Methods
define_denormalizer()
click to toggle source
# File lib/ama-entity-mapper/type/builtin/enumerable_type.rb, line 41 def define_denormalizer denormalizer_block do |data, type, context = nil, *| if data.is_a?(Hash) || !data.is_a?(Enumerable) message = "Can't denormalize Enumerable from #{data.class}" type.mapping_error(message, context: context) end data.map(&:itself) end end
define_enumerator()
click to toggle source
# File lib/ama-entity-mapper/type/builtin/enumerable_type.rb, line 51 def define_enumerator enumerator_block do |entity, type, *| ::Enumerator.new do |yielder| attribute = type.attributes[:_value] entity.each_with_index do |value, index| yielder << [attribute, value, Path::Segment.index(index)] end end end end
define_factory()
click to toggle source
# File lib/ama-entity-mapper/type/builtin/enumerable_type.rb, line 29 def define_factory factory_block do |*| [] end end
define_injector()
click to toggle source
# File lib/ama-entity-mapper/type/builtin/enumerable_type.rb, line 62 def define_injector injector_block do |entity, _, _, value, context| entity[context.path.current.name] = value end end
define_normalizer()
click to toggle source
# File lib/ama-entity-mapper/type/builtin/enumerable_type.rb, line 35 def define_normalizer normalizer_block do |input, *| input.map(&:itself) end end