Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reboot! to rails console #39239

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions railties/lib/rails/console/app.rb
Expand Up @@ -2,6 +2,7 @@

require "active_support/all"
require "action_controller"
require "irb"

module Rails
module ConsoleMethods
Expand Down Expand Up @@ -34,5 +35,15 @@ def reload!(print = true)
Rails.application.reloader.reload!
true
end

# reboot a brand new session and exit current context
def reboot!(print = true)
puts "Rebooting..." if print
existing_context = IRB.CurrentContext
Rails.application.reloader.reload!
IRB.start
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The console is not always IRB. It is configurable in config.console. We need to take in consideration this.

existing_context.exit
true
end
end
end
11 changes: 11 additions & 0 deletions railties/test/application/console_test.rb
Expand Up @@ -174,4 +174,15 @@ def test_environment_option_and_irb_option
write_prompt "puts Rails.env", "puts Rails.env\r\ntest"
@primary.puts "quit"
end

def test_reboot
options = "-- --verbose"
options += " --singleline --nocolorize" if RUBY_VERSION >= "2.7"
spawn_console(options)

write_prompt "a = 1", "a = 1"
write_prompt "reboot!", "Rebooting..."
write_prompt "a", "undefined local variable or method `a' for main:Object"
@primary.puts "quit"
end
end