From 5a2fae8cf2b365c48858565b16e1762f74ddc0af Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Thu, 19 Oct 2023 17:18:26 +0200 Subject: [PATCH] Use Rails' delegate `delegate` is already used in other parts of the library --- .rubocop_todo.yml | 7 ------- lib/chrono_model/time_machine.rb | 4 +--- lib/chrono_model/time_machine/history_model.rb | 8 ++------ 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 61284db..e42d281 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -57,13 +57,6 @@ Naming/VariableNumber: Exclude: - 'lib/chrono_model/adapter/upgrade.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforceForPrefixed. -Rails/Delegate: - Exclude: - - 'lib/chrono_model/time_machine.rb' - - 'lib/chrono_model/time_machine/history_model.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). Rails/SquishedSQLHeredocs: Exclude: diff --git a/lib/chrono_model/time_machine.rb b/lib/chrono_model/time_machine.rb index 8564fe2..4727b2f 100644 --- a/lib/chrono_model/time_machine.rb +++ b/lib/chrono_model/time_machine.rb @@ -102,9 +102,7 @@ def history? # Returns an ActiveRecord::Relation on the history of this model as # it was +time+ ago. - def as_of(time) - history.as_of(time) - end + delegate :as_of, to: :history def attribute_names_for_history_changes @attribute_names_for_history_changes ||= attribute_names - diff --git a/lib/chrono_model/time_machine/history_model.rb b/lib/chrono_model/time_machine/history_model.rb index ef187ca..b76b2ba 100644 --- a/lib/chrono_model/time_machine/history_model.rb +++ b/lib/chrono_model/time_machine/history_model.rb @@ -109,9 +109,7 @@ def of(object) # # As such it is overriden here to return the same contents that # the parent would have returned. - def sti_name - superclass.sti_name - end + delegate :sti_name, to: :superclass # For STI to work, the history model needs to have the exact same # semantics as the model it inherits from. However given it is @@ -120,9 +118,7 @@ def sti_name # same exact hierarchy location as its parent, thus this is defined in # this override. # - def descends_from_active_record? - superclass.descends_from_active_record? - end + delegate :descends_from_active_record?, to: :superclass private