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

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

View file

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

View file

@ -22,12 +22,16 @@ class Pry
@line = target.eval('__LINE__') @line = target.eval('__LINE__')
end end
def options(opt)
opt.on :q, :quiet, "Don't display anything in case of an error"
end
def code def code
if show_method? @code ||= if show_method?
Pry::Code.from_method(@method) Pry::Code.from_method(@method)
else else
Pry::Code.from_file(@file).around(@line, 5) Pry::Code.from_file(@file).around(@line, 5)
end end
end end
def location def location
@ -35,6 +39,13 @@ class Pry
end end
def process 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) set_file_and_dir_locals(@file)
output.puts "\n#{text.bold('From:')} #{location}:\n\n" output.puts "\n#{text.bold('From:')} #{location}:\n\n"
@ -44,6 +55,10 @@ class Pry
private private
def internal_binding?
@method && ['__binding__', '__binding_impl__'].include?(@method.name)
end
def show_method? def show_method?
args.empty? && @method && @method.source? && @method.source_range.count < 20 && 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 # 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) @method.source_file == @file && @method.source_range.include?(@line)
end end
def invalid_file?(file) def code?
file != Pry.eval_path && !!code
(file =~ /(\(.*\))|<.*>/ || file == "" || file == "-e") rescue MethodSource::SourceNotFoundError
false
end end
end end

View file

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