Class: TrackChanges::Diff

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/track_changes/diff.rb

Instance Method Summary collapse

Instance Method Details

#changesObject

Returns a hash of changes where the key is the field name and the value is an array of the from value and the to value



17
18
19
20
21
# File 'app/models/track_changes/diff.rb', line 17

def changes
  Hash[(from.keys + to.keys).collect do |key|
    [key, [from[key], to[key]]]
  end]
end

#visible_changesObject

Returns changes but only those where the string representation of the value has changed



11
12
13
# File 'app/models/track_changes/diff.rb', line 11

def visible_changes
  changes.select {|key, (from, to)| (from.present? || to.present?) && (from.to_s != to.to_s) }
end