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

bug fixes for edit-method

This commit is contained in:
Ryan Fitzgerald 2012-01-15 23:45:08 -08:00
parent 7b9915b190
commit 96cc93a75b
3 changed files with 17 additions and 6 deletions

View file

@ -146,8 +146,8 @@ class Pry
# CommandErrors are caught by the REPL loop and displayed to the user. They # CommandErrors are caught by the REPL loop and displayed to the user. They
# indicate an exceptional condition that's fatal to the current command. # indicate an exceptional condition that's fatal to the current command.
class CommandError < StandardError class CommandError < StandardError; end
end class NonMethodContextError < CommandError; end
end end
require "method_source" require "method_source"

View file

@ -249,11 +249,22 @@ class Pry
raise CommandError, "No editor set!\nEnsure that #{text.bold("Pry.config.editor")} is set to your editor of choice." raise CommandError, "No editor set!\nEnsure that #{text.bold("Pry.config.editor")} is set to your editor of choice."
end end
@method = method_object rescue nil begin
@method = method_object
rescue NonMethodContextError => err
end
if opts.present?(:patch) || (@method && @method.dynamically_defined?) if opts.present?(:patch) || (@method && @method.dynamically_defined?)
if err
raise err # can't patch a non-method
end
process_patch process_patch
else else
if err && !File.exist?(target.eval('__FILE__'))
raise err # can't edit a non-file
end
process_file process_file
end end
end end

View file

@ -29,7 +29,7 @@ class Pry
if name && !meth if name && !meth
command_error("The method '#{name}' could not be found.", omit_help) command_error("The method '#{name}' could not be found.", omit_help)
elsif !meth elsif !meth
command_error("No method name given, and context is not a method.", omit_help) command_error("No method name given, and context is not a method.", omit_help, NonMethodContextError)
end end
(opts[:super] || 0).times do (opts[:super] || 0).times do
@ -44,9 +44,9 @@ class Pry
meth meth
end end
def command_error(message, omit_help) def command_error(message, omit_help, klass=CommandError)
message += " Type `#{command_name} --help` for help." unless omit_help message += " Type `#{command_name} --help` for help." unless omit_help
raise CommandError, message raise klass, message
end end
def make_header(meth, content=meth.source) def make_header(meth, content=meth.source)