Sha256: d329354b4ef6df981f760284e8e7a2165598a4d26aea2625f3f4cea812ad67f1

Contents?: true

Size: 734 Bytes

Versions: 3

Compression:

Stored size: 734 Bytes

Contents

module BasicCache
  ##
  # Basic store object (uses a Hash)
  class Store
    attr_reader :raw

    ##
    # Generate an empty store

    def initialize
      @raw = {}
    end

    ##
    # Clears a specified key or the whole store

    def clear!(key = nil)
      key.nil? ? @raw.clear : @raw.delete(key)
    end

    ##
    # Retrieve a key

    def [](key)
      @raw[key]
    end

    ##
    # Set a key

    def []=(key, value)
      @raw[key] = value
    end

    ##
    # Return the size of the store

    def size
      @raw.size
    end

    ##
    # Check for a key in the store

    def include?(key)
      @raw.include? key
    end

    ##
    # Array of keys in the store

    def keys
      @raw.keys
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
basiccache-0.2.1 lib/basiccache/stores/store.rb
basiccache-0.2.0 lib/basiccache/stores/store.rb
basiccache-0.1.0 lib/stores/store.rb