Sha256: 85f15aa5caad1c1d6ccc553c9965da2c2d257baa750b45e2dec53cb90059d5bb

Contents?: true

Size: 894 Bytes

Versions: 8

Compression:

Stored size: 894 Bytes

Contents

# frozen_string_literal: true

class Grumlin::TraversalStart < Grumlin::Steppable
  include Grumlin::WithExtension

  class TraversalError < Grumlin::Error; end
  class AlreadyBoundToTransactionError < TraversalError; end

  def tx
    raise AlreadyBoundToTransactionError if @session_id

    transaction = tx_class.new(self.class, pool: @pool, middlewares: @middlewares)
    return transaction unless block_given?

    result = nil

    begin
      result = yield transaction.begin
    rescue Grumlin::Rollback
      transaction.rollback
      result
    rescue StandardError
      transaction.rollback
      raise
    else
      transaction.commit
      result
    end
  end

  def to_s(*)
    self.class.to_s
  end

  def inspect
    self.class.inspect
  end

  private

  def tx_class
    Grumlin.features.supports_transactions? ? Grumlin::Transaction : Grumlin::DummyTransaction
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
grumlin-1.0.2 lib/grumlin/traversal_start.rb
grumlin-1.0.1 lib/grumlin/traversal_start.rb
grumlin-1.0.0 lib/grumlin/traversal_start.rb
grumlin-1.0.0.rc7 lib/grumlin/traversal_start.rb
grumlin-1.0.0.rc6 lib/grumlin/traversal_start.rb
grumlin-1.0.0.rc5 lib/grumlin/traversal_start.rb
grumlin-1.0.0.rc4 lib/grumlin/traversal_start.rb
grumlin-1.0.0.rc3 lib/grumlin/traversal_start.rb