Module: Gemmy::Patches::HashPatch::PersistedHash
- Defined in:
- lib/gemmy/patches/hash_patch.rb
Overview
Helper methods for the persistence patch
Instance Method Summary collapse
- #clear ⇒ Object
- #data ⇒ Object
- #get(*keys, disk: true) ⇒ Object
- #set(*keys, val) ⇒ Object
-
#set_state(hash) ⇒ Object
This won’t autovivify the hash automatically.
Instance Method Details
#clear ⇒ Object
345 346 347 348 349 |
# File 'lib/gemmy/patches/hash_patch.rb', line 345 def clear autovivified = Gemmy.patch("hash/i/autovivified")\ .method(:_autovivified) @store.transaction { @store[:data] = autovivified.call({}) } end |
#data ⇒ Object
336 337 338 |
# File 'lib/gemmy/patches/hash_patch.rb', line 336 def data @store.transaction { @store[:data] } end |
#get(*keys, disk: true) ⇒ Object
325 326 327 |
# File 'lib/gemmy/patches/hash_patch.rb', line 325 def get(*keys, disk: true) disk ? @store.transaction { @store[:data].dig(*keys) } : dig(*keys) end |
#set(*keys, val) ⇒ Object
328 329 330 331 332 333 334 335 |
# File 'lib/gemmy/patches/hash_patch.rb', line 328 def set(*keys, val) bury = Gemmy::Patches::HashPatch::InstanceMethods::Bury.method(:bury) bury.call(self, *keys, val) @store.transaction do bury.call(@store[:data], *(keys + [val])) end val end |
#set_state(hash) ⇒ Object
This won’t autovivify the hash automatically
341 342 343 |
# File 'lib/gemmy/patches/hash_patch.rb', line 341 def set_state(hash) @store.transaction { @store[:data] = hash } end |