Class: Dry::Operation::Extensions::ROM::Builder Private

Inherits:
Module
  • Object
show all
Defined in:
lib/dry/operation/extensions/rom.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 Method Summary collapse

Constructor Details

#initialize(gateway:, **options) ⇒ Builder

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



101
102
103
104
105
# File 'lib/dry/operation/extensions/rom.rb', line 101

def initialize(gateway:, **options)
  super()
  @gateway = gateway
  @options = options
end

Instance Method Details

#included(_klass) ⇒ 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.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/dry/operation/extensions/rom.rb', line 107

def included(_klass)
  default_gateway = @gateway
  default_options = @options

  define_method(:transaction) do |gateway: default_gateway, **opts, &steps|
    raise Dry::Operation::ExtensionError, <<~MSG unless respond_to?(:rom)
      When using the Rom extension, you need to define a #rom method \
      that returns the Rom container
    MSG

    intercepting_failure do
      result = nil
      rom.gateways[gateway].transaction(**default_options.merge(opts)) do |t|
        intercepting_failure(->(failure) {
                               result = failure
                               t.rollback!
                             }) do
          result = steps.()
        end
      end
      result
    end
  end
end