Class: Rash

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

Instance Method Summary collapse

Methods included from Memoizable

#memoize

Constructor Details

#initialize(url, path) ⇒ Object

Initializes a new store object.

Parameters:

  • data (Hash)

    (optional) data to load into the stash.



33
34
35
36
37
38
# File 'lib/hoodie/rash.rb', line 33

def initialize(url, path)
  @url = url
  @path = path
  memoize [:fetch], Stash.new(DiskStash::Cache.new)
  @store ||= fetch
end

Instance Method Details

#[](key) ⇒ Hash, ...

Retrieves the value for a given key

Parameters:

  • key (Symbol, String)

    representing the key

Returns:



46
47
48
# File 'lib/hoodie/rash.rb', line 46

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

#[]=(key, value) ⇒ Object

Store the given value with the given key, either an an argument or block. If a previous value was set it will be overwritten with the new value.

Parameters:

  • key (Symbol, String)

    string or symbol representing the key

  • value (Object)

    any object that represents the value (optional)

  • block (&block)

    that returns the value to set (optional)

Returns:

  • nothing.



60
61
62
# File 'lib/hoodie/rash.rb', line 60

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

#keysArray<String, Symbol>

return all keys in the store as an array

Returns:

  • (Array<String, Symbol>)

    all the keys in store



76
77
78
# File 'lib/hoodie/rash.rb', line 76

def keys
  @store.keys
end

#sizeFixnum

return the size of the store as an integer

Returns:

  • (Fixnum)


68
69
70
# File 'lib/hoodie/rash.rb', line 68

def size
  @store.size
end