Sha256: f93f46531c8f9b01cbee868a1578410c8a8b69d206a7cbc8681cd545a8e54961

Contents?: true

Size: 814 Bytes

Versions: 20

Compression:

Stored size: 814 Bytes

Contents

require 'dry/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 => 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

20 entries across 20 versions & 1 rubygems

Version Path
rom-repository-2.0.2 lib/rom/repository/session.rb
rom-repository-2.0.1 lib/rom/repository/session.rb
rom-repository-2.0.0 lib/rom/repository/session.rb
rom-repository-2.0.0.rc2 lib/rom/repository/session.rb
rom-repository-2.0.0.rc1 lib/rom/repository/session.rb
rom-repository-2.0.0.beta3 lib/rom/repository/session.rb
rom-repository-2.0.0.beta2 lib/rom/repository/session.rb
rom-repository-1.4.0 lib/rom/repository/session.rb
rom-repository-2.0.0.beta1 lib/rom/repository/session.rb
rom-repository-1.3.3 lib/rom/repository/session.rb
rom-repository-1.3.2 lib/rom/repository/session.rb
rom-repository-1.3.1 lib/rom/repository/session.rb
rom-repository-1.3.0 lib/rom/repository/session.rb
rom-repository-1.2.0 lib/rom/repository/session.rb
rom-repository-1.1.0 lib/rom/repository/session.rb
rom-repository-1.0.2 lib/rom/repository/session.rb
rom-repository-1.0.1 lib/rom/repository/session.rb
rom-repository-1.0.0 lib/rom/repository/session.rb
rom-repository-1.0.0.rc2 lib/rom/repository/session.rb
rom-repository-1.0.0.rc1 lib/rom/repository/session.rb