class AMA::Entity::Mapper::Handler::Entity::Injector
Default attribute injector
Constants
- INSTANCE
Public Class Methods
wrap(implementation)
click to toggle source
@param [Injector] implementation @return [Injector]
# 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
Private Class Methods
handler_factory(impl, fallback)
click to toggle source
@param [Injector] impl @param [Injector] fallback @return [Injector]
# File lib/ama-entity-mapper/handler/entity/injector.rb, line 48 def handler_factory(impl, fallback) lambda do |entity, type, attr, val, ctx| begin impl.inject(entity, type, attr, val, ctx) do |e, t, a, v, c| fallback.inject(e, t, a, v, c) end rescue StandardError => e raise_if_internal(e) message = "Unexpected error from injector #{impl}" signature = '(entity, type, attr, val, ctx)' options = { parent: e, context: ctx, signature: signature } compliance_error(message, options) end end end
Public Instance Methods
inject(entity, _type, attribute, value, _context = nil)
click to toggle source
@param [Object] entity @param [AMA::Entity::Mapper::Type] _type @param [AMA::Entity::Mapper::Type::Attribute] attribute @param [Object] value @param [AMA::Entity::Mapper::Context] _context
# 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