Sha256: a00324363304fcb2072c487f49197c2360d92acd646cd9aeb7ba14016422f23d

Contents?: true

Size: 875 Bytes

Versions: 1

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true

module Grumlin
  class TraversalStart < Steppable
    include 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?

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

    def to_s(*)
      self.class.to_s
    end

    def inspect
      self.class.inspect
    end

    private

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grumlin-0.23.0 lib/grumlin/traversal_start.rb