Sha256: 6e3a3fbbe481df15e151de43e78510fe4eb05a1798b4d0355e47d54cbcc3876a

Contents?: true

Size: 1.48 KB

Versions: 68

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require "active_support/core_ext/module/delegation"

module Rails
  class Application
    class RoutesReloader
      include ActiveSupport::Callbacks

      attr_reader :route_sets, :paths, :external_routes
      attr_accessor :eager_load
      attr_writer :run_after_load_paths # :nodoc:
      delegate :execute_if_updated, :execute, :updated?, to: :updater

      def initialize
        @paths      = []
        @route_sets = []
        @external_routes = []
        @eager_load = false
      end

      def reload!
        clear!
        load_paths
        finalize!
        route_sets.each(&:eager_load!) if eager_load
      ensure
        revert
      end

    private
      def updater
        @updater ||= begin
          dirs = @external_routes.each_with_object({}) do |dir, hash|
            hash[dir.to_s] = %w(rb)
          end

          ActiveSupport::FileUpdateChecker.new(paths, dirs) { reload! }
        end
      end

      def clear!
        route_sets.each do |routes|
          routes.disable_clear_and_finalize = true
          routes.clear!
        end
      end

      def load_paths
        paths.each { |path| load(path) }
        run_after_load_paths.call
      end

      def run_after_load_paths
        @run_after_load_paths ||= -> { }
      end

      def finalize!
        route_sets.each(&:finalize!)
      end

      def revert
        route_sets.each do |routes|
          routes.disable_clear_and_finalize = false
        end
      end
    end
  end
end

Version data entries

68 entries across 64 versions & 7 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/railties-7.0.8.6/lib/rails/application/routes_reloader.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/railties-7.0.8.7/lib/rails/application/routes_reloader.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/application/routes_reloader.rb
railties-7.2.2.1 lib/rails/application/routes_reloader.rb
railties-7.1.5.1 lib/rails/application/routes_reloader.rb
railties-7.0.8.7 lib/rails/application/routes_reloader.rb
railties-7.2.2 lib/rails/application/routes_reloader.rb
railties-7.1.5 lib/rails/application/routes_reloader.rb
railties-7.2.1.2 lib/rails/application/routes_reloader.rb
railties-7.1.4.2 lib/rails/application/routes_reloader.rb
railties-7.0.8.6 lib/rails/application/routes_reloader.rb
railties-7.2.1.1 lib/rails/application/routes_reloader.rb
railties-7.1.4.1 lib/rails/application/routes_reloader.rb
railties-7.0.8.5 lib/rails/application/routes_reloader.rb
railties-7.1.4 lib/rails/application/routes_reloader.rb
railties-7.2.1 lib/rails/application/routes_reloader.rb
railties-7.2.0 lib/rails/application/routes_reloader.rb
railties-7.2.0.rc1 lib/rails/application/routes_reloader.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/application/routes_reloader.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/application/routes_reloader.rb