1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/commands/reload_code.rb
Kyrylo Silin 256f35422a Prettify command descriptions, switches and stuff
Wrap command descriptions to 80 characters. Convert some string options
to symbols (where possible). Align options in code. Remove dots in the
end of switch descriptions.

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
2013-01-09 22:23:19 +02:00

39 lines
1.1 KiB
Ruby

class Pry
class Command::ReloadCode < Pry::ClassCommand
match 'reload-code'
group 'Misc'
description 'Reload the source file that contains the specified code object.'
banner <<-'BANNER'
Reload the source file that contains the specified code object.
BANNER
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 "#{obj_name} was reloaded!"
end
def obj_name
@obj_name ||= args.empty? ? "self" : 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 #{obj_name} 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