Class: Dry::Transaction::Step Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/transaction/step.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.

Constant Summary collapse

UNDEFINED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Object.new.freeze
RETURN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

-> x { x }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter:, name:, operation_name:, options:, operation: nil, call_args: []) ⇒ Step

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.

rubocop:disable Metrics/ParameterLists



26
27
28
29
30
31
32
# File 'lib/dry/transaction/step.rb', line 26

def initialize(adapter:, name:, operation_name:, options:, operation: nil, call_args: [])
  @adapter = StepAdapter[adapter, operation,
                         {**options, step_name: name, operation_name: operation_name}]
  @name = name
  @operation_name = operation_name
  @call_args = call_args
end

Instance Attribute Details

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



20
21
22
# File 'lib/dry/transaction/step.rb', line 20

def adapter
  @adapter
end

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



23
24
25
# File 'lib/dry/transaction/step.rb', line 23

def call_args
  @call_args
end

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



21
22
23
# File 'lib/dry/transaction/step.rb', line 21

def name
  @name
end

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



22
23
24
# File 'lib/dry/transaction/step.rb', line 22

def operation_name
  @operation_name
end

Instance Method Details

#arityObject

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.



84
85
86
# File 'lib/dry/transaction/step.rb', line 84

def arity
  adapter.operation.arity
end

#call(input, continue = RETURN) ⇒ 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.



51
52
53
54
55
56
57
58
59
# File 'lib/dry/transaction/step.rb', line 51

def call(input, continue = RETURN)
  args = [input, *call_args]

  if adapter.yields?
    with_broadcast(args) { adapter.(args, &continue) }
  else
    continue.(with_broadcast(args) { adapter.(args) })
  end
end

#external?Boolean

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:

  • (Boolean)


80
81
82
# File 'lib/dry/transaction/step.rb', line 80

def external?
  !!operation_name
end

#internal?Boolean

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:

  • (Boolean)


76
77
78
# File 'lib/dry/transaction/step.rb', line 76

def internal?
  !external?
end

#operationObject

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.



88
89
90
# File 'lib/dry/transaction/step.rb', line 88

def operation
  adapter.operation
end

#with(operation: UNDEFINED, call_args: UNDEFINED) ⇒ 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.

rubocop:enable Metrics/ParameterLists



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dry/transaction/step.rb', line 35

def with(operation: UNDEFINED, call_args: UNDEFINED)
  return self if operation == UNDEFINED && call_args == UNDEFINED

  new_operation = operation == UNDEFINED ? adapter.operation : operation
  new_call_args = call_args == UNDEFINED ? self.call_args : Array(call_args)

  self.class.new(
    adapter: adapter,
    name: name,
    operation_name: operation_name,
    operation: new_operation,
    options: adapter.options,
    call_args: new_call_args
  )
end

#with_broadcast(args) ⇒ 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.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dry/transaction/step.rb', line 61

def with_broadcast(args)
  publish(:step, step_name: name, args: args)

  yield.fmap { |value|
    publish(:step_succeeded, step_name: name, args: args, value: value)
    value
  }.or { |value|
    Failure(
      StepFailure.(self, value) {
        publish(:step_failed, step_name: name, args: args, value: value)
      }
    )
  }
end