Extract private method init_model_by_finding_item_id
This commit is contained in:
parent
df8cc94f27
commit
c5baf370b0
|
@ -9,7 +9,7 @@
|
||||||
# Offense count: 5
|
# Offense count: 5
|
||||||
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Max: 18.3 # Goal: 17, the default
|
Max: 17.5 # Goal: 17, the default
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Configuration parameters: IgnoredMethods.
|
# Configuration parameters: IgnoredMethods.
|
||||||
|
|
|
@ -60,9 +60,7 @@ module PaperTrail
|
||||||
model = if options[:dup] == true || version.event == "destroy"
|
model = if options[:dup] == true || version.event == "destroy"
|
||||||
klass.new
|
klass.new
|
||||||
else
|
else
|
||||||
find_cond = { klass.primary_key => version.item_id }
|
version.item || init_model_by_finding_item_id(klass, version) || klass.new
|
||||||
|
|
||||||
version.item || klass.unscoped.where(find_cond).first || klass.new
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:unversioned_attributes] == :nil && !model.new_record?
|
if options[:unversioned_attributes] == :nil && !model.new_record?
|
||||||
|
@ -72,6 +70,11 @@ module PaperTrail
|
||||||
model
|
model
|
||||||
end
|
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.
|
# Look for attributes that exist in `model` and not in this version.
|
||||||
# These attributes should be set to nil. Modifies `attrs`.
|
# These attributes should be set to nil. Modifies `attrs`.
|
||||||
# @api private
|
# @api private
|
||||||
|
|
Loading…
Reference in New Issue