Class: AMA::Entity::Mapper::Engine::RecursiveNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/ama-entity-mapper/engine/recursive_normalizer.rb

Overview

Helper and self-explanatory engine class

Instance Method Summary collapse

Constructor Details

#initialize(registry) ⇒ RecursiveNormalizer

Returns a new instance of RecursiveNormalizer.

Parameters:



13
14
15
# File 'lib/ama-entity-mapper/engine/recursive_normalizer.rb', line 13

def initialize(registry)
  @registry = registry
end

Instance Method Details

#normalize(entity, ctx, type = nil) ⇒ Object

Parameters:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ama-entity-mapper/engine/recursive_normalizer.rb', line 20

def normalize(entity, ctx, type = nil)
  type ||= find_type(entity.class)
  target = entity
  ctx.logger.debug("Normalizing #{entity.class} as #{type.type}")
  if type.virtual
    message = "Type #{type.type} is virtual, skipping to attributes"
    ctx.logger.debug(message)
  else
    target = type.normalizer.normalize(entity, type, ctx)
  end
  target_type = find_type(target.class)
  process_attributes(target, target_type, ctx)
end