Class: AMA::Entity::Mapper::Handler::Entity::Injector

Inherits:
Object
  • Object
show all
Extended by:
Mixin::Reflection
Includes:
Mixin::Reflection
Defined in:
lib/ama-entity-mapper/handler/entity/injector.rb

Overview

Default attribute injector

Constant Summary collapse

INSTANCE =
new

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Reflection

install_object_method, method_object, object_variable, object_variable_exists, object_variables, set_object_attribute

Methods included from Mixin::Errors

#compliance_error, #mapping_error, #raise_if_internal, #validation_error

Class Method Details

.wrap(implementation) ⇒ Injector

Parameters:

Returns:



33
34
35
36
37
38
39
40
41
# File 'lib/ama-entity-mapper/handler/entity/injector.rb', line 33

def wrap(implementation)
  handler = handler_factory(implementation, INSTANCE)
  description = "Safety wrapper for #{implementation}"
  wrapper = method_object(:inject, to_s: description, &handler)
  wrapper.singleton_class.instance_eval do
    include Mixin::Errors
  end
  wrapper
end

Instance Method Details

#inject(entity, _type, attribute, value, _context = nil) ⇒ Object

Parameters:



22
23
24
25
26
# File 'lib/ama-entity-mapper/handler/entity/injector.rb', line 22

def inject(entity, _type, attribute, value, _context = nil)
  return entity if attribute.virtual
  set_object_attribute(entity, attribute.name, value)
  entity
end