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

Conversation

hahmed
Copy link
Contributor

@hahmed hahmed commented May 11, 2020

Summary

Add the ability to reboot! inside rails a console, which will clear all local/instance variables and run reload! too. This will run a new console session within the current session and also close the old IRB context.

https://discuss.rubyonrails.org/t/console-is-not-aware-of-code-changes/74782/14

Not sure if a changelog needs to be added?

@rails-bot rails-bot bot added the railties label May 11, 2020
@simi
Copy link
Contributor

simi commented May 11, 2020

This will not reload the code actually. AFAIK the original idea was to restart console. Something like exec('bin/rails c'), but more generic (preserving original command with all arguments) would work here IMHO.

@hahmed hahmed marked this pull request as ready for review May 11, 2020 20:55
@hahmed
Copy link
Contributor Author

hahmed commented May 11, 2020

The env variables look to be preserved, below is the output, is that ok?

blob1 HEAD % bin/rails c -e test       
Running via Spring preloader in process 99887
Loading test environment (Rails 6.1.0.alpha)
irb(main):001:0> e = :hello
=> :hello
irb(main):002:0> reboot!
Rebooting...
irb(main):001:0> Rails.env
=> "test"
irb(main):002:0> e
Traceback (most recent call last):
        2: from (irb):2
        1: from (irb):2
NameError (undefined local variable or method `e' for main:Object)

@hahmed
Copy link
Contributor Author

hahmed commented May 11, 2020

This will not reload the code actually.

Good catch, fixed (I was focused on 💥 the session and forgot about this)

AFAIK the original idea was to restart console. Something like exec('bin/rails c')

We already have access to IRB, so I went with a method call instead of a system call, so we don't need to jump through thor/rails cli...

@rails-bot
Copy link

rails-bot bot commented Aug 10, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Aug 10, 2020
@hahmed hahmed closed this Aug 11, 2020
@hahmed hahmed reopened this Aug 11, 2020
@rails-bot rails-bot bot removed the stale label Aug 11, 2020
@rails-bot
Copy link

rails-bot bot commented Nov 9, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Nov 9, 2020
@rails-bot rails-bot bot closed this Nov 16, 2020
@rafaelfranca rafaelfranca reopened this Nov 16, 2020
@rails-bot rails-bot bot removed the stale label Nov 16, 2020
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.

Base automatically changed from master to main January 14, 2021 17:01
@rails-bot
Copy link

rails-bot bot commented Apr 14, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Apr 14, 2021
@rails-bot rails-bot bot closed this Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants