class Dry::Transaction::DSL

Public Class Methods

new(step_adapters:) click to toggle source
Calls superclass method
# File lib/dry/transaction/dsl.rb, line 6
def initialize(step_adapters:)
  super()
  @step_adapters = step_adapters

  define_steps
  define_dsl
end

Public Instance Methods

inspect() click to toggle source
# File lib/dry/transaction/dsl.rb, line 14
def inspect
  "Dry::Transaction::DSL(#{@step_adapters.keys.sort.join(", ")})"
end

Private Instance Methods

define_dsl() click to toggle source
# File lib/dry/transaction/dsl.rb, line 28
def define_dsl
  module_exec(@step_adapters) do |step_adapters|
    step_adapters.each do |adapter_name, adapter|
      define_method(adapter_name) do |step_name, with: nil, **options|
        operation_name = with

        steps << Step.new(
          adapter: adapter,
          name: step_name,
          operation_name: operation_name,
          operation: nil, # operations are resolved only when transactions are instantiated
          options: options
        )
      end
    end
  end
end
define_steps() click to toggle source
# File lib/dry/transaction/dsl.rb, line 20
def define_steps
  module_eval do
    define_method(:steps) do
      @steps ||= []
    end
  end
end