Class: Juno::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/juno/base.rb

Overview

Simple interface to key/value stores with Hash-like interface.

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Fetch value with key. Return nil if the key doesn’t exist

Parameters:

  • key (Object)

Returns:

  • (Object)

    value



26
27
28
# File 'lib/juno/base.rb', line 26

def [](key)
  load(key)
end

#[]=(key, value) ⇒ Object

Store value with key

Parameters:

  • key (Object)
  • value (Object)

Returns:

  • value



36
37
38
# File 'lib/juno/base.rb', line 36

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

#closeObject

Explicitly close the store



7
8
# File 'lib/juno/base.rb', line 7

def close
end

#fetch(key, value = nil, options = {}) ⇒ Object

Fetch value with key. Return default if value is nil.

Parameters:

  • key (Object)
  • value (Object) (defaults to: nil)

    Default value

  • options (Hash) (defaults to: {})

Returns:

  • (Object)

    value from store



17
18
19
# File 'lib/juno/base.rb', line 17

def fetch(key, value = nil, options = {})
  load(key, options) || (block_given? && yield(key)) || value
end