Class: Teton::Db
- Inherits:
-
Object
- Object
- Teton::Db
- Defined in:
- lib/teton/db.rb
Overview
The main interface for any store backend.
Constant Summary collapse
- DEFAULT_SEPARATOR =
'/'
Instance Attribute Summary collapse
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #count(key) ⇒ Object
- #del(key) ⇒ Object
- #get(key, limit: nil, skip: nil) ⇒ Object
-
#initialize(separator: DEFAULT_SEPARATOR, store: Stores::Memory.new) ⇒ Db
constructor
A new instance of Db.
- #set(key, data) ⇒ Object
Constructor Details
#initialize(separator: DEFAULT_SEPARATOR, store: Stores::Memory.new) ⇒ Db
Returns a new instance of Db.
14 15 16 17 18 19 20 21 |
# File 'lib/teton/db.rb', line 14 def initialize(separator: DEFAULT_SEPARATOR, store: Stores::Memory.new) raise ArgumentError, 'separator is required' if separator.to_s.empty? @separator = separator.to_s @store = store freeze end |
Instance Attribute Details
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
12 13 14 |
# File 'lib/teton/db.rb', line 12 def separator @separator end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
12 13 14 |
# File 'lib/teton/db.rb', line 12 def store @store end |
Instance Method Details
#count(key) ⇒ Object
45 46 47 |
# File 'lib/teton/db.rb', line 45 def count(key) store.count(key(key)) end |
#del(key) ⇒ Object
41 42 43 |
# File 'lib/teton/db.rb', line 41 def del(key) tap { store.del(key(key)) } end |
#get(key, limit: nil, skip: nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/teton/db.rb', line 33 def get(key, limit: nil, skip: nil) store.get( key(key), limit: zero_floor_or_nil(limit), skip: zero_floor_or_nil(skip) ) end |
#set(key, data) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/teton/db.rb', line 23 def set(key, data) key = key(key) raise ArgumentError, "key: #{key} does not point to an entry" unless key.entry? store.set(key, string_keys_and_values(data)) self end |