Skip to content

Commit c695694

Browse files
committed
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.
1 parent 592a52b commit c695694

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

railties/lib/rails/commands/console/irb_console.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ def execute(create = false)
5151
end
5252
end
5353

54-
class Reloader < IRB::Command::Base
54+
class ReloadHelper < RailsHelperBase
55+
description "Reloads the Rails application."
56+
57+
def execute
58+
puts "Reloading..."
59+
Rails.application.reloader.reload!
60+
end
61+
end
62+
63+
class ReloadCommand < IRB::Command::Base
5564
include ConsoleMethods
5665

5766
category "Rails console"
@@ -67,7 +76,8 @@ def execute(*)
6776
IRB::HelperMethod.register(:controller, ControllerInstance)
6877
IRB::HelperMethod.register(:new_session, NewSession)
6978
IRB::HelperMethod.register(:app, AppInstance)
70-
IRB::Command.register(:reload!, Reloader)
79+
IRB::HelperMethod.register(:reload!, ReloadHelper)
80+
IRB::Command.register(:reload!, ReloadCommand)
7181

7282
class IRBConsole
7383
def initialize(app)

0 commit comments

Comments
 (0)