mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Extract private method init_unversioned_attrs
This commit is contained in:
parent
44206e1a49
commit
2fe07006c3
2 changed files with 10 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
|||
# one by one as the offenses are removed from the code base.
|
||||
|
||||
Metrics/AbcSize:
|
||||
Max: 32 # Goal: 15
|
||||
Max: 30 # Goal: 15
|
||||
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 13 # Goal: 6
|
||||
|
|
|
@ -22,10 +22,8 @@ module PaperTrail
|
|||
# class.
|
||||
if options[:dup] != true && version.item
|
||||
model = version.item
|
||||
# Look for attributes that exist in the model and not in this
|
||||
# version. These attributes should be set to nil.
|
||||
if options[:unversioned_attributes] == :nil
|
||||
(model.attribute_names - attrs.keys).each { |k| attrs[k] = nil }
|
||||
init_unversioned_attrs(attrs, model)
|
||||
end
|
||||
else
|
||||
klass = version_reification_class(version, attrs)
|
||||
|
@ -35,9 +33,7 @@ module PaperTrail
|
|||
model = klass.new
|
||||
elsif options[:unversioned_attributes] == :nil
|
||||
model = item_found
|
||||
# Look for attributes that exist in the model and not in this
|
||||
# version. These attributes should be set to nil.
|
||||
(model.attribute_names - attrs.keys).each { |k| attrs[k] = nil }
|
||||
init_unversioned_attrs(attrs, model)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -131,6 +127,13 @@ module PaperTrail
|
|||
collection
|
||||
end
|
||||
|
||||
# Look for attributes that exist in `model` and not in this version.
|
||||
# These attributes should be set to nil. Modifies `attrs`.
|
||||
# @api private
|
||||
def init_unversioned_attrs(attrs, model)
|
||||
(model.attribute_names - attrs.keys).each { |k| attrs[k] = nil }
|
||||
end
|
||||
|
||||
# Given a HABTM association `assoc` and an `id`, return a version record
|
||||
# from the point in time identified by `transaction_id` or `version_at`.
|
||||
# @api private
|
||||
|
|
Loading…
Reference in a new issue