Class: Artisan::Activity::Formatters::DiffChanges

Inherits:
Object
  • Object
show all
Defined in:
lib/artisan/activity/formatters/diff_changes.rb

Instance Method Summary collapse

Constructor Details

#initialize(change) ⇒ DiffChanges

Returns a new instance of DiffChanges.



6
7
8
# File 'lib/artisan/activity/formatters/diff_changes.rb', line 6

def initialize(change)
  @change = change
end

Instance Method Details

#diffsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/artisan/activity/formatters/diff_changes.rb', line 10

def diffs
  diffs = []
  return diffs if @change.changed_fields.nil? || @change.original_fields.nil?

  changed_fields = YAML::load(@change.changed_fields)
  original_fields = YAML::load(@change.original_fields)

  changed_fields.keys.each do |field|
    if fields_different?(changed_fields, original_fields, field)
      diffs << "#{field} changed from '#{display_nil(original_fields[field])}' to '#{display_nil(changed_fields[field])}'"
    end
  end
  return diffs
end