Sha256: bb096c2fba39a970908f91ca8c78aca8b5c956587c8965ea188d8d0cc0f14cd3

Contents?: true

Size: 820 Bytes

Versions: 4

Compression:

Stored size: 820 Bytes

Contents

module ProstoCache
  class ProstoHash
    extend Forwardable
    def initialize(hash = {})
      @hash = hash.each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v }
    end

    def [](key)
      raise ArgumentError unless key
      hash[key.to_sym]
    end

    def []=(key, value)
      raise ArgumentError unless key
      hash[key.to_sym] = value
    end

    def keys(init = nil)
      @keys = @keys || init || hash.keys
    end

    def values(init = nil)
      @values = @values || init || hash.values
    end

    def_delegators :hash, :to_s, :inspect

    private

    attr_reader :hash
  end

  def self.fail_on_missing_value?(litmus)
    case litmus
    when Symbol
      true
    when String
      false
    else
      raise ArgumentError, "Unknown type of cache key #{litmus.inspect}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
prosto_cache-0.2.5 lib/prosto_cache/prosto_hash.rb
prosto_cache-0.2.4 lib/prosto_cache/prosto_hash.rb
prosto_cache-0.2.3 lib/prosto_cache/prosto_hash.rb
prosto_cache-0.2.2 lib/prosto_cache/prosto_hash.rb