Class: Yoda::Store::Adapters::GdbmAdapter::NamespaceAccessor
- Inherits:
-
Object
- Object
- Yoda::Store::Adapters::GdbmAdapter::NamespaceAccessor
- Defined in:
- lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb
Constant Summary collapse
- KEYS_ADDRESS =
"%keys"
Instance Attribute Summary collapse
- #database ⇒ GDBM readonly
- #namespace ⇒ String? readonly
Instance Method Summary collapse
- #batch_write(data, bar) ⇒ Object abstract
-
#clear ⇒ void
abstract
Clear all contents in the database.
- #delete(address) ⇒ void
- #empty? ⇒ Boolean abstract
- #exist?(address) ⇒ Boolean abstract
- #get(address) ⇒ Object?
-
#initialize(database:, namespace:) ⇒ NamespaceAccessor
constructor
A new instance of NamespaceAccessor.
- #inspect ⇒ String
- #keys ⇒ Integer abstract
- #persistable? ⇒ Boolean abstract
- #put(address, object, modify_keys: true) ⇒ void
- #stats ⇒ Object abstract
- #sync ⇒ void abstract
Constructor Details
#initialize(database:, namespace:) ⇒ NamespaceAccessor
Returns a new instance of NamespaceAccessor.
16 17 18 19 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 16 def initialize(database:, namespace:) @database = database @namespace = namespace&.to_s end |
Instance Attribute Details
#database ⇒ GDBM (readonly)
9 10 11 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 9 def database @database end |
#namespace ⇒ String? (readonly)
12 13 14 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 12 def namespace @namespace end |
Instance Method Details
#batch_write(data, bar) ⇒ Object
This method is abstract.
103 104 105 106 107 108 109 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 103 def batch_write(data, ) data.each do |(k, v)| put(k, v, modify_keys: false) &.increment end add_addresses(data.map(&:first).map(&:to_s).compact) end |
#clear ⇒ void
This method is abstract.
This method returns an undefined value.
Clear all contents in the database.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 73 def clear if namespace keys.each do |key| delete(key) end delete(KEYS_ADDRESS) else database.clear end end |
#delete(address) ⇒ void
This method returns an undefined value.
37 38 39 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 37 def delete(address) database.delete(build_key(address)) end |
#empty? ⇒ Boolean
This method is abstract.
86 87 88 89 90 91 92 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 86 def empty? if namespace keys.empty? else database.empty? end end |
#exist?(address) ⇒ Boolean
This method is abstract.
44 45 46 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 44 def exist?(address) database.has_key?(build_key(address)) end |
#get(address) ⇒ Object?
23 24 25 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 23 def get(address, **) JSON.load(database[build_key(address)], symbolize_names: true) end |
#inspect ⇒ String
112 113 114 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 112 def inspect "#<#{self.class.name}: #{self.class.type}>" end |
#keys ⇒ Integer
This method is abstract.
50 51 52 53 54 55 56 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 50 def keys if namespace get(KEYS_ADDRESS) || [] else database.keys end end |
#persistable? ⇒ Boolean
This method is abstract.
96 97 98 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 96 def persistable? true end |
#put(address, object, modify_keys: true) ⇒ void
This method returns an undefined value.
30 31 32 33 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 30 def put(address, object, modify_keys: true) database[build_key(address)] = object.to_json add_addresses([address]) if modify_keys end |
#stats ⇒ Object
This method is abstract.
60 61 62 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 60 def stats {} end |
#sync ⇒ void
This method is abstract.
This method returns an undefined value.
66 67 68 |
# File 'lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb', line 66 def sync database.sync end |