Class: Dry::Transaction::Callable Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/transaction/callable.rb

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation) ⇒ Callable

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 Callable.



19
20
21
22
23
24
25
26
27
28
# File 'lib/dry/transaction/callable.rb', line 19

def initialize(operation)
  @operation = case operation
               when Proc, Method
                 operation
               else
                 operation.method(:call)
               end

  @arity = @operation.arity
end

Instance Attribute Details

#arityObject (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.



17
18
19
# File 'lib/dry/transaction/callable.rb', line 17

def arity
  @arity
end

#operationObject (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.



17
18
19
# File 'lib/dry/transaction/callable.rb', line 17

def operation
  @operation
end

Class Method Details

.[](callable) ⇒ Object

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.



7
8
9
10
11
12
13
14
15
# File 'lib/dry/transaction/callable.rb', line 7

def self.[](callable)
  if callable.is_a?(self)
    callable
  elsif callable.nil?
    nil
  else
    new(callable)
  end
end

Instance Method Details

#call(*args, &block) ⇒ Object

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.



30
31
32
33
34
35
36
37
38
39
# File 'lib/dry/transaction/callable.rb', line 30

def call(*args, &block)
  if arity.zero?
    operation.(&block)
  elsif ruby_27_last_arg_hash?(args)
    *prefix, last = args
    operation.(*prefix, **last, &block)
  else
    operation.(*args, &block)
  end
end