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(step_adapter, step_name, operation_name, operation, 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(step_adapter, step_name, operation_name, operation, options, call_args = [])
  @step_adapter = StepAdapter[step_adapter, operation, **options, step_name: step_name, operation_name: operation_name]
  @step_name = step_name
  @operation_name = operation_name
  @call_args = call_args
end

Instance Attribute Details

#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

#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

#step_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 step_adapter
  @step_adapter
end

#step_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 step_name
  @step_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.



70
71
72
# File 'lib/dry/transaction/step.rb', line 70

def arity
  step_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 step_adapter.yields?
    with_broadcast(args) { step_adapter.(args, &continue) }
  else
    continue.(with_broadcast(args) { step_adapter.(args) })
  end
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.



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

def operation
  step_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 ? step_adapter.operation : operation
  new_call_args = call_args == UNDEFINED ? self.call_args : Array(call_args)

  self.class.new(
    step_adapter,
    step_name,
    operation_name,
    new_operation,
    step_adapter.options,
    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
# File 'lib/dry/transaction/step.rb', line 58

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

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