Class: Aws::Templates::Processor::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/templates/processor/registry.rb

Overview

Handler registry

Handler registries encapsulate differerent ways of transforming entities into domain-specific output. In nutshell, they are registries of Handler classes which are able to lookup proper Handler for a given entity.

Instance Method Summary collapse

Instance Method Details

#[](entity) ⇒ Object

Look-up the handler



52
53
54
55
# File 'lib/aws/templates/processor/registry.rb', line 52

def [](entity)
  return registry[entity] unless entity.is_a?(Module)
  registry[entity.name] || registry[entity]
end

#handler_for(entity) ⇒ Object

Try to look-up the handler



31
32
33
34
35
# File 'lib/aws/templates/processor/registry.rb', line 31

def handler_for(entity)
  handler = self[entity]
  raise "Handler is not found for #{entity}" unless handler
  handler.reduce
end

#include?(k) ⇒ Boolean Also known as: handler?

Check if handler exists

Returns:

  • (Boolean)


59
60
61
# File 'lib/aws/templates/processor/registry.rb', line 59

def include?(k)
  !self[k].nil?
end

#keysObject

All possible entity types



46
47
48
# File 'lib/aws/templates/processor/registry.rb', line 46

def keys
  registry.keys
end

#merge(recursive) ⇒ Object

Merge map with another recursive



39
40
41
42
43
# File 'lib/aws/templates/processor/registry.rb', line 39

def merge(recursive)
  raise "#{recursive} is not recursive" unless Utils.recursive?(recursive)
  recursive.keys.each { |k| register(k, recursive[k]) }
  self
end

#register(entity, handler) ⇒ Object

Register pair entity-handler

Invoked from inside of a Handler class at definition of the link between the handler class and an entity.

  • entity - entity the handler claims to be able to process

  • handler - handler class



25
26
27
# File 'lib/aws/templates/processor/registry.rb', line 25

def register(entity, handler)
  registry.put_if_absent(_process_entity(entity), handler)
end

#registryObject

Handler registry accessor



14
15
16
# File 'lib/aws/templates/processor/registry.rb', line 14

def registry
  @registry ||= ::Concurrent::Map.new
end