Module: Serialist::DirtyAdditions

Defined in:
lib/serialist/serialist_module.rb

Instance Method Summary collapse

Instance Method Details

#serialist_changesObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/serialist/serialist_module.rb', line 113

def serialist_changes
  full_changes = self.old_changes
  unless (slug = full_changes.delete(self.class.serialist_field.to_s)).blank?
    ((slug[0].try(:keys) || []) + (slug[1].try(:keys) || [])).uniq.each do |serialized_key| 
      attr_change = [(slug[0].try(:fetch, serialized_key) rescue nil), (slug[1].try(:fetch, serialized_key) rescue nil)]
      full_changes[serialized_key.to_s] = attr_change if attr_change[0] != attr_change[1]
    end
  end
  full_changes
end