module Sequel::Plugins::ModificationDetection::InstanceMethods

Public Instance Methods

after_update() click to toggle source

Recalculate the column value hashes after updating.

Calls superclass method
   # File lib/sequel/plugins/modification_detection.rb
50 def after_update
51   super
52   recalculate_values_hashes
53 end
calculate_values_hashes() click to toggle source

Calculate the column hash values if they haven't been already calculated.

   # File lib/sequel/plugins/modification_detection.rb
56 def calculate_values_hashes
57   @values_hashes || recalculate_values_hashes
58 end
changed_columns() click to toggle source

Detect which columns have been modified by comparing the cached hash value to the hash of the current value.

Calls superclass method
   # File lib/sequel/plugins/modification_detection.rb
62 def changed_columns
63   changed = super
64   if vh = @values_hashes
65     values = @values
66     changed = changed.dup if frozen?
67     vh.each do |c, v|
68       match = values.has_key?(c) && v == values[c].hash
69       if changed.include?(c)
70         changed.delete(c) if match
71       else
72         changed << c unless match
73       end
74     end
75   end
76   changed
77 end

Private Instance Methods

_refresh(dataset) click to toggle source

Recalculate the column value hashes after manually refreshing.

Calls superclass method
   # File lib/sequel/plugins/modification_detection.rb
82 def _refresh(dataset)
83   super
84   recalculate_values_hashes
85 end
_save_refresh() click to toggle source

Recalculate the column value hashes after refreshing after saving a new object.

Calls superclass method
   # File lib/sequel/plugins/modification_detection.rb
88 def _save_refresh
89   super
90   recalculate_values_hashes
91 end
recalculate_values_hashes() click to toggle source

Recalculate the column value hashes, caching them for later use.

    # File lib/sequel/plugins/modification_detection.rb
 94 def recalculate_values_hashes
 95   vh = {}
 96   @values.each do |k,v|
 97     vh[k] = v.hash
 98   end
 99   @values_hashes = vh.freeze
100 end