method

prevent_active_support_rails_requires

rails latest stable - Class: RailInspector::Requires

Method not available on this version

This method is only available on newer versions. The first available version (v8.1.1) is shown here.

prevent_active_support_rails_requires()
private

No documentation available.

# File tools/rail_inspector/lib/rail_inspector/requires.rb, line 40
      def prevent_active_support_rails_requires
        frameworks.each do |framework|
          next if framework == "activesupport"

          @rails_path.glob("#{framework}/lib/*.rb").each do |root_path|
            root_requires = @loads[root_path.to_s][:requires]
            next if root_requires.include?("active_support/rails")

            # required transitively
            next if root_requires.include?("action_dispatch")
            # action_pack namespace doesn't include any code
            # arel does not depend on active_support at all
            next if ["action_pack.rb", "arel.rb"].include?(root_path.basename.to_s)

            @exit = false
            puts root_path
            puts "  + \"active_support/rails\" (framework root)"
          end
        end

        active_support_rails_requires = @loads["activesupport/lib/active_support/rails.rb"][:requires]

        duplicated_requires = {}

        @loads.each do |path, file_loads|
          next if path.start_with? "activesupport"

          if active_support_rails_requires.intersect?(file_loads[:requires])
            duplicated_requires[path] = active_support_rails_requires.intersection(file_loads[:requires])
          end
        end

        duplicated_requires.each do |path, offenses|
          @exit = false
          puts path
          offenses.each do |duplicate_require|
            puts "  - #{duplicate_require} (active_support/rails)"

            next unless @autocorrect

            file = File.read(path)
            file.gsub!("require \"#{duplicate_require}\"\n", "")

            File.write(path, file)
          end
        end
      end