From f65722b590a50a975771801b755378fc1d5efdd9 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Fri, 20 Sep 2024 09:09:03 +0200 Subject: [PATCH] Prefer require_relative for internal requires `require_relative` is preferred over `require` for files within the same project because it uses paths relative to the current file, making code more portable and less dependent on the load path. This change updates internal requires to use `require_relative` for consistency, performance, and improved portability. Refs: - rubocop/rubocop#8748 --- .rubocop_todo.yml | 4 ++-- .../chronomodel_adapter.rb | 2 +- lib/chrono_model.rb | 20 +++++++++---------- lib/chrono_model/adapter.rb | 10 +++++----- lib/chrono_model/db_console.rb | 2 +- lib/chrono_model/patches.rb | 14 ++++++------- lib/chrono_model/railtie.rb | 2 +- lib/chrono_model/time_machine.rb | 6 +++--- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fe72539..7cc6044 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --no-offense-counts --no-auto-gen-timestamp` -# using RuboCop version 1.64.1. +# using RuboCop version 1.66.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -8,7 +8,7 @@ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 71 + Max: 70 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. # AllowedMethods: refine diff --git a/lib/active_record/connection_adapters/chronomodel_adapter.rb b/lib/active_record/connection_adapters/chronomodel_adapter.rb index d79bb10..3c8619f 100644 --- a/lib/active_record/connection_adapters/chronomodel_adapter.rb +++ b/lib/active_record/connection_adapters/chronomodel_adapter.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'chrono_model' +require_relative '../../chrono_model' module ActiveRecord # TODO: Remove when dropping Rails < 7.2 compatibility diff --git a/lib/chrono_model.rb b/lib/chrono_model.rb index d4a87fd..8e6cf1a 100644 --- a/lib/chrono_model.rb +++ b/lib/chrono_model.rb @@ -2,16 +2,16 @@ require 'active_record' -require 'chrono_model/chrono' -require 'chrono_model/conversions' -require 'chrono_model/patches' -require 'chrono_model/adapter' -require 'chrono_model/time_machine' -require 'chrono_model/time_gate' -require 'chrono_model/version' - -require 'chrono_model/railtie' if defined?(Rails::Railtie) -require 'chrono_model/db_console' if defined?(Rails::DBConsole) && Rails.version < '7.1' +require_relative 'chrono_model/chrono' +require_relative 'chrono_model/conversions' +require_relative 'chrono_model/patches' +require_relative 'chrono_model/adapter' +require_relative 'chrono_model/time_machine' +require_relative 'chrono_model/time_gate' +require_relative 'chrono_model/version' + +require_relative 'chrono_model/railtie' if defined?(Rails::Railtie) +require_relative 'chrono_model/db_console' if defined?(Rails::DBConsole) && Rails.version < '7.1' module ChronoModel class Error < ActiveRecord::ActiveRecordError # :nodoc: diff --git a/lib/chrono_model/adapter.rb b/lib/chrono_model/adapter.rb index 259fe91..afdfee6 100644 --- a/lib/chrono_model/adapter.rb +++ b/lib/chrono_model/adapter.rb @@ -2,12 +2,12 @@ require 'active_record/connection_adapters/postgresql_adapter' -require 'chrono_model/adapter/migrations' -require 'chrono_model/adapter/migrations_modules/stable' +require_relative 'adapter/migrations' +require_relative 'adapter/migrations_modules/stable' -require 'chrono_model/adapter/ddl' -require 'chrono_model/adapter/indexes' -require 'chrono_model/adapter/upgrade' +require_relative 'adapter/ddl' +require_relative 'adapter/indexes' +require_relative 'adapter/upgrade' module ChronoModel # This class implements all ActiveRecord::ConnectionAdapters::SchemaStatements diff --git a/lib/chrono_model/db_console.rb b/lib/chrono_model/db_console.rb index 56bd549..78ccbe4 100644 --- a/lib/chrono_model/db_console.rb +++ b/lib/chrono_model/db_console.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'chrono_model/patches/db_console' +require_relative 'patches/db_console' Rails::DBConsole.prepend ChronoModel::Patches::DBConsole::DbConfig diff --git a/lib/chrono_model/patches.rb b/lib/chrono_model/patches.rb index 4130e9a..a9179e1 100644 --- a/lib/chrono_model/patches.rb +++ b/lib/chrono_model/patches.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'chrono_model/patches/as_of_time_holder' -require 'chrono_model/patches/as_of_time_relation' +require_relative 'patches/as_of_time_holder' +require_relative 'patches/as_of_time_relation' -require 'chrono_model/patches/join_node' -require 'chrono_model/patches/relation' -require 'chrono_model/patches/preloader' -require 'chrono_model/patches/association' -require 'chrono_model/patches/batches' +require_relative 'patches/join_node' +require_relative 'patches/relation' +require_relative 'patches/preloader' +require_relative 'patches/association' +require_relative 'patches/batches' diff --git a/lib/chrono_model/railtie.rb b/lib/chrono_model/railtie.rb index 9b04154..b8f972f 100644 --- a/lib/chrono_model/railtie.rb +++ b/lib/chrono_model/railtie.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_record/tasks/chronomodel_database_tasks' +require_relative '../active_record/tasks/chronomodel_database_tasks' module ChronoModel class Railtie < ::Rails::Railtie diff --git a/lib/chrono_model/time_machine.rb b/lib/chrono_model/time_machine.rb index 082d580..4b9125d 100644 --- a/lib/chrono_model/time_machine.rb +++ b/lib/chrono_model/time_machine.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'chrono_model/time_machine/time_query' -require 'chrono_model/time_machine/timeline' -require 'chrono_model/time_machine/history_model' +require_relative 'time_machine/time_query' +require_relative 'time_machine/timeline' +require_relative 'time_machine/history_model' module ChronoModel module TimeMachine