Repository: rails/rails
File: railties/lib/rails/application/finisher.rb (Ruby)

Code before:
        end
      end

      # Set routes reload after the finisher hook to ensure routes added in
      # the hook are taken into account.
      initializer :set_routes_reloader_hook do |app|
        reloader = routes_reloader
        reloader.eager_load = app.config.eager_load
        reloader.execute
        reloaders << reloader

        app.reloader.to_run do
          # We configure #execute rather than #execute_if_updated because if
          # autoloaded constants are cleared we need to reload routes also in
          # case any was used there, as in
          #
          #   mount MailPreview => 'mail_view'
          #
          # This means routes are also reloaded if i18n is updated, which
          # might not be necessary, but in order to be more precise we need
          # some sort of reloaders dependency support, to be added.
          require_unload_lock!
          reloader.execute
          ActiveSupport.run_load_hooks(:after_routes_loaded, self)
        end

        ActiveSupport.run_load_hooks(:after_routes_loaded, self)
      end

      # Set clearing dependencies after the finisher hook to ensure paths
      # added in the hook are taken into account.
      initializer :set_clear_dependencies_hook, group: :all do |app|
        callback = lambda do
          # Order matters.
          ActiveSupport::DescendantsTracker.clear(ActiveSupport::Dependencies._autoloaded_tracked_classes)
          ActiveSupport::Dependencies.clear
        end

        if config.reloading_enabled?
          if config.reload_classes_only_on_change
            app.reloader.check = lambda do
              app.reloaders.map(&:updated?).any?
            end
          else
            app.reloader.check = lambda { true }
          end
        else
          app.reloader.check = lambda { false }
        end

        if config.reloading_enabled?

Review comment (bug):
I was debugging for autoloaded constants at boot using @bensheldon script from his recent talk, and since I use Devise the `devise_for`calls autoloads ActiveRecord models at boot **when the config/routes.rb file is loaded**

I don't know why but when I debugged here, `app.routes` is not an instance of  `LazyRouteSet` even though `make_routes_lazy` initializer got called multiple times. it was still an instance of ` ActionDispatch::Routing::RouteSet` despite that initializer.

I had to set this manually in `config/application.rb` ( in `config/environments/development.rb` it didn't work)
```ruby
# config/application.rb
config.route_set_class = Rails::Engine::LazyRouteSet if Rails.env.local?
```

for my routes to not get loaded at boot on development.

I wish I could help more, I'm stuck at this point, thought this could maybe help

Code after:
        end
      end

      # Set routes reload after the finisher hook to ensure routes added in
      # the hook are taken into account.
      initializer :set_routes_reloader_hook do |app|
        reloader = routes_reloader
        reloader.eager_load = app.config.eager_load
        reloaders << reloader

        app.reloader.to_run do
          # We configure #execute rather than #execute_if_updated because if
          # autoloaded constants are cleared we need to reload routes also in
          # case any was used there, as in
          #
          #   mount MailPreview => 'mail_view'
          #
          # This means routes are also reloaded if i18n is updated, which
          # might not be necessary, but in order to be more precise we need
          # some sort of reloaders dependency support, to be added.
          require_unload_lock!
          reloader.execute
          ActiveSupport.run_load_hooks(:after_routes_loaded, self)
        end

        reloader.execute_unless_loaded if !app.routes.is_a?(Engine::LazyRouteSet) || app.config.eager_load
      end

      # Set clearing dependencies after the finisher hook to ensure paths
      # added in the hook are taken into account.
      initializer :set_clear_dependencies_hook, group: :all do |app|
        callback = lambda do
          # Order matters.
          ActiveSupport::DescendantsTracker.clear(ActiveSupport::Dependencies._autoloaded_tracked_classes)
          ActiveSupport::Dependencies.clear
        end

        if config.reloading_enabled?
          if config.reload_classes_only_on_change
            app.reloader.check = lambda do
              app.reloaders.map(&:updated?).any?
            end
          else
            app.reloader.check = lambda { true }
          end
        else
          app.reloader.check = lambda { false }
        end

        if config.reloading_enabled?
          if config.reload_classes_only_on_change