module Gemmy::Patches::HashPatch::PersistedHash
Helper methods for the persistence patch
Public Instance Methods
clear()
click to toggle source
# File lib/gemmy/patches/hash_patch.rb, line 382 def clear autovivified = Gemmy.patch("hash/i/autovivified")\ .method(:_autovivified) @store.transaction { @store[:data] = autovivified.call({}) } end
data()
click to toggle source
# File lib/gemmy/patches/hash_patch.rb, line 355 def data @store.transaction { @store[:data] } end
dig_delete(*keys)
click to toggle source
Delete functions like “dig_delete” I.e. if given a few keys as arguments, it will treat only the last as a delete key and all the rest as dig keys.
# File lib/gemmy/patches/hash_patch.rb, line 362 def dig_delete(*keys) key_to_delete = keys.pop if keys.empty? delete key_to_delete @store.transaction do @store[:data].delete key_to_delete end else dig(*keys).delete key_to_delete @store.transaction do @store[:data].dig(*keys).delete key_to_delete end end end
get(*keys, disk: true)
click to toggle source
# File lib/gemmy/patches/hash_patch.rb, line 342 def get(*keys, disk: true) disk ? @store.transaction { @store[:data].dig(*keys) } : dig(*keys) end
set(*keys, val)
click to toggle source
# File lib/gemmy/patches/hash_patch.rb, line 346 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)
click to toggle source
This won't autovivify the hash automatically
# File lib/gemmy/patches/hash_patch.rb, line 378 def set_state(hash) @store.transaction { @store[:data] = hash } end