Class: Shomen::CLI::RDocCommand

Inherits:
Abstract
  • Object
show all
Defined in:
lib/shomen/cli/rdoc.rb

Overview

RDoc command line interface.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#option_debug, #option_force, #option_format, #option_help, #option_source, #option_warn, #parse, #root?

Constructor Details

#initializeRDocCommand

New RDoc command line interface.



20
21
22
23
24
25
# File 'lib/shomen/cli/rdoc.rb', line 20

def initialize
  begin
    gem 'rdoc'
  rescue
  end
end

Class Method Details

.run(*argv) ⇒ Object



15
16
17
# File 'lib/shomen/cli/rdoc.rb', line 15

def self.run(*argv)
  new.run(argv)
end

Instance Method Details

#option_main(parser, options) ⇒ Object



111
112
113
114
115
# File 'lib/shomen/cli/rdoc.rb', line 111

def option_main(parser, options)
  parser.on('-m', '--main FILE') do |file|
    options[:main] = file
  end
end

#option_visibility(parser, options) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/shomen/cli/rdoc.rb', line 94

def option_visibility(parser, options)
  parser.on('--private', 'include public, protected and private methods') do
    options[:visibility] = :private
  end
  parser.on('--protected', 'include public and protected methods') do
    options[:visibility] = :protected
  end
end

#run(argv) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/shomen/cli/rdoc.rb', line 28

def run(argv)
  require 'shomen/rdoc'

  defaults = {}
  defaults[:format]  = :json
  defaults[:force]   = false
  defaults[:source]  = true

  options = parse(argv, :format, :force, :visibility, :main, :source, defaults)

  if !options[:force] && !root?
    $stderr.puts "Not a project directory. Use --force to override."
    exit -1
  end

  if argv.empty?
    if File.exist?('.document')
      files = File.read('.document').split("\n")
      files = files.reject{ |f| f.strip == '' or f.strip =~ /^\#/ }
      files = files.map{ |f| Dir[f] }.flatten
    else
      files = ['lib']
    end
  else
    files = argv
  end

  tmpdir     = File.join(Dir.tmpdir, 'shomen-rdoc')
  main       = options[:main] || Dir.glob('{README.*,README}').first
  visibility = options[:visibility].to_s

  # TODO: Any way to supress the cretion of the time stamp altogether?
  # Options#update_output_dir for instance?

  # TODO: Using the ::RDoc::Options doesn't seem to work.
  # It complains about a template being nil in `rdoc/options.rb:760`.

  #rdoc_options = ::RDoc::Options.new
  #rdoc_options.generator = 'shomen'
  #rdoc_options.main_page = Dir.glob('README*').first
  ##rdoc_options.template  = 'shomen'
  ##rdoc_options.template_dir = File.dirname(__FILE__)
  #rdoc_options.op_dir    = 'tmp/rdoc'  # '/dev/null'
  #rdoc_options.files     = files

  rdoc_options  = []
  rdoc_options += ['-q']
  #rdoc_options += ['-t', title]
  rdoc_options += ['-f', 'shomen']
  rdoc_options += ['-m', main] if main
  rdoc_options += ['-V', visibility]
  rdoc_options += ['-o', tmpdir]  # '/dev/null'
  rdoc_options += files

  rdoc = ::RDoc::RDoc.new
  rdoc.document(rdoc_options)

  case options[:format]
  when :yaml
    $stdout.puts(rdoc.generator.shomen.to_yaml)
  else
    $stdout.puts(JSON.generate(rdoc.generator.shomen))
  end
end