Module: Transproc
- Defined in:
- lib/transproc.rb,
lib/transproc/hash.rb,
lib/transproc/proc.rb,
lib/transproc/array.rb,
lib/transproc/class.rb,
lib/transproc/error.rb,
lib/transproc/store.rb,
lib/transproc/version.rb,
lib/transproc/composer.rb,
lib/transproc/function.rb,
lib/transproc/registry.rb,
lib/transproc/coercions.rb,
lib/transproc/composite.rb,
lib/transproc/functions.rb,
lib/transproc/recursion.rb,
lib/transproc/conditional.rb,
lib/transproc/transformer.rb,
lib/transproc/support/deprecations.rb,
lib/transproc/transformer/class_interface.rb
Defined Under Namespace
Modules: ArrayTransformations, ClassTransformations, Coercions, Composer, Conditional, Deprecations, Functions, HashTransformations, Helper, ProcTransformations, Recursion, Registry Classes: Composite, Function, FunctionNotFoundError, Store, Transformer
Constant Summary collapse
- Undefined =
Object.new.freeze
- Error =
Class.new(StandardError)
- FunctionAlreadyRegisteredError =
Class.new(Error)
- VERSION =
'0.4.2'.freeze
Class Method Summary collapse
-
.[](name, *args) ⇒ Object
private
Get registered function with provided name.
-
.functions ⇒ Object
private
Function registry.
-
.register(*args, &block) ⇒ Function
Register a new function.
Class Method Details
.[](name, *args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get registered function with provided name
45 46 47 48 49 50 51 52 53 |
# File 'lib/transproc.rb', line 45 def self.[](name, *args) fn = functions.fetch(name) { raise(FunctionNotFoundError, name) } if args.any? fn.with(*args) else fn end end |
.functions ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Function registry
17 18 19 |
# File 'lib/transproc.rb', line 17 def self.functions @_functions ||= {} end |
.register(*args, &block) ⇒ Function
Register a new function
32 33 34 35 36 37 38 |
# File 'lib/transproc.rb', line 32 def self.register(*args, &block) name, fn = *args if functions.include? name raise FunctionAlreadyRegisteredError, "Function #{name} is already defined" end functions[name] = fn || block end |