class KeyValueTree::TransactionStore
Public Class Methods
new(store = MemoryStore.new())
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 5 def initialize(store = MemoryStore.new()) @store = store @access_mutex = Mutex.new() reset() end
Public Instance Methods
commit()
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 55 def commit @access_mutex.synchronize do @changed_properties.each do |key, value| @store.store(key, value) end @deleted_property_keys.each do |key| @store.delete(key) end reset() end end
delete(key)
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 27 def delete(key) @access_mutex.synchronize do @changed_properties.delete(key) @deleted_property_keys << key end end
key(key)
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 11 def key(key) @access_mutex.synchronize do result = @changed_properties[key] return result unless result.nil? @store.key(key) end end
keys()
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 34 def keys @access_mutex.synchronize do result = @store.keys + @changed_properties.keys @deleted_property_keys.each do |key| result.delete(key) end result end end
pending_changes?()
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 73 def pending_changes? !(@changed_properties.empty? && @deleted_property_keys.empty?) end
rollback()
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 67 def rollback @access_mutex.synchronize do reset() end end
store(key, value)
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 19 def store(key, value) @access_mutex.synchronize do @changed_properties[key] = value @deleted_property_keys.delete(key) value end end
to_hash()
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 44 def to_hash result = @store.to_hash @changed_properties.each do |key, value| result[key] = value end @deleted_property_keys.each do |key| result.delete(key) end result end
Private Instance Methods
reset()
click to toggle source
# File lib/keyvaluetree/transaction_store.rb, line 79 def reset @changed_properties = {} @deleted_property_keys = [] end