Some small tweaks in PaperTrail::Model.
This commit is contained in:
parent
a23144fc04
commit
fa98219bbf
|
@ -98,7 +98,7 @@ module PaperTrail
|
||||||
end
|
end
|
||||||
|
|
||||||
def record_update
|
def record_update
|
||||||
if switched_on? && changed_and_we_care?
|
if switched_on? && changed_notably?
|
||||||
versions.build merge_metadata(:event => 'update',
|
versions.build merge_metadata(:event => 'update',
|
||||||
:object => object_to_string(item_before_change),
|
:object => object_to_string(item_before_change),
|
||||||
:whodunnit => PaperTrail.whodunnit)
|
:whodunnit => PaperTrail.whodunnit)
|
||||||
|
@ -124,20 +124,22 @@ module PaperTrail
|
||||||
end
|
end
|
||||||
|
|
||||||
def item_before_change
|
def item_before_change
|
||||||
previous = self.clone
|
self.clone.tap do |previous|
|
||||||
previous.id = id
|
previous.id = id
|
||||||
changes.each do |attr, ary|
|
changed_attributes.each { |attr, before| previous[attr] = before }
|
||||||
previous.send :write_attribute, attr.to_sym, ary.first
|
|
||||||
end
|
end
|
||||||
previous
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def object_to_string(object)
|
def object_to_string(object)
|
||||||
object.attributes.to_yaml
|
object.attributes.to_yaml
|
||||||
end
|
end
|
||||||
|
|
||||||
def changed_and_we_care?
|
def changed_notably?
|
||||||
changed? and !(changed - self.class.ignore).empty?
|
notably_changed.any?
|
||||||
|
end
|
||||||
|
|
||||||
|
def notably_changed
|
||||||
|
changed - self.class.ignore
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns `true` if PaperTrail is globally enabled and active for this class,
|
# Returns `true` if PaperTrail is globally enabled and active for this class,
|
||||||
|
|
Loading…
Reference in New Issue