Sha256: 707361a9a24e48a2e4e1029878dc53e378b300e63c9fcf5115a6110a6a2433b6

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

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

    # Pool should have size of 1 when working with session
    pool = Async::Pool::Controller.new(Grumlin::Client::PoolResource, limit: 1)

    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

5 entries across 5 versions & 1 rubygems

Version Path
grumlin-1.2.0 lib/grumlin/traversal_start.rb
grumlin-1.1.0 lib/grumlin/traversal_start.rb
grumlin-1.0.4 lib/grumlin/traversal_start.rb
grumlin-1.0.3 lib/grumlin/traversal_start.rb
grumlin-1.0.3.beta1 lib/grumlin/traversal_start.rb