Class: Snowden::Backends::HashBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/snowden/backends/hash_backend.rb

Instance Method Summary collapse

Constructor Details

#initialize(namespace = "", hash = SNOWDEN_BACKEND_HASH) ⇒ HashBackend

Creates a new redis backend

Parameters:

  • namespace (String) (defaults to: "")

    the string this backend is namespaced under.

  • hash (Hash) (defaults to: SNOWDEN_BACKEND_HASH)

    a Hash object instance to save values in.



11
12
13
14
# File 'lib/snowden/backends/hash_backend.rb', line 11

def initialize(namespace="", hash=SNOWDEN_BACKEND_HASH)
  @namespace = namespace
  @hash      = hash
end

Instance Method Details

#find(key) ⇒ [String]

Finds a value in this index

Parameters:

  • key (String)

    the string key to search the index for.

Returns:

  • ([String])

    a list of strings that matched the namespaced key.



30
31
32
# File 'lib/snowden/backends/hash_backend.rb', line 30

def find(key)
  @hash.fetch(namespaced_key(key), [])
end

#save(key, value) ⇒ Object

Saves a value in this index

Parameters:

  • key (String)

    the string key to save the value under.

  • value (String)

    the value to save.



20
21
22
23
24
# File 'lib/snowden/backends/hash_backend.rb', line 20

def save(key, value)
  @hash[namespaced_key(key)] ||= []
  @hash[namespaced_key(key)] << value
  nil
end