From 2fe07006c355733d6aca90aa3dfbd841082a3e49 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Tue, 26 Apr 2016 01:56:23 -0400 Subject: [PATCH] Extract private method init_unversioned_attrs --- .rubocop_todo.yml | 2 +- lib/paper_trail/reifier.rb | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1f45c233..1f101636 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 diff --git a/lib/paper_trail/reifier.rb b/lib/paper_trail/reifier.rb index cc2c9816..43c065e4 100644 --- a/lib/paper_trail/reifier.rb +++ b/lib/paper_trail/reifier.rb @@ -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