From df8cc94f27a64e7a2c32912dabac476df9ff66af Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 29 Aug 2021 23:36:49 -0400 Subject: [PATCH] Extract private method: assert_valid_recording_order_for_on_destroy --- .rubocop_todo.yml | 6 +++--- lib/paper_trail/model_config.rb | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 83c1dd28..07ccb876 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -9,17 +9,17 @@ # Offense count: 5 # Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: - Max: 19 # Goal: the default (17?) + Max: 18.3 # Goal: 17, the default # Offense count: 1 # Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: - Max: 8 # Goal: 7 + Max: 8 # Goal: 7, the default # Offense count: 1 # Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: - Max: 9 # Goal: 7 + Max: 9 # Goal: 8, the default # Offense count: 56 # Cop supports --auto-correct. diff --git a/lib/paper_trail/model_config.rb b/lib/paper_trail/model_config.rb index b976bd5b..60cef85a 100644 --- a/lib/paper_trail/model_config.rb +++ b/lib/paper_trail/model_config.rb @@ -48,13 +48,7 @@ def on_create # # @api public def on_destroy(recording_order = "before") - unless %w[after before].include?(recording_order.to_s) - raise ArgumentError, 'recording order can only be "after" or "before"' - end - - if recording_order.to_s == "after" && cannot_record_after_destroy? - raise Error, E_CANNOT_RECORD_AFTER_DESTROY - end + assert_valid_recording_order_for_on_destroy(recording_order) @model_class.send( "#{recording_order}_destroy", @@ -141,6 +135,17 @@ def assert_concrete_activerecord_class(class_name) end end + # @api private + def assert_valid_recording_order_for_on_destroy(recording_order) + unless %w[after before].include?(recording_order.to_s) + raise ArgumentError, 'recording order can only be "after" or "before"' + end + + if recording_order.to_s == "after" && cannot_record_after_destroy? + raise Error, E_CANNOT_RECORD_AFTER_DESTROY + end + end + def cannot_record_after_destroy? ::ActiveRecord::Base.belongs_to_required_by_default end