module Sandthorn::AggregateRoot::Marshal
Public Instance Methods
aggregate_initialize(*args)
click to toggle source
# File lib/sandthorn/aggregate_root_marshal.rb, line 5 def aggregate_initialize *args @aggregate_attribute_deltas = {} @aggregate_stored_instance_variables = {} end
get_delta()
click to toggle source
# File lib/sandthorn/aggregate_root_marshal.rb, line 20 def get_delta deltas = extract_relevant_aggregate_instance_variables deltas.each { |d| delta_attribute(d) } result = @aggregate_attribute_deltas clear_aggregate_deltas result end
set_instance_variables!(attribute)
click to toggle source
Calls superclass method
# File lib/sandthorn/aggregate_root_marshal.rb, line 10 def set_instance_variables! attribute super attribute init_vars = extract_relevant_aggregate_instance_variables init_vars.each do |attribute_name| @aggregate_stored_instance_variables[attribute_name] = ::Marshal.dump(instance_variable_get(attribute_name)) end end
Private Instance Methods
clear_aggregate_deltas()
click to toggle source
# File lib/sandthorn/aggregate_root_marshal.rb, line 55 def clear_aggregate_deltas @aggregate_attribute_deltas = {} end
delta_attribute(attribute_name)
click to toggle source
# File lib/sandthorn/aggregate_root_marshal.rb, line 31 def delta_attribute attribute_name old_dump = @aggregate_stored_instance_variables[attribute_name] new_dump = ::Marshal.dump(instance_variable_get(attribute_name)) unless old_dump == new_dump store_attribute_deltas attribute_name, new_dump, old_dump store_aggregate_instance_variable attribute_name, new_dump end end
store_aggregate_instance_variable(attribute_name, new_dump)
click to toggle source
# File lib/sandthorn/aggregate_root_marshal.rb, line 51 def store_aggregate_instance_variable attribute_name, new_dump @aggregate_stored_instance_variables[attribute_name] = new_dump end
store_attribute_deltas(attribute_name, new_dump, old_dump)
click to toggle source
# File lib/sandthorn/aggregate_root_marshal.rb, line 41 def store_attribute_deltas attribute_name, new_dump, old_dump new_value_to_store = ::Marshal.load(new_dump) old_value_to_store = old_dump ? ::Marshal.load(old_dump) : nil @aggregate_attribute_deltas[attribute_name.to_s.delete("@").to_sym] = { old_value: old_value_to_store, new_value: new_value_to_store } end