Class: KeyValueTree::Store
- Inherits:
-
Object
- Object
- KeyValueTree::Store
- Defined in:
- lib/keyvaluetree/store.rb
Overview
This class defines the methods expected by KeyValueTree::Hash for it’s Store backend
Direct Known Subclasses
Required methods collapse
-
#delete(key) ⇒ String
Delete the given key.
-
#key(key) ⇒ String
Return the value for the given key.
-
#store(key, value) ⇒ String
Store the value at the given key.
Optional methods (as some stores don't support (sub-) key enumeration) collapse
-
#delete_all(key) ⇒ Object
Delete all keys starting with the given prefix.
-
#keys ⇒ Array<String>
Fetch all keys in store.
-
#keys_starting_with(key) ⇒ Array<String>
Fetch all keys in store with the given key prefix.
-
#to_hash ⇒ Object
Convert the store to a hierachical Hash return [Hash].
Instance Method Details
#delete(key) ⇒ String
Delete the given key
26 27 28 |
# File 'lib/keyvaluetree/store.rb', line 26 def delete(key) raise NotImplementedError end |
#delete_all(key) ⇒ Object
Delete all keys starting with the given prefix
52 53 54 55 56 |
# File 'lib/keyvaluetree/store.rb', line 52 def delete_all(key) keys_starting_with(key.to_s).each do |each| self.delete(each) end end |
#key(key) ⇒ String
Return the value for the given key
11 12 13 |
# File 'lib/keyvaluetree/store.rb', line 11 def key(key) raise NotImplementedError end |
#keys ⇒ Array<String>
Fetch all keys in store
36 37 38 |
# File 'lib/keyvaluetree/store.rb', line 36 def keys raise NotImplementedError end |
#keys_starting_with(key) ⇒ Array<String>
Fetch all keys in store with the given key prefix
43 44 45 46 47 |
# File 'lib/keyvaluetree/store.rb', line 43 def keys_starting_with(key) self.keys.select do |sub_key| sub_key.start_with?(key.to_s) end end |
#store(key, value) ⇒ String
Store the value at the given key
19 20 21 |
# File 'lib/keyvaluetree/store.rb', line 19 def store(key, value) raise NotImplementedError end |
#to_hash ⇒ Object
Convert the store to a hierachical Hash return [Hash]
60 61 62 |
# File 'lib/keyvaluetree/store.rb', line 60 def to_hash raise NotImplementedError end |