Sha256: 4682ea2e3eec478979f4bce7fbd43457fae8320c8e96998265b63cee581e5239

Contents?: true

Size: 804 Bytes

Versions: 9

Compression:

Stored size: 804 Bytes

Contents

# frozen_string_literal: true

class Grumlin::Transaction
  attr_reader :session_id

  include Console

  COMMIT = Grumlin::Repository.new.g.step(:tx, :commit)
  ROLLBACK = Grumlin::Repository.new.g.step(:tx, :rollback)

  def initialize(traversal_start_class, pool:, middlewares:)
    @traversal_start_class = traversal_start_class
    @pool = pool
    @session_id = SecureRandom.uuid
    @middlewares = middlewares
  end

  def begin
    @traversal_start_class.new(session_id: @session_id, pool: @pool)
  end

  def commit
    finalize(COMMIT)
  end

  def rollback
    finalize(ROLLBACK)
  end

  private

  def finalize(step)
    @middlewares.call(traversal: step,
                      need_results: false,
                      session_id: @session_id,
                      pool: @pool)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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