Class: Proc::Callable
- Inherits:
-
Object
show all
- Defined in:
- lib/proc/callable.rb
Constant Summary
collapse
- IGNORE_MISSING =
i[to_hash].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(proc, client:, input: nil, arguments: {}) ⇒ Callable
Returns a new instance of Callable.
7
8
9
10
11
12
|
# File 'lib/proc/callable.rb', line 7
def initialize(proc, client:, input: nil, arguments: {})
@proc = proc
@client = client
@input = input
@arguments = arguments
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, input = input_omitted = true, **arguments) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/proc/callable.rb', line 51
def method_missing(name, input = input_omitted = true, **arguments)
if IGNORE_MISSING.include?(name)
super
else
Callable.new(
[@proc, name].join("."),
client: @client,
input: input_omitted ? @input : input,
arguments: @arguments.merge(arguments)
)
end
end
|
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
5
6
7
|
# File 'lib/proc/callable.rb', line 5
def arguments
@arguments
end
|
Returns the value of attribute input.
5
6
7
|
# File 'lib/proc/callable.rb', line 5
def input
@input
end
|
#proc ⇒ Object
Returns the value of attribute proc.
5
6
7
|
# File 'lib/proc/callable.rb', line 5
def proc
@proc
end
|
Instance Method Details
#>>(other) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/proc/callable.rb', line 27
def >>(other)
composed = Composition.new(client: @client, input: @input)
composed << self
composed << other
composed
end
|
#call(input = input_omitted = true, **arguments) ⇒ Object
19
20
21
|
# File 'lib/proc/callable.rb', line 19
def call(input = input_omitted = true, **arguments)
@client.call(@proc, input_omitted ? @input : input, **@arguments.merge(arguments))
end
|
#initialize_copy(_) ⇒ Object
14
15
16
17
|
# File 'lib/proc/callable.rb', line 14
def initialize_copy(_)
@input = input.dup
@arguments = arguments.dup
end
|
#respond_to_missing?(name) ⇒ Boolean
64
65
66
67
68
69
70
|
# File 'lib/proc/callable.rb', line 64
def respond_to_missing?(name, *)
if IGNORE_MISSING.include?(name)
super
else
true
end
end
|
#serialize ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/proc/callable.rb', line 34
def serialize
{
"{}" => {
"<<" => serialize_value(@input),
"[]" => [[@proc, serialized_arguments]]
}
}
end
|
#serialized_arguments ⇒ Object
43
44
45
46
47
|
# File 'lib/proc/callable.rb', line 43
def serialized_arguments
@arguments.each_pair.each_with_object({}) { |(key, value), hash|
hash[key.to_s] = serialize_value(value)
}
end
|
#with(input = input_omitted = true, **arguments) ⇒ Object
23
24
25
|
# File 'lib/proc/callable.rb', line 23
def with(input = input_omitted = true, **arguments)
self.class.new(@proc, client: @client, input: input_omitted ? @input : input, arguments: @arguments.merge(arguments))
end
|