Class: Hashcraft::Transformers
- Inherits:
-
Generic::Registry
- Object
- Generic::Registry
- Hashcraft::Transformers
- 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
-
#initialize ⇒ Transformers
constructor
A new instance of Transformers.
- #transform(name, value, option) ⇒ Object
Methods inherited from Generic::Registry
#register, #register_all, #resolve
Constructor Details
#initialize ⇒ Transformers
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 |