Extract private method init_model_by_finding_item_id

This commit is contained in:
Jared Beck 2021-08-29 23:51:00 -04:00
parent df8cc94f27
commit c5baf370b0
2 changed files with 7 additions and 4 deletions

View File

@ -9,7 +9,7 @@
# Offense count: 5
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 18.3 # Goal: 17, the default
Max: 17.5 # Goal: 17, the default
# Offense count: 1
# Configuration parameters: IgnoredMethods.

View File

@ -60,9 +60,7 @@ module PaperTrail
model = if options[:dup] == true || version.event == "destroy"
klass.new
else
find_cond = { klass.primary_key => version.item_id }
version.item || klass.unscoped.where(find_cond).first || klass.new
version.item || init_model_by_finding_item_id(klass, version) || klass.new
end
if options[:unversioned_attributes] == :nil && !model.new_record?
@ -72,6 +70,11 @@ module PaperTrail
model
end
# @api private
def init_model_by_finding_item_id(klass, version)
klass.unscoped.where(klass.primary_key => version.item_id).first
end
# Look for attributes that exist in `model` and not in this version.
# These attributes should be set to nil. Modifies `attrs`.
# @api private