Class: Transproc::Function Private

Inherits:
Object
  • Object
show all
Defined in:
lib/transproc/function.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Transformation proc wrapper allowing composition of multiple procs into a data-transformation pipeline.

This is used by Transproc to wrap registered methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fn, options = {}) ⇒ Function

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.

Returns a new instance of Function.



26
27
28
29
# File 'lib/transproc/function.rb', line 26

def initialize(fn, options = {})
  @fn = fn
  @args = options.fetch(:args) { [] }
end

Instance Attribute Details

#argsArray (readonly)

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.

Additional arguments that will be passed to the wrapped proc

Returns:

  • (Array)


23
24
25
# File 'lib/transproc/function.rb', line 23

def args
  @args
end

#fnProc, Composed (readonly)

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.

Wrapped proc or another composite function

Returns:

  • (Proc, Composed)


16
17
18
# File 'lib/transproc/function.rb', line 16

def fn
  @fn
end

Instance Method Details

#call(*value) ⇒ Object Also known as: []

Call the wrapped proc

Parameters:

  • value (Object)

    The input value



38
39
40
41
42
# File 'lib/transproc/function.rb', line 38

def call(*value)
  fn[*value, *args]
rescue => ex
  raise MalformedInputError.new(@fn, value, ex)
end

#compose(other) ⇒ Composite Also known as: +, >>

Compose this function with another function or a proc

Parameters:

Returns:



54
55
56
# File 'lib/transproc/function.rb', line 54

def compose(other)
  Composite.new(self, other)
end

#to_astArray

Return a simple AST representation of this function

Returns:

  • (Array)


65
66
67
68
# File 'lib/transproc/function.rb', line 65

def to_ast
  identifier = fn.is_a?(::Proc) ? fn : fn.name
  [identifier, args]
end