Class: Proc::Composition

Inherits:
Object
  • Object
show all
Defined in:
lib/proc/composition.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, input:, callables: []) ⇒ Composition

Returns a new instance of Composition.



5
6
7
8
9
# File 'lib/proc/composition.rb', line 5

def initialize(client:, input:, callables: [])
  @client = client
  @input = input
  @callables = callables
end

Instance Method Details

#<<(callable) ⇒ Object



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

def <<(callable)
  @callables << callable
end

#>>(other) ⇒ Object



23
24
25
26
27
# File 'lib/proc/composition.rb', line 23

def >>(other)
  composed = dup
  composed << other
  composed
end

#call(input = input_omitted = true, **arguments) ⇒ Object



15
16
17
# File 'lib/proc/composition.rb', line 15

def call(input = input_omitted = true, **arguments)
  @client.call("exec", input_omitted ? @input : input, proc: serialized_calls)
end

#initialize_copy(_) ⇒ Object



11
12
13
# File 'lib/proc/composition.rb', line 11

def initialize_copy(_)
  @callables = @callables.dup
end

#serializeObject



33
34
35
36
37
38
39
40
# File 'lib/proc/composition.rb', line 33

def serialize
  {
    "{}" => {
      "<<" => @input,
      "[]" => serialized_calls
    }
  }
end

#serialized_callsObject



42
43
44
45
46
# File 'lib/proc/composition.rb', line 42

def serialized_calls
  @callables.map { |callable|
    [callable.proc, callable.serialized_arguments]
  }
end

#with(input = input_omitted = true) ⇒ Object



19
20
21
# File 'lib/proc/composition.rb', line 19

def with(input = input_omitted = true)
  self.class.new(client: @client, input: input_omitted ? @input : input, callables: @callables.dup)
end