Module: Transproc::Registry
- Included in:
- ArrayTransformations, ClassTransformations, Coercions, Conditional, HashTransformations, ProcTransformations, Recursion
- Defined in:
- lib/transproc/registry.rb
Overview
Container to define transproc functions in, and access them via ‘[]` method from the outside of the module
Instance Method Summary collapse
-
#[](fn, *args) ⇒ Transproc::Function
(also: #t)
Builds the transformation.
-
#fetch(fn) ⇒ #call
Gets the procedure for creating a transproc.
-
#import(*args) ⇒ itself
(also: #uses)
Imports either a method (converted to a proc) from another module, or all methods from that module.
-
#store ⇒ Transproc::Store
The store of procedures imported from external modules.
Instance Method Details
#[](fn, *args) ⇒ Transproc::Function Also known as: t
Builds the transformation
47 48 49 |
# File 'lib/transproc/registry.rb', line 47 def [](fn, *args) Function.new(fetch(fn), args: args, name: fn) end |
#fetch(fn) ⇒ #call
Gets the procedure for creating a transproc
103 104 105 106 107 108 |
# File 'lib/transproc/registry.rb', line 103 def fetch(fn) return fn unless fn.instance_of? Symbol respond_to?(fn) ? method(fn) : store.fetch(fn) rescue raise FunctionNotFoundError.new(fn, self) end |
#import(source) ⇒ itself #import(*names, **options) ⇒ itself #import(name, **options) ⇒ itself Also known as: uses
Imports either a method (converted to a proc) from another module, or all methods from that module.
If the external module is a registry, looks for its imports too.
81 82 83 84 |
# File 'lib/transproc/registry.rb', line 81 def import(*args) @store = store.import(*args) self end |
#store ⇒ Transproc::Store
The store of procedures imported from external modules
91 92 93 |
# File 'lib/transproc/registry.rb', line 91 def store @store ||= Store.new end |