From c6956945a0d8b31a7ec656e23db3b6a32092ee94 Mon Sep 17 00:00:00 2001 From: Patrick Hogan Date: Fri, 20 Sep 2024 14:35:42 -0500 Subject: [PATCH] Add reload! as a IRB::HelperMethod so it can be combined with other calls in a single statement. It is useful to iterate and test in the console by reloading and executing something in a single line command. Something like: reload!; Post.find(123).test_a_thing This makes it easy to quickly switch to the console, hit up and enter to re-execute after a code change. This restores functionality that used to work until a few months ago. --- railties/lib/rails/commands/console/irb_console.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/commands/console/irb_console.rb b/railties/lib/rails/commands/console/irb_console.rb index b2ec859025fc3..a11e7a58d1391 100644 --- a/railties/lib/rails/commands/console/irb_console.rb +++ b/railties/lib/rails/commands/console/irb_console.rb @@ -51,7 +51,16 @@ def execute(create = false) end end - class Reloader < IRB::Command::Base + class ReloadHelper < RailsHelperBase + description "Reloads the Rails application." + + def execute + puts "Reloading..." + Rails.application.reloader.reload! + end + end + + class ReloadCommand < IRB::Command::Base include ConsoleMethods category "Rails console" @@ -67,7 +76,8 @@ def execute(*) IRB::HelperMethod.register(:controller, ControllerInstance) IRB::HelperMethod.register(:new_session, NewSession) IRB::HelperMethod.register(:app, AppInstance) - IRB::Command.register(:reload!, Reloader) + IRB::HelperMethod.register(:reload!, ReloadHelper) + IRB::Command.register(:reload!, ReloadCommand) class IRBConsole def initialize(app)