Class: Hashcraft::Transformers

Inherits:
Generic::Registry show all
Defined in:
lib/hashcraft/transformers.rb

Overview

Singleton that knows how to register and retrieve transformer instances. Entries can either be instances that respond to transform or procs that accept two arguments.

Instance Method Summary collapse

Methods inherited from Generic::Registry

#register, #register_all, #resolve

Constructor Details

#initializeTransformers

Returns a new instance of Transformers.



28
29
30
31
# File 'lib/hashcraft/transformers.rb', line 28

def initialize
  # append on the default case
  super(FUNCTIONS.merge('': FUNCTIONS[:pass_thru]))
end

Instance Method Details

#transform(name, value, option) ⇒ Object



33
34
35
36
37
38
# File 'lib/hashcraft/transformers.rb', line 33

def transform(name, value, option)
  object = resolve(name)
  method = object.is_a?(Proc) ? :call : :transform

  object.send(method, value, option)
end