Add reload command to re-load files loaded via require#1157
Add reload command to re-load files loaded via require#1157ahogappa wants to merge 4 commits intoruby:masterfrom
Conversation
|
|
||
| register(:cd, Command::CD) | ||
| register(:copy, Command::Copy) | ||
| register(:reload, Command::Reload) |
There was a problem hiding this comment.
The command name reload might be confused with Rails console's reload!. Consider alternatives like reload_requires or refresh.
There was a problem hiding this comment.
I think the name should have box in it so users understand it's closely associated with that language feature.
3013701 to
fe7a510
Compare
fe7a510 to
30f842f
Compare
30f842f to
cdbbb67
Compare
| module Command | ||
| class Reload < Base | ||
| category "IRB" | ||
| description "Reload files that were loaded via require in IRB session." |
There was a problem hiding this comment.
We should mark this as experimental.
And this command should have detailed help_mesasge to explain what it's for and how to set things up to run it.
|
|
||
| register(:cd, Command::CD) | ||
| register(:copy, Command::Copy) | ||
| register(:reload, Command::Reload) |
There was a problem hiding this comment.
I think the name should have box in it so users understand it's closely associated with that language feature.
|
|
||
| @CONF[:RELOADABLE_REQUIRE] = false | ||
| @CONF[:__RELOADABLE_FILES__] = Set.new | ||
| @CONF[:__AUTOLOAD_FILES__] = Set.new |
There was a problem hiding this comment.
Can we not put these in CONF? It's already bloated with things unrelated configs. We shouldn't use this as a cache storage.
| unless Ruby::Box.method_defined?(:__irb_original_require__) | ||
| Ruby::Box.class_eval do | ||
| alias_method :__irb_original_require__, :require | ||
| alias_method :__irb_original_require_relative__, :require_relative |
There was a problem hiding this comment.
Can we avoid this old alias_method_chain style?
Summary
Add reload command to IRB that reloads files loaded via
require,require_relative, orautoloadduring an IRB session.Motivation
When developing gems and debugging/testing with IRB, it's tedious to restart IRB every time you modify a file. This feature allows you to reload modified files without restarting the session.
Implementation
Uses Ruby::Box's sandboxed
$LOADED_FEATURESto detect which files are loaded by require. The basic flow is:requireis called from the IRB prompt, execute it inside a newRuby::Box$LOADED_FEATURESbefore and after to detect newly loaded filesload(native extensions userequire)Usage
Prerequisites
RUBY_BOX=1environment variableIRB.conf[:RELOADABLE_REQUIRE] = truein your .irbrcExample
Limitations
Ruby::Box#requiredirectly are not trackedRuby::Box) is not supported