Skip to content

Commit

Permalink
Merge pull request #13 from dtflowers/fix-routes-command-for-rails-7.1
Browse files Browse the repository at this point in the history
Fix routes command for Rails 7.1+
  • Loading branch information
amatsuda authored Jan 23, 2024
2 parents 285be26 + 708d261 commit 68f1dc3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
10 changes: 10 additions & 0 deletions lib/routes_lazy_routes/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,15 @@ def load_tasks(*)
load "#{__dir__}/tasks/routes_lazy_routes.rake"
end
end

# A monkey-patch that eager loads routes before the routes command is executed by prepending this module to the
# require_enviornment! method that's called when boot_application! is executed performing console commands.
module RoutesCommandEagerLoader
def require_environment!
super

RoutesLazyRoutes.eager_load!
end
end
end
end
14 changes: 0 additions & 14 deletions lib/routes_lazy_routes/command/routes_command.rb

This file was deleted.

3 changes: 1 addition & 2 deletions lib/routes_lazy_routes/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class Railtie < ::Rails::Railtie
Rails::Application.prepend RoutesLazyRoutes::Application::TaskLoader

if defined? Rails::Command::RoutesCommand
require_relative 'command/routes_command'
Rails::Command::RoutesCommand.prepend RoutesLazyRoutes::Command::RoutesCommand
Rails::Application.prepend RoutesLazyRoutes::Application::RoutesCommandEagerLoader
end

initializer :routes_lazy_routes, before: :add_routing_paths do
Expand Down

0 comments on commit 68f1dc3

Please sign in to comment.