Skip to content

Commit 43a7725

Browse files
committed
RDoc::RDoc#document now takes an RDoc::Options
1 parent b9fca6f commit 43a7725

File tree

3 files changed

+54
-31
lines changed

3 files changed

+54
-31
lines changed

History.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
=== 3.3.1
1+
=== 3.4
22

3+
* Minor enhancements
4+
* RDoc::RDoc#document may now be called with an RDoc::Options instance.
35
* Bug fixes
46
* Added skips to Encoding tests running on 1.8.
57
* Fixed warnings

lib/rdoc/options.rb

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class RDoc::Options
7171
attr_accessor :formatter
7272

7373
##
74-
# Description of the output generator (set with the <tt>-fmt</tt> option)
74+
# Description of the output generator (set with the <tt>--fmt</tt> option)
7575

7676
attr_accessor :generator
7777

@@ -246,6 +246,35 @@ def default_title=(string)
246246
@title ||= string
247247
end
248248

249+
##
250+
# Completes any unfinished option setup business such as filtering for
251+
# existent files, creating a regexp for #exclude and setting a default
252+
# #template.
253+
254+
def finish
255+
@op_dir ||= 'doc'
256+
257+
@rdoc_include << "." if @rdoc_include.empty?
258+
259+
if @exclude.empty? then
260+
@exclude = nil
261+
else
262+
@exclude = Regexp.new(@exclude.join("|"))
263+
end
264+
265+
check_files
266+
267+
# If no template was specified, use the default template for the output
268+
# formatter
269+
270+
unless @template then
271+
@template = @generator_name
272+
@template_dir = template_dir_for @template
273+
end
274+
275+
self
276+
end
277+
249278
##
250279
# Returns a properly-space list of generators and their descriptions.
251280

@@ -273,7 +302,7 @@ def generator_descriptions
273302
end
274303

275304
##
276-
# Parse command line options.
305+
# Parses command line options.
277306

278307
def parse(argv)
279308
ignore_invalid = true
@@ -677,26 +706,9 @@ def parse(argv)
677706
end
678707
end
679708

680-
@op_dir ||= 'doc'
681709
@files = argv.dup
682710

683-
@rdoc_include << "." if @rdoc_include.empty?
684-
685-
if @exclude.empty? then
686-
@exclude = nil
687-
else
688-
@exclude = Regexp.new(@exclude.join("|"))
689-
end
690-
691-
check_files
692-
693-
# If no template was specified, use the default template for the output
694-
# formatter
695-
696-
unless @template then
697-
@template = @generator_name
698-
@template_dir = template_dir_for @template
699-
end
711+
finish
700712
end
701713

702714
##

lib/rdoc/rdoc.rb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,27 @@ def remove_unparseable files
384384
##
385385
# Format up one or more files according to the given arguments.
386386
#
387-
# For simplicity, +argv+ is an array of strings, equivalent to the strings
388-
# that would be passed on the command line. (This isn't a coincidence, as
389-
# we _do_ pass in ARGV when running interactively). For a list of options,
390-
# see <tt>rdoc --help</tt>. By default, output will be stored in a directory
391-
# called +doc+ below the current directory, so make sure you're somewhere
392-
# writable before invoking.
393-
394-
def document(argv)
387+
# +options+ can be either an RDoc::Options instance or an array of strings
388+
# equivalent to the strings that would be passed on the command line like
389+
# <tt>%w[-q -o doc -t My\ Doc\ Title]</tt>.
390+
# #document will automatically call #finish on an RDoc::Options instance.
391+
#
392+
# For a list of options, see either RDoc::Options or <tt>rdoc --help</tt>.
393+
#
394+
# By default, output will be stored in a directory called "doc" below the
395+
# current directory, so make sure you're somewhere writable before invoking.
396+
397+
def document options
395398
RDoc::TopLevel.reset
396399
RDoc::Parser::C.reset
397400

398-
@options = RDoc::Options.new
399-
@options.parse argv
401+
if RDoc::Options === options then
402+
@options = options
403+
@options.finish
404+
else
405+
@options = RDoc::Options.new
406+
@options.parse options
407+
end
400408

401409
if @options.pipe then
402410
handle_pipe
@@ -478,6 +486,7 @@ def remove_siginfo_handler
478486
load extension
479487
rescue => e
480488
warn "error loading #{extension.inspect}: #{e.message} (#{e.class})"
489+
warn "\t#{e.backtrace.join "\n\t"}" if $DEBUG
481490
end
482491
end
483492
end

0 commit comments

Comments
 (0)