class Dry::Transaction::Step
@api private
Constants
- RETURN
- UNDEFINED
Attributes
adapter[R]
call_args[R]
name[R]
operation_name[R]
Public Class Methods
new(adapter:, name:, operation_name:, options:, operation: nil, call_args: [])
click to toggle source
rubocop:disable Metrics/ParameterLists
# 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
Public Instance Methods
arity()
click to toggle source
# File lib/dry/transaction/step.rb, line 84 def arity adapter.operation.arity end
call(input, continue = RETURN)
click to toggle source
# 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?()
click to toggle source
# File lib/dry/transaction/step.rb, line 80 def external? !!operation_name end
internal?()
click to toggle source
# File lib/dry/transaction/step.rb, line 76 def internal? !external? end
operation()
click to toggle source
# File lib/dry/transaction/step.rb, line 88 def operation adapter.operation end
with(operation: UNDEFINED, call_args: UNDEFINED)
click to toggle source
rubocop:enable Metrics/ParameterLists
# 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) { || ... }
click to toggle source
# 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