Class: Dry::Transaction::Step Private

Inherits:
Object
  • Object
show all
Includes:
Monads::Result::Mixin
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:, operation: nil, options:, 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.

Returns a new instance of Step.



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

def initialize(adapter:, name:, operation_name:, operation: nil, options:, 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.



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

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.



48
49
50
51
52
53
54
55
56
# File 'lib/dry/transaction/step.rb', line 48

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)


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

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)


73
74
75
# File 'lib/dry/transaction/step.rb', line 73

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.



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

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.



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

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.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dry/transaction/step.rb', line 58

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