Class: AMA::Entity::Mapper::Engine::RecursiveMapper
- Inherits:
-
Object
- Object
- AMA::Entity::Mapper::Engine::RecursiveMapper
- Includes:
- Mixin::Errors, Mixin::SuppressionSupport
- Defined in:
- lib/ama-entity-mapper/engine/recursive_mapper.rb
Overview
Recursively maps object to one of specified types
Instance Method Summary collapse
-
#initialize(registry) ⇒ RecursiveMapper
constructor
A new instance of RecursiveMapper.
- #map(source, types, context) ⇒ Object
- #map_type(source, type, ctx) ⇒ Object
Methods included from Mixin::Errors
#compliance_error, #mapping_error, #raise_if_internal, #validation_error
Methods included from Mixin::SuppressionSupport
Constructor Details
#initialize(registry) ⇒ RecursiveMapper
Returns a new instance of RecursiveMapper.
19 20 21 |
# File 'lib/ama-entity-mapper/engine/recursive_mapper.rb', line 19 def initialize(registry) @registry = registry end |
Instance Method Details
#map(source, types, context) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/ama-entity-mapper/engine/recursive_mapper.rb', line 26 def map(source, types, context) map_unsafe(source, types, context) rescue StandardError => e = "Failed to map #{source.class} " \ "to any of provided types (#{types.map(&:to_def).join(', ')}). " \ "Last error: #{e.message} in #{e.backtrace_locations[0]}" mapping_error() end |
#map_type(source, type, ctx) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ama-entity-mapper/engine/recursive_mapper.rb', line 39 def map_type(source, type, ctx) ctx.logger.debug("Mapping #{source.class} to type #{type.to_def}") source, reassembled = request_reassembly(source, type, ctx) epithet = reassembled ? 'reassembled' : 'source' if type.attributes.empty? = "#{type.to_def} has no attributes, " \ "returning #{epithet} instance" ctx.logger.debug() return source end process_attributes(source, type, ctx) end |