From b14e7719aaffc311062a47c89971d968c1396d0d Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 19:23:15 -0400 Subject: [PATCH] Extract private method: reify_associations --- .rubocop.yml | 6 ++++++ lib/paper_trail/reifier.rb | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3708d372..14978bdb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -39,6 +39,12 @@ Style/DotPosition: Style/DoubleNegation: Enabled: false +# The decision of when to use a guard clause to improve readability is subtle, +# and it's not clear that it can be linted. Certainly, the default +# `MinBodyLength` of 1 can actually hurt readability. +Style/GuardClause: + MinBodyLength: 3 + # The Ruby Style Guide says: # # > Use \ instead of + or << to concatenate two string literals at line end. diff --git a/lib/paper_trail/reifier.rb b/lib/paper_trail/reifier.rb index b27eead0..68496203 100644 --- a/lib/paper_trail/reifier.rb +++ b/lib/paper_trail/reifier.rb @@ -53,22 +53,22 @@ module PaperTrail end reify_attributes(model, version, attrs) - model.send "#{model.class.version_association_name}=", version - - unless options[:has_one] == false - reify_has_ones version.transaction_id, model, options - end - - unless options[:has_many] == false - reify_has_manys version.transaction_id, model, options - end - + reify_associations(model, options, version) model end private + def reify_associations(model, options, version) + if options[:has_one] + reify_has_ones version.transaction_id, model, options + end + if options[:has_many] + reify_has_manys version.transaction_id, model, options + end + end + # Set all the attributes in this version on the model. def reify_attributes(model, version, attrs) enums = model.class.respond_to?(:defined_enums) ? model.class.defined_enums : {}