Class: Gem::Commands::DocCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
VersionOption, GemToolbox::CommonOptions
Defined in:
lib/rubygems/commands/doc_command.rb

Overview

DocCommand will open a gem’s rdoc This command is the same as the open_gem ReadCommand

Instance Method Summary collapse

Methods included from GemToolbox::CommonOptions

#add_command_option, #add_exact_match_option, #add_latest_version_option, #get_spec, #show

Constructor Details

#initializeDocCommand

Returns a new instance of DocCommand.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubygems/commands/doc_command.rb', line 10

def initialize
  super 'doc', "Read the gem's documentation", 
    :command => nil, 
    :version=>  Gem::Requirement.default,
    :latest=>   false
  
  add_command_option "Application to read rdoc with"
  add_latest_version_option
  add_version_option
  add_exact_match_option
end

Instance Method Details

#argumentsObject

:nodoc:



22
23
24
# File 'lib/rubygems/commands/doc_command.rb', line 22

def arguments # :nodoc:
  "GEMNAME       gem to read"
end

#executeObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubygems/commands/doc_command.rb', line 26

def execute
  name = get_one_gem_name
  spec = get_spec(name){|s| s.has_rdoc? }
  if spec && path = get_path(spec)
    if File.exists? path
      read_gem path
    elsif ask_yes_no "The rdoc seems to be missing, would you like to generate one?", true
      generate_rdoc spec
      read_gem path
    end
  end
end

#generate_rdoc(spec) ⇒ Object



43
44
45
# File 'lib/rubygems/commands/doc_command.rb', line 43

def generate_rdoc(spec)
  Gem::DocManager.new(spec).generate_rdoc
end

#get_path(spec) ⇒ Object



39
40
41
# File 'lib/rubygems/commands/doc_command.rb', line 39

def get_path(spec)
  File.join(spec.installation_path, "doc", spec.full_name, 'rdoc','index.html')
end

#read_gem(path) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rubygems/commands/doc_command.rb', line 47

def read_gem(path)
  if options[:command]
    command_parts = Shellwords.shellwords(options[:command])
    command_parts << path
    success = system(*command_parts)
    if !success 
      raise Gem::CommandLineError, "Could not run '#{options[:command]} #{path}', exit code: #{$?.exitstatus}"
    end
  else
    Launchy::Browser.run("file://"+path)
  end
end