2012-08-11 20:22:29 -04:00
|
|
|
class Pry
|
2012-12-25 16:35:17 -05:00
|
|
|
class Command::Ri < Pry::ClassCommand
|
|
|
|
match 'ri'
|
2012-08-11 21:26:59 -04:00
|
|
|
group 'Introspection'
|
2013-01-09 15:23:19 -05:00
|
|
|
description 'View ri documentation.'
|
2012-08-11 21:26:59 -04:00
|
|
|
|
2013-01-09 15:23:19 -05:00
|
|
|
banner <<-'BANNER'
|
2012-08-11 20:22:29 -04:00
|
|
|
Usage: ri [spec]
|
|
|
|
|
2013-01-09 15:23:19 -05:00
|
|
|
View ri documentation. Relies on the "rdoc" gem being installed.
|
|
|
|
See also "show-doc" command.
|
|
|
|
|
|
|
|
ri Array#each
|
2012-08-11 20:22:29 -04:00
|
|
|
BANNER
|
|
|
|
|
|
|
|
def process(spec)
|
|
|
|
# Lazily load RI
|
|
|
|
require 'rdoc/ri/driver'
|
|
|
|
|
|
|
|
unless defined? RDoc::RI::PryDriver
|
|
|
|
|
|
|
|
# Subclass RI so that it formats its output nicely, and uses `lesspipe`.
|
|
|
|
subclass = Class.new(RDoc::RI::Driver) # the hard way.
|
|
|
|
|
|
|
|
subclass.class_eval do
|
|
|
|
def page
|
2012-09-16 17:19:10 -04:00
|
|
|
paging_text = StringIO.new
|
|
|
|
yield paging_text
|
|
|
|
Pry::Pager.page(paging_text.string)
|
2012-08-11 20:22:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def formatter(io)
|
|
|
|
if @formatter_klass then
|
|
|
|
@formatter_klass.new
|
|
|
|
else
|
|
|
|
RDoc::Markup::ToAnsi.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RDoc::RI.const_set :PryDriver, subclass # hook it up!
|
|
|
|
end
|
|
|
|
|
|
|
|
# Spin-up an RI insance.
|
|
|
|
ri = RDoc::RI::PryDriver.new :use_stdout => true, :interactive => false
|
|
|
|
|
|
|
|
begin
|
|
|
|
ri.display_names [spec] # Get the documentation (finally!)
|
|
|
|
rescue RDoc::RI::Driver::NotFoundError => e
|
|
|
|
output.puts "error: '#{e.name}' not found"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-12-25 16:35:17 -05:00
|
|
|
|
|
|
|
Pry::Commands.add_command(Pry::Command::Ri)
|
2012-08-11 20:22:29 -04:00
|
|
|
end
|