mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
define .source, .doc, etc on Pry::ClassCommand
This is so that Pry::CodeObject can return Pry::ClassCommand objects directly, this is impt as we want slightly different behaviour than just Pry::WrappedModule(command_class), notably .doc should return command help rather than comments above the command's class definition.
This commit is contained in:
parent
6f7e483884
commit
c1ae63446f
2 changed files with 27 additions and 1 deletions
|
@ -70,7 +70,9 @@ class Pry
|
|||
if str !~ /\S#\S/ && target.eval("defined? #{str} ") =~ /variable|constant/
|
||||
obj = target.eval(str)
|
||||
|
||||
if obj.respond_to?(:source_location)
|
||||
# restrict to only objects we KNOW for sure support the full API
|
||||
# Do NOT support just any object that responds to source_location
|
||||
if [::Proc, ::Method, ::UnboundMethod].any? { |o| obj.is_a?(o) }
|
||||
Pry::Method(obj)
|
||||
elsif !obj.is_a?(Module)
|
||||
Pry::WrappedModule(obj.class)
|
||||
|
|
|
@ -506,6 +506,30 @@ class Pry
|
|||
# gems your command needs to run, or to set up state.
|
||||
class ClassCommand < Command
|
||||
|
||||
class << self
|
||||
def source
|
||||
Pry::WrappedModule(self).source
|
||||
end
|
||||
|
||||
def doc
|
||||
new.help
|
||||
end
|
||||
|
||||
def source_location
|
||||
Pry::WrappedModule(self).source_location
|
||||
end
|
||||
|
||||
def source_file
|
||||
Pry::WrappedModule(self).source_file
|
||||
end
|
||||
alias_method :file, :source_file
|
||||
|
||||
def source_line
|
||||
Pry::WrappedModule(self).source_line
|
||||
end
|
||||
alias_method :line, :source_line
|
||||
end
|
||||
|
||||
# The class that couples together subcommands and top-level options (that
|
||||
# are known as "default" options). The explicitly defined instance methods
|
||||
# of this class provide the coupling with default options of a
|
||||
|
|
Loading…
Reference in a new issue