Class: Dry::Operation::Extensions::Sequel::Builder Private

Inherits:
Module
  • Object
show all
Defined in:
lib/dry/operation/extensions/sequel.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(**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.



79
80
81
82
# File 'lib/dry/operation/extensions/sequel.rb', line 79

def initialize(**options)
  super()
  @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.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/dry/operation/extensions/sequel.rb', line 84

def included(klass)
  class_exec(@options) do |default_options|
    klass.define_method(:transaction) do |**opts, &steps|
      raise Dry::Operation::ExtensionError, <<~MSG unless respond_to?(:db)
        When using the Sequel extension, you need to define a #db method \
        that returns the Sequel database object
      MSG

      intercepting_failure do
        result = nil
        db.transaction(**default_options.merge(opts)) do
          intercepting_failure(->(failure) {
            result = failure
            raise ::Sequel::Rollback
          }) do
            result = steps.()
          end
        end
        result
      end
    end
  end
end