Fix whereami inside __binding_impl__

This commit is contained in:
Conrad Irwin 2012-06-10 23:37:47 -07:00
parent 4af01cb3a5
commit 6281d3c788
4 changed files with 27 additions and 14 deletions

View File

@ -13,10 +13,7 @@ class Pry
# ensure we're actually in a method
file = target.eval('__FILE__')
# /unknown/ for rbx
if file !~ /(\(.*\))|<.*>/ && file !~ /__unknown__/ && file != "" && file != "-e" || file == Pry.eval_path
_pry_.run_command("whereami", "", target)
end
_pry_.run_command("whereami --quiet", "", target)
end
# The default print

View File

@ -43,7 +43,7 @@ class Pry
f = File.open(fn, 'r')
code_type = type_from_filename(fn)
else
raise CommandError, "Cannot open #{fn.inspect} for reading."
raise MethodSource::SourceNotFoundError, "Cannot open #{fn.inspect} for reading."
end
end
new(f, 1, code_type || :ruby)

View File

@ -22,12 +22,16 @@ class Pry
@line = target.eval('__LINE__')
end
def options(opt)
opt.on :q, :quiet, "Don't display anything in case of an error"
end
def code
if show_method?
Pry::Code.from_method(@method)
else
Pry::Code.from_file(@file).around(@line, 5)
end
@code ||= if show_method?
Pry::Code.from_method(@method)
else
Pry::Code.from_file(@file).around(@line, 5)
end
end
def location
@ -35,6 +39,13 @@ class Pry
end
def process
if opts.quiet? && (internal_binding? || !code?)
return
elsif internal_binding?
output.puts "Could not find local context, did you use `binding.pry`?"
return
end
set_file_and_dir_locals(@file)
output.puts "\n#{text.bold('From:')} #{location}:\n\n"
@ -44,6 +55,10 @@ class Pry
private
def internal_binding?
@method && ['__binding__', '__binding_impl__'].include?(@method.name)
end
def show_method?
args.empty? && @method && @method.source? && @method.source_range.count < 20 &&
# These checks are needed in case of an eval with a binding and file/line
@ -51,9 +66,10 @@ class Pry
@method.source_file == @file && @method.source_range.include?(@line)
end
def invalid_file?(file)
file != Pry.eval_path &&
(file =~ /(\(.*\))|<.*>/ || file == "" || file == "-e")
def code?
!!code
rescue MethodSource::SourceNotFoundError
false
end
end

View File

@ -26,7 +26,7 @@ describe Pry::Code do
should 'raise an error if the file doesn\'t exist' do
proc do
Pry::Code.from_file('/knalkjsdnalsd/alkjdlkq')
end.should.raise(Pry::CommandError)
end.should.raise(MethodSource::SourceNotFoundError)
end
end