Sha256: 9d7a5d922f59d6235fc4e9aefa7be7d4f80efb4281e1b09d10b2d6eb51d08121

Contents?: true

Size: 1.8 KB

Versions: 6790

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require 'stringio'

class Pry
  class Command
    class 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_instance.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
end

Version data entries

6,790 entries across 6,786 versions & 31 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/pry-0.13.1/lib/pry/commands/ri.rb
cybrid_api_bank_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_organization_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_id_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_bank_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_id_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_organization_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
ory-client-1.16.1 vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
ory-client-1.16.0 vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/commands/ri.rb
cybrid_api_bank_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ri.rb