Module: Sequel::Plugins::ModificationDetection::InstanceMethods

Defined in:
lib/sequel/plugins/modification_detection.rb

Instance Method Summary collapse

Instance Method Details

#after_updateObject

Recalculate the column value hashes after updating.



48
49
50
51
# File 'lib/sequel/plugins/modification_detection.rb', line 48

def after_update
  super
  recalculate_values_hashes
end

#calculate_values_hashesObject

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



54
55
56
# File 'lib/sequel/plugins/modification_detection.rb', line 54

def calculate_values_hashes
  @values_hashes || recalculate_values_hashes
end

#changed_columnsObject

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sequel/plugins/modification_detection.rb', line 60

def changed_columns
  changed = super
  if vh = @values_hashes
    values = @values
    changed = changed.dup if frozen?
    vh.each do |c, v|
      match = values.has_key?(c) && v == values[c].hash
      if changed.include?(c)
        changed.delete(c) if match
      else
        changed << c unless match
      end
    end
  end
  changed
end