Class: Juno::Base
- Inherits:
-
Object
- Object
- Juno::Base
- Defined in:
- lib/juno/base.rb
Overview
Simple interface to key/value stores with Hash-like interface.
Direct Known Subclasses
Adapters::ActiveRecord, Adapters::Cassandra, Adapters::Couch, Adapters::DataMapper, Adapters::File, Adapters::Fog, Adapters::MemcachedDalli, Adapters::MemcachedNative, Adapters::Memory, Adapters::Mongo, Adapters::Null, Adapters::PStore, Adapters::Redis, Adapters::Riak, Adapters::Sequel, Adapters::Sqlite, Cache, Proxy, Stack
Instance Method Summary collapse
-
#[](key) ⇒ Object
Fetch value with key.
-
#[]=(key, value) ⇒ Object
Store value with key.
-
#close ⇒ Object
Explicitly close the store.
-
#fetch(key, default = nil, options = nil) ⇒ Object
Fetch value with key.
Instance Method Details
#[](key) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
38 39 40 |
# File 'lib/juno/base.rb', line 38 def [](key) load(key) end |
#[]=(key, value) ⇒ Object
Store value with key
48 49 50 |
# File 'lib/juno/base.rb', line 48 def []=(key, value) store(key, value) end |
#close ⇒ Object
Explicitly close the store
7 8 |
# File 'lib/juno/base.rb', line 7 def close end |
#fetch(key, default = nil, options = nil) ⇒ Object
Fetch value with key
This is a overloaded method:
-
fetch(key, options = {}, &block) retrieve a key. if the key is not available, execute the block and return its return value.
-
fetch(key, value, options = {}) retrieve a key. if the key is not available, return the value.
24 25 26 27 28 29 30 31 |
# File 'lib/juno/base.rb', line 24 def fetch(key, default = nil, = nil) if block_given? raise ArgumentError, 'Only one argument accepted if block is given' if load(key, default || {}) || yield(key) else load(key, || {}) || default end end |