added more rbx helpers (command_helpers.rb) and added limited support for cat --ex on rbx
This commit is contained in:
parent
84b0601f4a
commit
b3576244db
|
@ -19,6 +19,7 @@
|
|||
* can no longer interpolate command name itself e.g #{x}-#{y} where x = "show" and y = "doc"
|
||||
* ^C no longer captured
|
||||
* got rid of Pry.active_instance, Pry.last_exception and friends.
|
||||
* also special locals now shared among bindings in a pry instance (i.e _ex_ (and friends) re-injected into new binding entered with 'cd')
|
||||
|
||||
*/7/2011 version 0.9.3
|
||||
* cat --ex (cats 5 lines above and below line in file where exception was raised)
|
||||
|
|
|
@ -133,7 +133,12 @@ class Pry
|
|||
if opts.ex?
|
||||
next output.puts "No Exception found." if _pry_.last_exception.nil?
|
||||
|
||||
file_name = _pry_.last_exception.file
|
||||
if is_core_rbx_path?(_pry_.last_exception.file)
|
||||
file_name = rbx_convert_path_to_full(_pry_.last_exception.file)
|
||||
else
|
||||
file_name = _pry_.last_exception.file
|
||||
end
|
||||
|
||||
line = _pry_.last_exception.line
|
||||
next output.puts "Exception has no associated file." if file_name.nil?
|
||||
next output.puts "Cannot edit exceptions raised in REPL." if Pry.eval_path == file_name
|
||||
|
|
|
@ -55,7 +55,11 @@ class Pry
|
|||
start_line = (ex.line - 1) - window_size
|
||||
start_line = start_line < 0 ? 0 : start_line
|
||||
end_line = (ex.line - 1) + window_size
|
||||
file_name = ex.file
|
||||
if is_core_rbx_path?(ex.file)
|
||||
file_name = rbx_convert_path_to_full(ex.file)
|
||||
else
|
||||
file_name = ex.file
|
||||
end
|
||||
end
|
||||
|
||||
opt.on :l, "line-numbers", "Show line numbers."
|
||||
|
@ -101,7 +105,7 @@ class Pry
|
|||
end.join
|
||||
|
||||
# header for exceptions
|
||||
output.puts "\n#{Pry::Helpers::Text.bold('Exception:')}: #{_pry_.last_exception.class}: #{_pry_.last_exception.message}"
|
||||
output.puts "\n#{Pry::Helpers::Text.bold('Exception:')} #{_pry_.last_exception.class}: #{_pry_.last_exception.message}\n--"
|
||||
output.puts "#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{_pry_.last_exception.line}\n\n"
|
||||
end
|
||||
|
||||
|
|
|
@ -89,7 +89,12 @@ class Pry
|
|||
|
||||
# are we on Jruby platform?
|
||||
def jruby?
|
||||
Object.const_defined?(:RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
|
||||
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
|
||||
end
|
||||
|
||||
# are we on rbx platform?
|
||||
def rbx?
|
||||
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
||||
end
|
||||
|
||||
# a simple pager for systems without `less`. A la windows.
|
||||
|
|
|
@ -40,11 +40,14 @@ class Pry
|
|||
end
|
||||
|
||||
########### RBX HELPERS #############
|
||||
def is_core_rbx_path?(path)
|
||||
rbx? &&
|
||||
path.start_with?("kernel")
|
||||
end
|
||||
|
||||
def rbx_core?(meth)
|
||||
defined?(RUBY_ENGINE) &&
|
||||
RUBY_ENGINE =~ /rbx/ &&
|
||||
meth.source_location &&
|
||||
meth.source_location.first.start_with?("kernel")
|
||||
is_core_rbx_path?(meth.source_location.first)
|
||||
end
|
||||
|
||||
def rvm_ruby?(path)
|
||||
|
@ -70,6 +73,28 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
def rbx_convert_path_to_full(path)
|
||||
if rvm_ruby?(Rubinius::BIN_PATH)
|
||||
rbx_rvm_convert_path_to_full(path)
|
||||
else
|
||||
rbx_std_convert_path_to_full(path)
|
||||
end
|
||||
end
|
||||
|
||||
def rbx_rvm_convert_path_to_full(path)
|
||||
ruby_name = File.dirname(Rubinius::BIN_PATH).split("/").last
|
||||
source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name)
|
||||
file_name = File.join(source_path, path)
|
||||
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
||||
file_name
|
||||
end
|
||||
|
||||
def rbx_std_convert_path_to_full(path)
|
||||
file_name = File.join(Rubinius::BIN_PATH, "..", path)
|
||||
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
||||
file_name
|
||||
end
|
||||
|
||||
def rbx_core_path_line_for(meth)
|
||||
if rvm_ruby?(Rubinius::BIN_PATH)
|
||||
rvm_rbx_core_path_line_for(meth)
|
||||
|
@ -79,21 +104,14 @@ class Pry
|
|||
end
|
||||
|
||||
def std_rbx_core_path_line_for(meth)
|
||||
file_name = File.join(Rubinius::BIN_PATH, "..", meth.source_location.first)
|
||||
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
||||
|
||||
file_name = rbx_std_convert_path_to_full(meth.source_location.first)
|
||||
start_line = meth.source_location.last
|
||||
|
||||
[file_name, start_line]
|
||||
end
|
||||
|
||||
def rvm_rbx_core_path_line_for(meth)
|
||||
ruby_name = File.dirname(Rubinius::BIN_PATH).split("/").last
|
||||
source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name)
|
||||
|
||||
file_name = File.join(source_path, meth.source_location.first)
|
||||
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
||||
|
||||
file_name = rbx_rvm_convert_path_to_full(meth.source_location.first)
|
||||
start_line = meth.source_location.last
|
||||
|
||||
[file_name, start_line]
|
||||
|
|
|
@ -25,6 +25,16 @@ class << Pry
|
|||
end
|
||||
end
|
||||
|
||||
# are we on Jruby platform?
|
||||
def jruby?
|
||||
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
|
||||
end
|
||||
|
||||
# are we on rbx platform?
|
||||
def rbx?
|
||||
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
||||
end
|
||||
|
||||
Pry.reset_defaults
|
||||
|
||||
# this is to test exception code (cat --ex)
|
||||
|
|
Loading…
Reference in New Issue