Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
renamed reload-method to reload-code and extended functionality
Should now be able to reload any valid code object, including: methods, modules, commands, procs, etc
- Loading branch information
Showing
2 changed files
with
35 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
class Pry | |||
class Command::ReloadCode < Pry::ClassCommand | |||
match 'reload-code' | |||
group 'Misc' | |||
description 'Reload the source file that contains the specified code object' | |||
|
|||
def process | |||
code_object = Pry::CodeObject.lookup(obj_name, target, _pry_) | |||
|
|||
check_for_reloadability(code_object) | |||
reload_code_object(code_object) | |||
end | |||
|
|||
private | |||
|
|||
def reload_code_object(code_object) | |||
load code_object.source_file | |||
output.puts "#{code_object} was reloaded!" | |||
end | |||
|
|||
def obj_name | |||
@obj_name ||= args.empty? ? nil : args.join(" ") | |||
end | |||
|
|||
def check_for_reloadability(code_object) | |||
if !code_object | |||
raise CommandError, "Cannot locate #{obj_name}!" | |||
elsif !File.exists?(code_object.source_file) | |||
raise CommandError, "Cannot reload #{code_object} as it has no associated file on disk. File found was: #{code_object.source_file}" | |||
end | |||
end | |||
end | |||
|
|||
Pry::Commands.add_command(Pry::Command::ReloadCode) | |||
end |
This file was deleted.
Oops, something went wrong.