Class: Aws::Templates::Processor::Handler

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

Overview

Basic entity handler

Handler are classes encapsulating functionality of transforming entity into desired output. For instance, the same LDAP record can be transformed into JSON description or LDIF definition. The same help article can be written to output console or HTML.

Each handler is attached to a registry object which stores correspondence between entities and their handlers. A handler is registered in a registry only when it is attached to an entity. Handler depend on entities but entities are not aware of handlers.

Handlers are regular Ruby classes and all assumptions made about polymorphism, inheritance and incapsulation are true for them.

Handler class itself is an abstract class which can’t be instantiated directly.

Direct Known Subclasses

Help::Provider, Render::BasicView

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, params = nil) ⇒ Handler

Create handler instance and link it to the context



75
76
77
78
# File 'lib/aws/templates/processor/handler.rb', line 75

def initialize(ctx, params = nil)
  @context = ctx
  @parameters = params
end

Class Attribute Details

.entityObject (readonly)

Entity the handler is registered for



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

def entity
  @entity
end

Instance Attribute Details

#contextObject (readonly)

Context handler object is attached to



58
59
60
# File 'lib/aws/templates/processor/handler.rb', line 58

def context
  @context
end

#parametersObject (readonly)

Assigned handler parameters



62
63
64
# File 'lib/aws/templates/processor/handler.rb', line 62

def parameters
  @parameters
end

Class Method Details

.for_entity(entity) ⇒ Object

Link the handler class to the entity

Registers the link in the processor object of the handler class.



45
46
47
48
49
# File 'lib/aws/templates/processor/handler.rb', line 45

def for_entity(entity)
  @entity = entity
  processor.register(entity, self)
  self
end

.processorObject

Render accessor

Returns either processor of this handler class or processor of any ancestor.



27
28
29
# File 'lib/aws/templates/processor/handler.rb', line 27

def processor
  @processor || (superclass.processor if superclass < Handler)
end

.register_in(r) ⇒ Object

Register the hander class in a processor

Registers the handler class in the processor

  • r - processor registrar



36
37
38
39
# File 'lib/aws/templates/processor/handler.rb', line 36

def register_in(r)
  @processor = r
  self
end

Instance Method Details

#handler_for(entity) ⇒ Object

Get handler for the entity

Returns registered handler for the entity



98
99
100
# File 'lib/aws/templates/processor/handler.rb', line 98

def handler_for(entity)
  processor.handler_for(entity)
end

#in_context(*args, &blk) ⇒ Object

Execute in the context

Executes passed block in the context. It helps against putting too much context-dependend method accesses in long blocks. Returns the value returned by the block.



69
70
71
# File 'lib/aws/templates/processor/handler.rb', line 69

def in_context(*args, &blk)
  context.instance_exec(*args, &blk)
end

#processed_for(obj, parameters_override = nil) ⇒ Object

Process the object

Processes passed object with the handler default processor



90
91
92
# File 'lib/aws/templates/processor/handler.rb', line 90

def processed_for(obj, parameters_override = nil)
  processor.process(obj, parameters_override.nil? ? parameters : parameters_override)
end

#processorObject

Alias for class method processor



82
83
84
# File 'lib/aws/templates/processor/handler.rb', line 82

def processor
  self.class.processor
end