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/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/support/deprecations.rb
Defined Under Namespace
Modules: ArrayTransformations, ClassTransformations, Coercions, Composer, Conditional, Deprecations, Functions, HashTransformations, Helper, Recursion, Registry Classes: Composite, Function, FunctionNotFoundError, MalformedInputError, Store
Constant Summary collapse
- Error =
Class.new(StandardError)
- FunctionAlreadyRegisteredError =
Class.new(Error)
- VERSION =
'0.3.1'.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
42 43 44 45 46 47 48 49 50 |
# File 'lib/transproc.rb', line 42 def self.[](name, *args) fn = functions.fetch(name) { raise FunctionNotFoundError.new(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
14 15 16 |
# File 'lib/transproc.rb', line 14 def self.functions @_functions ||= {} end |
.register(*args, &block) ⇒ Function
Register a new function
29 30 31 32 33 34 35 |
# File 'lib/transproc.rb', line 29 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 |