Class: Proc::Callable

Inherits:
Composer::Callable
  • Object
show all
Defined in:
lib/proc/callable.rb

Instance Method Summary collapse

Constructor Details

#initialize(proc, client:, **kwargs) ⇒ Callable



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

def initialize(proc, client:, **kwargs)
  @client = client

  super(proc, **kwargs)
end

Instance Method Details

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

public

Dispatches this callable context to proc using the client.

If a block is passed, it will be called to prior to dispatch and its result passed as a nested context.



15
16
17
18
19
20
21
22
23
# File 'lib/proc/callable.rb', line 15

def call(input = input_omitted = true, **arguments)
  if ::Kernel.block_given?
    arguments[:proc] = yield
  end

  callable = build_callable(input: input_omitted ? @input : input, arguments: @arguments.merge(arguments))

  @client.call(@proc, callable.input, **callable.arguments)
end

#each(input = input_omitted = true, **arguments, &block) ⇒ Object

public

Dispatches this callable context to proc using the client, calling the given block once for each value.



27
28
29
30
31
# File 'lib/proc/callable.rb', line 27

def each(input = input_omitted = true, **arguments, &block)
  callable = build_callable(input: input_omitted ? @input : input, arguments: @arguments.merge(arguments))

  @client.call(@proc, callable.input, **callable.arguments, &block)
end