Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added more rbx helpers (command_helpers.rb) and added limited support…

… for cat --ex on rbx
  • Loading branch information...
commit b3576244db423c5dc47331e6c98b47bd62174509 1 parent 84b0601
John Mair banister authored
1  CHANGELOG
View
@@ -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)
7 lib/pry/default_commands/introspection.rb
View
@@ -133,7 +133,12 @@ module DefaultCommands
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
8 lib/pry/default_commands/shell.rb
View
@@ -55,7 +55,11 @@ module DefaultCommands
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 @@ module DefaultCommands
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
7 lib/pry/helpers/base_helpers.rb
View
@@ -89,7 +89,12 @@ def page_size
# 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.
42 lib/pry/helpers/command_helpers.rb
View
@@ -40,11 +40,14 @@ def check_for_dynamically_defined_method(meth)
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 @@ def rbx_core_code_or_doc_for(meth, code_or_doc)
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 @@ def rbx_core_path_line_for(meth)
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]
10 test/helper.rb
View
@@ -25,6 +25,16 @@ def reset_defaults
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)
Please sign in to comment.
Something went wrong with that request. Please try again.