Class: Trocla::Store
- Inherits:
-
Object
- Object
- Trocla::Store
- Defined in:
- lib/trocla/store.rb
Overview
implements the default store behavior
Direct Known Subclasses
Trocla::Stores::Memory, Trocla::Stores::Moneta, Trocla::Stores::Vault
Instance Attribute Summary collapse
-
#store_config ⇒ Object
readonly
Returns the value of attribute store_config.
-
#trocla ⇒ Object
readonly
Returns the value of attribute trocla.
Instance Method Summary collapse
-
#close ⇒ Object
closes the store when called do whatever “closes” your store, e.g.
-
#delete(key, format = nil) ⇒ Object
deletes the value for format if format is nil everything is deleted returns value of format or hash of format => value # if everything is deleted.
-
#formats(_) ⇒ Object
returns all formats for a key.
-
#get(key, format) ⇒ Object
should return value for key & format returns nil if nothing or a nil value was found.
-
#initialize(config, trocla) ⇒ Store
constructor
A new instance of Store.
-
#search(_) ⇒ Object
def searches for a key.
-
#set(key, format, value, options = {}) ⇒ Object
sets value for key & format setting the plain format must invalidate all other formats as they should either be derived from plain or set directly.
Constructor Details
#initialize(config, trocla) ⇒ Store
Returns a new instance of Store.
5 6 7 8 |
# File 'lib/trocla/store.rb', line 5 def initialize(config, trocla) @store_config = config @trocla = trocla end |
Instance Attribute Details
#store_config ⇒ Object (readonly)
Returns the value of attribute store_config.
3 4 5 |
# File 'lib/trocla/store.rb', line 3 def store_config @store_config end |
#trocla ⇒ Object (readonly)
Returns the value of attribute trocla.
3 4 5 |
# File 'lib/trocla/store.rb', line 3 def trocla @trocla end |
Instance Method Details
#close ⇒ Object
closes the store when called do whatever “closes” your store, e.g. close database connections.
13 |
# File 'lib/trocla/store.rb', line 13 def close; end |
#delete(key, format = nil) ⇒ Object
deletes the value for format if format is nil everything is deleted returns value of format or hash of format => value # if everything is deleted.
49 50 51 |
# File 'lib/trocla/store.rb', line 49 def delete(key, format = nil) format.nil? ? (delete_all(key) || {}) : delete_format(key, format) end |
#formats(_) ⇒ Object
returns all formats for a key
54 55 56 |
# File 'lib/trocla/store.rb', line 54 def formats(_) raise 'not implemented' end |
#get(key, format) ⇒ Object
should return value for key & format returns nil if nothing or a nil value was found. If a key is expired it must return nil.
19 20 21 |
# File 'lib/trocla/store.rb', line 19 def get(key, format) raise 'not implemented' end |
#search(_) ⇒ Object
def searches for a key
59 60 61 |
# File 'lib/trocla/store.rb', line 59 def search(_) raise 'not implemented' end |
#set(key, format, value, options = {}) ⇒ Object
sets value for key & format setting the plain format must invalidate all other formats as they should either be derived from plain or set directly. options is a hash containing further information for the store. e.g. expiration of a key. Keys can have an expiration / timeout by setting ‘expires` within the options hashs. Value of `expires` must be an integer indicating the amount of seconds a key can live with. This mechanism is expected to be be implemented by the backend.
36 37 38 39 40 41 42 |
# File 'lib/trocla/store.rb', line 36 def set(key, format, value, = {}) if format == 'plain' set_plain(key, value, ) else set_format(key, format, value, ) end end |