mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Extract private method: Events::Base#metadatum_from_model_method
This commit is contained in:
parent
cb0af4f242
commit
0ed023ccde
1 changed files with 17 additions and 9 deletions
|
@ -196,20 +196,28 @@ module PaperTrail
|
|||
if value.respond_to?(:call)
|
||||
value.call(@record)
|
||||
elsif value.is_a?(Symbol) && @record.respond_to?(value, true)
|
||||
# If it is an attribute that is changing in an existing object,
|
||||
# be sure to grab the current version.
|
||||
if event != "create" &&
|
||||
@record.has_attribute?(value) &&
|
||||
attribute_changed_in_latest_version?(value)
|
||||
attribute_in_previous_version(value, false)
|
||||
else
|
||||
@record.send(value)
|
||||
end
|
||||
metadatum_from_model_method(event, value)
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
# The model method can either be an attribute or a non-attribute method.
|
||||
#
|
||||
# If it is an attribute that is changing in an existing object,
|
||||
# be sure to grab the correct version.
|
||||
#
|
||||
# @api private
|
||||
def metadatum_from_model_method(event, method)
|
||||
if event != "create" &&
|
||||
@record.has_attribute?(method) &&
|
||||
attribute_changed_in_latest_version?(method)
|
||||
attribute_in_previous_version(method, false)
|
||||
else
|
||||
@record.send(method)
|
||||
end
|
||||
end
|
||||
|
||||
# @api private
|
||||
def notable_changes
|
||||
changes_in_latest_version.delete_if { |k, _v|
|
||||
|
|
Loading…
Reference in a new issue