Sha256: 44eba27f4f735f7f7441eb92ab6dd3e56017c13a755adbec4a45a4b6b84ee51a

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

module Spontaneous::Output::Store
  # A Transaction is a write-only view of the template store.
  # It provides #commit & #rollback mechanisms that function
  # like their DB equivalents, either preserving or removing the
  # modifications made.
  class Transaction
    attr_reader :revision

    def initialize(revision, store)
      @revision, @store = revision, store
      @index = []
      @committed = false
    end

    def store(output, dynamic, template)
      key = @store.output_key(output, dynamic)
      case
      when dynamic || output.dynamic? # dynamic
        @store.store_dynamic(@revision, key, template, self)
      when output.page.dynamic? # protected
        @store.store_protected(@revision, key, template, self)
      else # static
        @store.store_static(@revision, key, template, self)
      end
    end

    # Stores call this method to register the keys
    # they write to their backends. This is necessary
    # because we don't want to limit our backends to those
    # that are able to return keys based on a glob
    def push(key)
      @index.push(key)
    end

    def commit
      @store.add_revision(@revision, @index)
      @committed = true
    end

    def rollback
      @store.delete_revision(@revision, @index) unless @committed
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/output/store/transaction.rb
spontaneous-0.2.0.beta9 lib/spontaneous/output/store/transaction.rb
spontaneous-0.2.0.beta8 lib/spontaneous/output/store/transaction.rb
spontaneous-0.2.0.beta7 lib/spontaneous/output/store/transaction.rb
spontaneous-0.2.0.beta6 lib/spontaneous/output/store/transaction.rb
spontaneous-0.2.0.beta5 lib/spontaneous/output/store/transaction.rb