Sha256: 999c6797fd26fcd720ad6983ef9f53a0a44edb30bb59c378519fd4418d0799e8

Contents?: true

Size: 551 Bytes

Versions: 13

Compression:

Stored size: 551 Bytes

Contents

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

  def initialize(_options = {}, &default)
    @hash    = {}
    @default = default
  end

  def clear
    hash.clear
  end

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

    hash.store(key, *args)
  end

  alias_method :[]=, :store

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

    hash.fetch(key, *args)
  end

  alias_method :[], :fetch

  protected

  attr_reader :hash, :default

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

Version data entries

13 entries across 13 versions & 1 rubygems

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