Sha256: afd55ab783858c4d8f5a5e668b9d99dab83152f34ecb820c911f8dbb13408d0e

Contents?: true

Size: 548 Bytes

Versions: 30

Compression:

Stored size: 548 Bytes

Contents

class Cistern::Data::Hash
  Cistern::Data.backends[:hash] = self

  def initialize(options={}, &default)
    @hash    = Hash.new
    @default = default
  end

  def clear
    hash.clear
  end

  def store(key, *args)
    assign_default(key)

    hash.store(key, *args)
  end

  alias []= store

  def fetch(key, *args)
    assign_default(key)

    hash.fetch(key, *args)
  end

  alias [] fetch

  protected

  attr_reader :hash, :default

  def assign_default(key)
    if !hash.key?(key) && default
      default.call(hash, key)
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
cistern-0.11.2.pre2 lib/cistern/data/hash.rb
cistern-0.11.1 lib/cistern/data/hash.rb
cistern-0.11.0 lib/cistern/data/hash.rb
cistern-0.10.2 lib/cistern/data/hash.rb
cistern-0.9.2 lib/cistern/data/hash.rb
cistern-0.9.1 lib/cistern/data/hash.rb
cistern-0.9.0 lib/cistern/data/hash.rb
cistern-0.8.0 lib/cistern/data/hash.rb
cistern-0.7.1 lib/cistern/data/hash.rb
cistern-0.7.0 lib/cistern/data/hash.rb