Sha256: f0e34eee8dd88632a0fd9654d42451d1f2cff89b1f9df471ed36f2e94b43f844

Contents?: true

Size: 782 Bytes

Versions: 13

Compression:

Stored size: 782 Bytes

Contents

module Cistern::Data
  def self.extended(klass)
    klass.send(:extend, ClassMethods)
    klass.send(:include, InstanceMethods)
  end

  def self.backends
    @backends ||= {}
  end

  def self.backend(*args, &block)
    engine, options = args

    Cistern::Data.backends[engine].new(options || {}, &block)
  end

  module ClassMethods
    def data
      @data ||= Cistern::Data.backend(*storage) { |d, k| d[k] = [] }
    end

    def reset!
      clear!
      @data = nil
    end

    def clear!
      data.clear
    end

    def store_in(*args)
      @storage = *args
      @data    = nil
    end

    def storage
      @storage ||= :hash
    end
  end

  module InstanceMethods
    def data
      self.class.data
    end

    def reset!
      self.class.reset!
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cistern-2.8.0 lib/cistern/data.rb
cistern-2.7.2 lib/cistern/data.rb
cistern-2.7.1 lib/cistern/data.rb
cistern-2.7.0 lib/cistern/data.rb
cistern-2.6.0 lib/cistern/data.rb
cistern-2.5.0 lib/cistern/data.rb
cistern-2.4.1 lib/cistern/data.rb
cistern-2.4.0 lib/cistern/data.rb
cistern-2.3.0 lib/cistern/data.rb
cistern-2.2.7 lib/cistern/data.rb
cistern-2.2.6 lib/cistern/data.rb
cistern-2.2.5 lib/cistern/data.rb
cistern-2.2.4 lib/cistern/data.rb