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.12.3 lib/cistern/data/hash.rb
cistern-2.2.3 lib/cistern/data/hash.rb
cistern-2.2.1 lib/cistern/data/hash.rb
cistern-2.1.0 lib/cistern/data/hash.rb
cistern-2.0.5 lib/cistern/data/hash.rb
cistern-2.0.4 lib/cistern/data/hash.rb
cistern-0.12.2 lib/cistern/data/hash.rb
cistern-0.12.1 lib/cistern/data/hash.rb
cistern-2.0.3 lib/cistern/data/hash.rb
cistern-2.0.2 lib/cistern/data/hash.rb
cistern-0.11.3 lib/cistern/data/hash.rb
cistern-2.0.1 lib/cistern/data/hash.rb
cistern-1.0.1.pre6 lib/cistern/data/hash.rb
cistern-1.0.1.pre5 lib/cistern/data/hash.rb
cistern-1.0.1.pre4 lib/cistern/data/hash.rb
cistern-1.0.1.pre3 lib/cistern/data/hash.rb
cistern-1.0.1.pre2 lib/cistern/data/hash.rb
cistern-0.11.2 lib/cistern/data/hash.rb
cistern-1.0.1.pre1 lib/cistern/data/hash.rb
cistern-1.0.0.pre lib/cistern/data/hash.rb