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.

Direct Known Subclasses

Composite

Defined Under Namespace

Classes: Composite

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.



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

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)


21
22
23
# File 'lib/transproc/function.rb', line 21

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)


14
15
16
# File 'lib/transproc/function.rb', line 14

def fn
  @fn
end

Instance Method Details

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

Call the wrapped proc

Parameters:

  • value (Object)

    The input value



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

def call(value)
  fn[value, *args]
end

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

Compose this function with another function or a proc

Parameters:

Returns:



50
51
52
# File 'lib/transproc/function.rb', line 50

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

#to_astArray

Return a simple AST representation of this function

Returns:

  • (Array)


61
62
63
64
# File 'lib/transproc/function.rb', line 61

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