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:
- ruby/psych#522
- ruby/logger#20
- ruby/rdoc#658
- rubocop/rubocop#8748
  • Loading branch information
tagliala committed Sep 27, 2024
1 parent cb01bb3 commit ba7d419
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
25 changes: 13 additions & 12 deletions lib/inline_svg.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
require "inline_svg/version"
require "inline_svg/action_view/helpers"
require "inline_svg/asset_file"
require "inline_svg/cached_asset_file"
require "inline_svg/finds_asset_paths"
require "inline_svg/propshaft_asset_finder"
require "inline_svg/static_asset_finder"
require "inline_svg/webpack_asset_finder"
require "inline_svg/transform_pipeline"
require "inline_svg/io_resource"

require "inline_svg/railtie" if defined?(Rails)
require_relative "inline_svg/version"
require_relative "inline_svg/action_view/helpers"
require_relative "inline_svg/asset_file"
require_relative "inline_svg/cached_asset_file"
require_relative "inline_svg/finds_asset_paths"
require_relative "inline_svg/propshaft_asset_finder"
require_relative "inline_svg/static_asset_finder"
require_relative "inline_svg/webpack_asset_finder"
require_relative "inline_svg/transform_pipeline"
require_relative "inline_svg/io_resource"

require_relative "inline_svg/railtie" if defined?(Rails)

require 'active_support'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/string'
Expand Down
2 changes: 1 addition & 1 deletion lib/inline_svg/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module InlineSvg
class Railtie < ::Rails::Railtie
initializer "inline_svg.action_view" do |app|
ActiveSupport.on_load :action_view do
require "inline_svg/action_view/helpers"
require_relative "action_view/helpers"
include InlineSvg::ActionView::Helpers
end
end
Expand Down
30 changes: 15 additions & 15 deletions lib/inline_svg/transform_pipeline/transformations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ def self.no_transform
end
end

require 'inline_svg/transform_pipeline/transformations/transformation'
require 'inline_svg/transform_pipeline/transformations/no_comment'
require 'inline_svg/transform_pipeline/transformations/class_attribute'
require 'inline_svg/transform_pipeline/transformations/style_attribute'
require 'inline_svg/transform_pipeline/transformations/title'
require 'inline_svg/transform_pipeline/transformations/description'
require 'inline_svg/transform_pipeline/transformations/size'
require 'inline_svg/transform_pipeline/transformations/height'
require 'inline_svg/transform_pipeline/transformations/width'
require 'inline_svg/transform_pipeline/transformations/view_box'
require 'inline_svg/transform_pipeline/transformations/id_attribute'
require 'inline_svg/transform_pipeline/transformations/data_attributes'
require 'inline_svg/transform_pipeline/transformations/preserve_aspect_ratio'
require 'inline_svg/transform_pipeline/transformations/aria_attributes'
require "inline_svg/transform_pipeline/transformations/aria_hidden_attribute"
require_relative 'transformations/transformation'
require_relative 'transformations/no_comment'
require_relative 'transformations/class_attribute'
require_relative 'transformations/style_attribute'
require_relative 'transformations/title'
require_relative 'transformations/description'
require_relative 'transformations/size'
require_relative 'transformations/height'
require_relative 'transformations/width'
require_relative 'transformations/view_box'
require_relative 'transformations/id_attribute'
require_relative 'transformations/data_attributes'
require_relative 'transformations/preserve_aspect_ratio'
require_relative 'transformations/aria_attributes'
require_relative "transformations/aria_hidden_attribute"

0 comments on commit ba7d419

Please sign in to comment.