Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some refactoring on show-source

  • Loading branch information...
commit be98279f7b990fbb4d666fd2195a1926a10449fb 1 parent cfc5890
@redgetan redgetan authored
View
1  lib/pry.rb
@@ -145,6 +145,7 @@ def self.===(exception)
# indicate an exceptional condition that's fatal to the current command.
class CommandError < StandardError; end
class NonMethodContextError < CommandError; end
+ class NonMethodError < CommandError; end
# indicates obsolete API
class ObsoleteError < StandardError; end
View
38 lib/pry/default_commands/introspection.rb
@@ -7,39 +7,43 @@ module DefaultCommands
module ModuleIntrospectionHelpers
attr_accessor :module_object
- def module?(name)
- self.module_object = Pry::WrappedModule.from_str(name, target)
- end
-
+ # is our target binding in a method?
def method?
!!method_object
- rescue CommandError
+ rescue NonMethodError,NonMethodContextError
false
end
+ def module?(name)
+ self.module_object = get_module(name)
+ end
+
+ def get_module(name)
+ wrapped = Pry::WrappedModule.from_str(name, target)
+ if !wrapped
+ if args.empty? && internal_binding?(target)
+ wrapped = Pry::WrappedModule(get_module_from_internal_binding)
+ end
+ end
+ wrapped
+ end
+
+ def get_module_from_internal_binding
+ mod = target_self.is_a?(Module) ? target_self : target_self.class
+ end
+
def process(name)
if module?(name)
code_or_doc = process_module
elsif method?
code_or_doc = process_method
else
- code_or_doc = process_alternatives
+ command_error("method or module for '#{name}' could not be found or derived", false)
end
render_output(code_or_doc, opts)
end
- def process_alternatives
- if args.empty? && internal_binding?(target)
- mod = target_self.is_a?(Module) ? target_self : target_self.class
- self.module_object = Pry::WrappedModule(mod)
-
- process_module
- else
- process_method
- end
- end
-
def module_start_line(mod, candidate_rank=0)
if opts.present?(:'base-one')
1
View
4 lib/pry/helpers/command_helpers.rb
@@ -49,14 +49,14 @@ def get_method_or_raise(name, target, opts={}, omit_help=false)
meth = Pry::Method.from_str(name, target, opts)
if name && !meth
- command_error("The method '#{name}' could not be found.", omit_help)
+ command_error("The method '#{name}' could not be found.", omit_help, NonMethodError)
end
(opts[:super] || 0).times do
if meth.super
meth = meth.super
else
- command_error("'#{meth.name_with_owner}' has no super method.", omit_help)
+ command_error("'#{meth.name_with_owner}' has no super method.", omit_help, NonMethodError)
end
end
View
2  test/test_default_commands/test_show_source.rb
@@ -149,7 +149,7 @@ def o.foo(*bars)
it "should not raise an exception when a non-extant super method is requested" do
def @o.foo(*bars); end
- mock_pry(binding, "show-source --super @o.foo").should =~ /'self.foo' has no super method/
+ mock_pry(binding, "show-source --super @o.foo").should =~ /'@o.foo' could not be found/
end
# dynamically defined method source retrieval is only supported in
Please sign in to comment.
Something went wrong with that request. Please try again.