Skip to content

Commit

Permalink
Prefer require_relative for internal requires
Browse files Browse the repository at this point in the history
`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.

Ref:
- activeadmin/arbre#622
- activeadmin/inherited_resources#939
  • Loading branch information
tagliala committed Sep 20, 2024
1 parent 50489c2 commit a213979
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 60 deletions.
10 changes: 5 additions & 5 deletions lib/active_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ def wrap_block_for_active_support_notifications block
end

# Require things that don't support autoload
require "active_admin/engine"
require "active_admin/error"
require_relative "active_admin/engine"
require_relative "active_admin/error"

# Require internal plugins
require "active_admin/batch_actions"
require "active_admin/filters"
require_relative "active_admin/batch_actions"
require_relative "active_admin/filters"

# Require ORM-specific plugins
require "active_admin/orm/active_record" if defined? ActiveRecord
require_relative "active_admin/orm/active_record" if defined? ActiveRecord
6 changes: 3 additions & 3 deletions lib/active_admin/application.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require "active_admin/router"
require "active_admin/application_settings"
require "active_admin/namespace_settings"
require_relative "router"
require_relative "application_settings"
require_relative "namespace_settings"

module ActiveAdmin
class Application
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/application_settings.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/settings_node"
require_relative "settings_node"

module ActiveAdmin
class ApplicationSettings < SettingsNode
Expand Down
8 changes: 4 additions & 4 deletions lib/active_admin/batch_actions.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true
ActiveAdmin.before_load do |app|
require "active_admin/batch_actions/resource_extension"
require "active_admin/batch_actions/controller"
require_relative "batch_actions/resource_extension"
require_relative "batch_actions/controller"

# Add our Extensions
ActiveAdmin::Resource.send :include, ActiveAdmin::BatchActions::ResourceExtension
ActiveAdmin::ResourceController.send :include, ActiveAdmin::BatchActions::Controller

require "active_admin/batch_actions/views/batch_action_form"
require "active_admin/batch_actions/views/selection_cells"
require_relative "batch_actions/views/batch_action_form"
require_relative "batch_actions/views/selection_cells"
end
2 changes: 1 addition & 1 deletion lib/active_admin/batch_actions/views/batch_action_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/component"
require_relative "../../component"

module ActiveAdmin
module BatchActions
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/batch_actions/views/selection_cells.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/component"
require_relative "../../component"

module ActiveAdmin
module BatchActions
Expand Down
4 changes: 2 additions & 2 deletions lib/active_admin/dynamic_settings_node.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require "active_admin/dynamic_setting"
require "active_admin/settings_node"
require_relative "dynamic_setting"
require_relative "settings_node"

module ActiveAdmin

Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Engine < ::Rails::Engine
end

initializer "active_admin.routes" do
require "active_admin/helpers/routes/url_helpers"
require_relative "helpers/routes/url_helpers"
end

initializer "active_admin.deprecator" do |app|
Expand Down
10 changes: 5 additions & 5 deletions lib/active_admin/filters.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true
require "active_admin/filters/dsl"
require "active_admin/filters/resource_extension"
require "active_admin/filters/formtastic_addons"
require "active_admin/filters/forms"
require "active_admin/helpers/optional_display"
require_relative "filters/dsl"
require_relative "filters/resource_extension"
require_relative "filters/formtastic_addons"
require_relative "filters/forms"
require_relative "helpers/optional_display"

# Add our Extensions
ActiveAdmin::ResourceDSL.send :include, ActiveAdmin::Filters::DSL
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/filters/active.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/filters/active_filter"
require_relative "active_filter"

module ActiveAdmin
module Filters
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/filters/resource_extension.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/filters/active"
require_relative "active"

module ActiveAdmin
module Filters
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/localizers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/localizers/resource_localizer"
require_relative "localizers/resource_localizer"

module ActiveAdmin
module Localizers
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/menu_item.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'active_admin/view_helpers/method_or_proc_helper'
require_relative "view_helpers/method_or_proc_helper"

module ActiveAdmin
class MenuItem
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/namespace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/resource_collection"
require_relative "resource_collection"

module ActiveAdmin

Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/namespace_settings.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/dynamic_settings_node"
require_relative "dynamic_settings_node"

module ActiveAdmin
class NamespaceSettings < DynamicSettingsNode
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/orm/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

ActiveAdmin::DatabaseHitDuringLoad.database_error_classes << ActiveRecord::StatementInvalid

require "active_admin/orm/active_record/comments"
require_relative "active_record/comments"
6 changes: 3 additions & 3 deletions lib/active_admin/orm/active_record/comments.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require "active_admin/orm/active_record/comments/views"
require "active_admin/orm/active_record/comments/namespace_helper"
require "active_admin/orm/active_record/comments/resource_helper"
require_relative "comments/views"
require_relative "comments/namespace_helper"
require_relative "comments/resource_helper"

# Add the comments configuration
ActiveAdmin::Application.inheritable_setting :comments, true
Expand Down
4 changes: 2 additions & 2 deletions lib/active_admin/orm/active_record/comments/views.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true
require "active_admin/views"
require "active_admin/orm/active_record/comments/views/active_admin_comments"
require_relative "../../../views"
require_relative "views/active_admin_comments"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/views"
require_relative "../../../../views"

module ActiveAdmin
module Comments
Expand Down
32 changes: 16 additions & 16 deletions lib/active_admin/resource.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# frozen_string_literal: true
require "active_admin/view_helpers/method_or_proc_helper"
require "active_admin/resource/action_items"
require "active_admin/resource/attributes"
require "active_admin/resource/controllers"
require "active_admin/resource/menu"
require "active_admin/resource/page_presenters"
require "active_admin/resource/pagination"
require "active_admin/resource/routes"
require "active_admin/resource/naming"
require "active_admin/resource/scopes"
require "active_admin/resource/includes"
require "active_admin/resource/scope_to"
require "active_admin/resource/sidebars"
require "active_admin/resource/belongs_to"
require "active_admin/resource/ordering"
require "active_admin/resource/model"
require_relative "view_helpers/method_or_proc_helper"
require_relative "resource/action_items"
require_relative "resource/attributes"
require_relative "resource/controllers"
require_relative "resource/menu"
require_relative "resource/page_presenters"
require_relative "resource/pagination"
require_relative "resource/routes"
require_relative "resource/naming"
require_relative "resource/scopes"
require_relative "resource/includes"
require_relative "resource/scope_to"
require_relative "resource/sidebars"
require_relative "resource/belongs_to"
require_relative "resource/ordering"
require_relative "resource/model"

module ActiveAdmin

Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/resource/action_items.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/helpers/optional_display"
require_relative "../helpers/optional_display"

module ActiveAdmin

Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/resource/belongs_to.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/resource"
require_relative "../resource"

module ActiveAdmin
class Resource
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/resource/sidebars.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "active_admin/helpers/optional_display"
require_relative "../helpers/optional_display"

module ActiveAdmin

Expand Down
4 changes: 2 additions & 2 deletions lib/active_admin/views/components/scopes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require "active_admin/async_count"
require "active_admin/view_helpers/method_or_proc_helper"
require_relative "../../async_count"
require_relative "../../view_helpers/method_or_proc_helper"

module ActiveAdmin
module Views
Expand Down
2 changes: 1 addition & 1 deletion lib/activeadmin.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# frozen_string_literal: true
require "active_admin"
require_relative "active_admin"
4 changes: 2 additions & 2 deletions lib/generators/active_admin/devise/devise_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require "active_admin/error"
require "active_admin/dependency"
require_relative "../../../active_admin/error"
require_relative "../../../active_admin/dependency"

module ActiveAdmin
module Generators
Expand Down

0 comments on commit a213979

Please sign in to comment.