Sha256: 2c674a753a93e21bc83c6c784eaf2193c1335ab844b1e7d3cd5339b887fbf860

Contents?: true

Size: 864 Bytes

Versions: 1

Compression:

Stored size: 864 Bytes

Contents

# frozen_string_literal: true

require "dry/core/equalizer"

module ROM
  # TODO: finish this in 1.1.0
  #
  # @api private
  class Session
    include Dry::Equalizer(:queue, :status)

    attr_reader :repo

    attr_reader :queue

    attr_reader :status

    def initialize(repo)
      @repo = repo
      @status = :pending
      initialize_queue!
    end

    def add(changeset)
      queue << changeset
      self
    end

    def commit!
      queue.each(&:commit)

      @status = :success

      self
    rescue StandardError => e
      @status = :failure
      raise e
    ensure
      initialize_queue!
    end

    def pending?
      status.equal?(:pending)
    end

    def success?
      status.equal?(:success)
    end

    def failure?
      status.equal?(:failure)
    end

    private

    def initialize_queue!
      @queue = []
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-6.0.0.alpha1 lib/rom/repository/session.rb