Class: Dry::Transformer::Function Private
- Inherits:
-
Object
- Object
- Dry::Transformer::Function
- Defined in:
- lib/dry/transformer/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 Dry::Transformer to wrap registered methods.
Instance Attribute Summary collapse
-
#args ⇒ Array
readonly
private
Additional arguments that will be passed to the wrapped proc.
-
#fn ⇒ Proc, Composed
readonly
private
Wrapped proc or another composite function.
-
#name ⇒ <type] The name of the function
readonly
<type] The name of the function.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#call(*value) ⇒ Object
(also: #[])
Call the wrapped proc.
-
#compose(other) ⇒ Composite
(also: #+, #>>)
Compose this function with another function or a proc.
-
#initialize(fn, options = {}) ⇒ Function
constructor
private
A new instance of Function.
-
#to_ast ⇒ Array
Return a simple AST representation of this function.
-
#to_proc ⇒ Proc
private
Converts a transproc to a simple proc.
-
#with(*args) ⇒ Function
private
Return a new fn with curried args.
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.
34 35 36 37 38 |
# File 'lib/dry/transformer/function.rb', line 34 def initialize(fn, = {}) @fn = fn @args = .fetch(:args, []) @name = .fetch(:name, fn) end |
Instance Attribute Details
#args ⇒ Array (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
24 25 26 |
# File 'lib/dry/transformer/function.rb', line 24 def args @args end |
#fn ⇒ Proc, 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
17 18 19 |
# File 'lib/dry/transformer/function.rb', line 17 def fn @fn end |
#name ⇒ <type] The name of the function (readonly)
Returns <type] The name of the function.
31 32 33 |
# File 'lib/dry/transformer/function.rb', line 31 def name @name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
77 78 79 80 81 |
# File 'lib/dry/transformer/function.rb', line 77 def ==(other) return false unless other.instance_of?(self.class) [fn, name, args] == [other.fn, other.name, other.args] end |
#call(*value) ⇒ Object Also known as: []
Call the wrapped proc
47 48 49 |
# File 'lib/dry/transformer/function.rb', line 47 def call(*value) fn.call(*value, *args) end |
#compose(other) ⇒ Composite Also known as: +, >>
Compose this function with another function or a proc
61 62 63 |
# File 'lib/dry/transformer/function.rb', line 61 def compose(other) Composite.new(self, other) end |
#to_ast ⇒ Array
Return a simple AST representation of this function
89 90 91 92 |
# File 'lib/dry/transformer/function.rb', line 89 def to_ast args_ast = args.map { |arg| arg.respond_to?(:to_ast) ? arg.to_ast : arg } [name, args_ast] end |
#to_proc ⇒ Proc
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.
Converts a transproc to a simple proc
98 99 100 101 102 103 104 |
# File 'lib/dry/transformer/function.rb', line 98 def to_proc if !args.empty? proc { |*value| fn.call(*value, *args) } else fn.to_proc end end |
#with(*args) ⇒ 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.
Return a new fn with curried args
72 73 74 |
# File 'lib/dry/transformer/function.rb', line 72 def with(*args) self.class.new(fn, name: name, args: args) end |