1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

reload-code (with no args) should reload 'current file'

This should fix #920.
Also added a guard for !code_object.source_file, this existed on 0.9.12
but for some reason was not on master.
This commit is contained in:
John Mair 2013-05-10 02:46:22 +02:00
parent 6ca5f60207
commit ed52bfdb74

View file

@ -15,25 +15,44 @@ class Pry
BANNER
def process
code_object = Pry::CodeObject.lookup(obj_name, _pry_)
check_for_reloadability(code_object)
reload_code_object(code_object)
if obj_name.empty?
# if no parameters were provided then try to reload the
# current file (i.e target.eval("__FILE__"))
reload_current_file
else
code_object = Pry::CodeObject.lookup(obj_name, _pry_)
reload_code_object(code_object)
end
end
private
def current_file
File.expand_path target.eval("__FILE__")
end
def reload_current_file
if !File.exists?(current_file)
raise CommandError, "Current file: #{current_file} cannot be found on disk!"
end
load current_file
output.puts "The current file: #{current_file} was reloaded!"
end
def reload_code_object(code_object)
check_for_reloadability(code_object)
load code_object.source_file
output.puts "#{obj_name} was reloaded!"
end
def obj_name
@obj_name ||= args.empty? ? "self" : args.join(" ")
@obj_name ||= args.join(" ")
end
def check_for_reloadability(code_object)
if !code_object
if !code_object || !code_object.source_file
raise CommandError, "Cannot locate #{obj_name}!"
elsif !File.exists?(code_object.source_file)
raise CommandError, "Cannot reload #{obj_name} as it has no associated file on disk. File found was: #{code_object.source_file}"