Class: Dry::Transaction::DSL Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/transaction/dsl.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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ DSL

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 DSL.



13
14
15
16
17
18
19
# File 'lib/dry/transaction/dsl.rb', line 13

def initialize(options, &block)
  @container = options.fetch(:container)
  @step_adapters = options.fetch(:step_adapters, StepAdapters)
  @steps = []

  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *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.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dry/transaction/dsl.rb', line 25

def method_missing(method_name, *args)
  return super unless step_adapters.key?(method_name)

  step_adapter = step_adapters[method_name]
  step_name = args.first
  options = args.last.is_a?(Hash) ? args.last : {}
  operation_name = options.delete(:with) || step_name
  operation = container[operation_name]

  steps << Step.new(step_adapter, step_name, operation_name, operation, options)
end

Instance Attribute Details

#containerObject (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.



9
10
11
# File 'lib/dry/transaction/dsl.rb', line 9

def container
  @container
end

#step_adaptersObject (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.



10
11
12
# File 'lib/dry/transaction/dsl.rb', line 10

def step_adapters
  @step_adapters
end

#stepsObject (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.



11
12
13
# File 'lib/dry/transaction/dsl.rb', line 11

def steps
  @steps
end

Instance Method Details

#callObject

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.



37
38
39
# File 'lib/dry/transaction/dsl.rb', line 37

def call
  Sequence.new(steps)
end

#respond_to_missing?(method_name) ⇒ 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)


21
22
23
# File 'lib/dry/transaction/dsl.rb', line 21

def respond_to_missing?(method_name)
  step_adapters.key?(method_name)
end