Module: Transproc

Defined in:
lib/transproc.rb,
lib/transproc/hash.rb,
lib/transproc/array.rb,
lib/transproc/version.rb,
lib/transproc/composer.rb,
lib/transproc/function.rb,
lib/transproc/coercions.rb,
lib/transproc/recursion.rb,
lib/transproc/conditional.rb

Defined Under Namespace

Modules: ArrayTransformations, Coercions, Composer, Conditional, Functions, HashTransformations, Helper, Recursion Classes: Function

Constant Summary collapse

VERSION =
'0.2.0'.freeze

Class Method Summary collapse

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



29
30
31
# File 'lib/transproc.rb', line 29

def [](name)
  functions.fetch(name)
end

.functionsObject

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



36
37
38
# File 'lib/transproc.rb', line 36

def functions
  @_functions ||= {}
end

.register(*args, &block) ⇒ Function

Register a new function

Examples:

Transproc.register(:to_json, -> v { v.to_json })

Transproc(:map_array, Transproc(:to_json))


19
20
21
22
# File 'lib/transproc.rb', line 19

def register(*args, &block)
  name, fn = *args
  functions[name] = fn || block
end