Sha256: d970a68536d839581ec6645fb0305bcaad2a070e45d70bc2563e553a83d3cfb4

Contents?: true

Size: 1.59 KB

Versions: 15

Compression:

Stored size: 1.59 KB

Contents

class Pry
  class Command::Ri < Pry::ClassCommand
    match 'ri'
    group 'Introspection'
    description 'View ri documentation.'

    banner <<-'BANNER'
      Usage: ri [spec]

      View ri documentation. Relies on the "rdoc" gem being installed.
      See also "show-doc" command.

      ri Array#each
    BANNER

    def process(spec)
      unless spec
        return output.puts "Please provide a class, module, or method name (e.g: ri Array#push)"
      end

      # 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 initialize(pager, opts)
            @pager = pager
            super opts
          end

          def page
            paging_text = StringIO.new
            yield paging_text
            @pager.page(paging_text.string)
          end

          def formatter(_io)
            if @formatter_klass
              @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 _pry_.pager, 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

  Pry::Commands.add_command(Pry::Command::Ri)
end

Version data entries

15 entries across 15 versions & 7 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/commands/ri.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/commands/ri.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/pry-0.12.2/lib/pry/commands/ri.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/commands/ri.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/commands/ri.rb
chess_engine-0.0.2 vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ri.rb
chess_engine-0.0.1 vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ri.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/commands/ri.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/commands/ri.rb
pry-0.12.2-java lib/pry/commands/ri.rb
pry-0.12.2 lib/pry/commands/ri.rb
pry-0.12.1 lib/pry/commands/ri.rb
pry-0.12.1-java lib/pry/commands/ri.rb
pry-0.12.0 lib/pry/commands/ri.rb
pry-0.12.0-java lib/pry/commands/ri.rb