Class: ChefStash::Rash

Inherits:
Object
  • Object
show all
Includes:
Memoizable
Defined in:
lib/chef_stash/rash.rb

Instance Method Summary collapse

Methods included from Memoizable

#memoize

Constructor Details

#initialize(url, path) ⇒ ChefStash

Initializes a new store object.

Parameters:

  • url (String, URI::HTTP)

    The URL to the repository to scan.

  • path (String)

    The path to append to the URL.



36
37
38
39
# File 'lib/chef_stash/rash.rb', line 36

def initialize(url, path)
  memoize [:fetch]
  @store ||= fetch(url, path)
end

Instance Method Details

#[](key) ⇒ Object? Also known as: get

Retrieves a value from the cache.

Parameters:

  • key (Object)

    The key to look up.

Returns:

  • (Object, nil)

    The value at the key, when present, or ‘nil`.



49
50
51
# File 'lib/chef_stash/rash.rb', line 49

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

#[]=(key, value) ⇒ Object? Also known as: set

Stores a value in the cache, either an an argument or block. If a previous value was set it will be overwritten with the new value.

Parameters:

  • key (Object)

    The key to store.

  • val (Object)

    The value to store.

Returns:

  • (Object, nil)

    The value at the key.



66
67
68
# File 'lib/chef_stash/rash.rb', line 66

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

#delete(key) ⇒ Object?

Removes a value from the cache.

Parameters:

  • key (Object)

    The key to remove.

Returns:

  • (Object, nil)

    The value at the key, when present, or ‘nil`.



79
80
81
# File 'lib/chef_stash/rash.rb', line 79

def delete(key)
  @store.delete(key)
end

#keysArray<String, Symbol>

return all keys in the store as an array

Returns:

  • (Array<String, Symbol>)

    all the keys in store



95
96
97
# File 'lib/chef_stash/rash.rb', line 95

def keys
  @store.keys
end

#sizeFixnum

return the size of the store as an integer

Returns:

  • (Fixnum)


87
88
89
# File 'lib/chef_stash/rash.rb', line 87

def size
  @store.size
end