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:
parent
7b9915b190
commit
96cc93a75b
3 changed files with 17 additions and 6 deletions
|
@ -146,8 +146,8 @@ class Pry
|
|||
|
||||
# CommandErrors are caught by the REPL loop and displayed to the user. They
|
||||
# indicate an exceptional condition that's fatal to the current command.
|
||||
class CommandError < StandardError
|
||||
end
|
||||
class CommandError < StandardError; end
|
||||
class NonMethodContextError < CommandError; end
|
||||
end
|
||||
|
||||
require "method_source"
|
||||
|
|
|
@ -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."
|
||||
end
|
||||
|
||||
@method = method_object rescue nil
|
||||
begin
|
||||
@method = method_object
|
||||
rescue NonMethodContextError => err
|
||||
end
|
||||
|
||||
if opts.present?(:patch) || (@method && @method.dynamically_defined?)
|
||||
if err
|
||||
raise err # can't patch a non-method
|
||||
end
|
||||
|
||||
process_patch
|
||||
else
|
||||
if err && !File.exist?(target.eval('__FILE__'))
|
||||
raise err # can't edit a non-file
|
||||
end
|
||||
|
||||
process_file
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ class Pry
|
|||
if name && !meth
|
||||
command_error("The method '#{name}' could not be found.", omit_help)
|
||||
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
|
||||
|
||||
(opts[:super] || 0).times do
|
||||
|
@ -44,9 +44,9 @@ class Pry
|
|||
meth
|
||||
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
|
||||
raise CommandError, message
|
||||
raise klass, message
|
||||
end
|
||||
|
||||
def make_header(meth, content=meth.source)
|
||||
|
|
Loading…
Reference in a new issue