Class: Dry::Transaction::Step Private
- Inherits:
-
Object
- Object
- Dry::Transaction::Step
- 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
- #adapter ⇒ Object readonly private
- #call_args ⇒ Object readonly private
- #name ⇒ Object readonly private
- #operation_name ⇒ Object readonly private
Instance Method Summary collapse
- #arity ⇒ Object private
- #call(input, continue = RETURN) ⇒ Object private
- #external? ⇒ Boolean private
-
#initialize(adapter:, name:, operation_name:, operation: nil, options:, call_args: []) ⇒ Step
constructor
private
A new instance of Step.
- #internal? ⇒ Boolean private
- #operation ⇒ Object private
- #with(operation: UNDEFINED, call_args: UNDEFINED) ⇒ Object private
- #with_broadcast(args) ⇒ Object private
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, **, step_name: name, operation_name: operation_name] @name = name @operation_name = operation_name @call_args = call_args end |
Instance Attribute Details
#adapter ⇒ Object (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_args ⇒ Object (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 |
#name ⇒ Object (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_name ⇒ Object (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
#arity ⇒ 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.
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.
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.
73 74 75 |
# File 'lib/dry/transaction/step.rb', line 73 def internal? !external? end |
#operation ⇒ 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.
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., 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 |