Module: Transproc
- Defined in:
- lib/transproc.rb,
lib/transproc/hash.rb,
lib/transproc/array.rb,
lib/transproc/class.rb,
lib/transproc/error.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
Defined Under Namespace
Modules: ArrayTransformations, ClassTransformations, Coercions, Composer, Conditional, Functions, HashTransformations, Helper, Recursion, Registry Classes: Composite, Function, MalformedInputError
Constant Summary collapse
- Error =
Class.new(StandardError)
- FunctionNotFoundError =
Class.new(Error)
- FunctionAlreadyRegisteredError =
Class.new(Error)
- VERSION =
'0.2.4'.freeze
Class Method Summary collapse
-
.[](name) ⇒ 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) ⇒ 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
35 36 37 38 39 |
# File 'lib/transproc.rb', line 35 def [](name) functions.fetch(name) { raise FunctionNotFoundError, "No registered function for #{name}" } 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
44 45 46 |
# File 'lib/transproc.rb', line 44 def functions @_functions ||= {} end |
.register(*args, &block) ⇒ Function
Register a new function
22 23 24 25 26 27 28 |
# File 'lib/transproc.rb', line 22 def register(*args, &block) name, fn = *args if functions.include?(name) raise FunctionAlreadyRegisteredError, "Function #{name} is already defined" end functions[name] = fn || block end |