Skip to content

Commit 5328a37

Browse files
committed
Move all progress printing to RDoc::Stats
1 parent 66cbb5d commit 5328a37

File tree

10 files changed

+211
-123
lines changed

10 files changed

+211
-123
lines changed

lib/rdoc/code_objects.rb

+16-10
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ def document_children=(val)
7171
# Do we _force_ documentation, even is we wouldn't normally show the entity
7272
attr_accessor :force_documentation
7373

74+
def parent_file_name
75+
@parent ? @parent.file_base_name : '(unknown)'
76+
end
77+
78+
def parent_name
79+
@parent ? @parent.name : '(unknown)'
80+
end
81+
7482
# Default callbacks to nothing, but this is overridden for classes
7583
# and modules
7684
def remove_classes_and_modules
@@ -272,7 +280,6 @@ def add_module(class_type, name)
272280
end
273281

274282
def add_method(a_method)
275-
puts "Adding #@visibility method #{a_method.name} to #@name" if $DEBUG_RDOC
276283
a_method.visibility = @visibility
277284
add_to(@method_list, a_method)
278285
end
@@ -283,7 +290,8 @@ def add_attribute(an_attribute)
283290

284291
def add_alias(an_alias)
285292
meth = find_instance_method_named(an_alias.old_name)
286-
if meth
293+
294+
if meth then
287295
new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
288296
new_meth.is_alias_for = meth
289297
new_meth.singleton = meth.singleton
@@ -294,6 +302,8 @@ def add_alias(an_alias)
294302
else
295303
add_to(@aliases, an_alias)
296304
end
305+
306+
an_alias
297307
end
298308

299309
def add_include(an_include)
@@ -321,7 +331,6 @@ def add_class_or_module(collection, class_type, name, superclass=nil)
321331
puts "Reusing class/module #{name}" if $DEBUG_RDOC
322332
else
323333
cls = class_type.new(name, superclass)
324-
puts "Adding class/module #{name} to #@name" if $DEBUG_RDOC
325334
# collection[name] = cls if @document_self && !@done_documenting
326335
collection[name] = cls if !@done_documenting
327336
cls.parent = self
@@ -569,8 +578,6 @@ def add_class_or_module(collection, class_type, name, superclass)
569578
all[name] = cls unless @done_documenting
570579
end
571580

572-
puts "Adding class/module #{name} to #{full_name}" if $DEBUG_RDOC
573-
574581
collection[name] = cls unless @done_documenting
575582

576583
cls.parent = self
@@ -806,7 +813,7 @@ def inspect
806813
alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
807814
"#<%s:0x%x %s%s%s (%s)%s>" % [
808815
self.class, object_id,
809-
@parent.name,
816+
parent_name,
810817
singleton ? '::' : '#',
811818
name,
812819
visibility,
@@ -928,7 +935,7 @@ def inspect
928935

929936
"#<%s:0x%x %s.%s :%s>" % [
930937
self.class, object_id,
931-
@parent.name, attr, @name,
938+
parent_name, attr, @name,
932939
]
933940
end
934941

@@ -955,7 +962,7 @@ def inspect
955962
self.class,
956963
object_id,
957964
@name,
958-
@parent.file_base_name,
965+
parent_file_name,
959966
]
960967
end
961968

@@ -979,8 +986,7 @@ def inspect
979986
"#<%s:0x%x %s.include %s>" % [
980987
self.class,
981988
object_id,
982-
@parent.name,
983-
@name,
989+
parent_name, @name,
984990
]
985991
end
986992

lib/rdoc/options.rb

+24-7
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ class RDoc::Options
107107

108108
attr_reader :promiscuous
109109

110-
##
111-
# Don't display progress as we process the files
112-
113-
attr_accessor :quiet
114-
115110
##
116111
# Array of directories to search for files to satisfy an :include:
117112

@@ -149,6 +144,11 @@ class RDoc::Options
149144

150145
attr_reader :title
151146

147+
##
148+
# Verbosity, zero means quiet
149+
150+
attr_accessor :verbosity
151+
152152
##
153153
# URL of web cvs frontend
154154

@@ -161,7 +161,6 @@ def initialize(generators = {}) # :nodoc:
161161
@main_page = nil
162162
@merge = false
163163
@exclude = []
164-
@quiet = false
165164
@generators = generators
166165
@generator_name = 'html'
167166
@generator = @generators[@generator_name]
@@ -180,6 +179,7 @@ def initialize(generators = {}) # :nodoc:
180179
@extra_accessor_flags = {}
181180
@promiscuous = false
182181
@force_update = false
182+
@verbosity = 1
183183

184184
@css = nil
185185
@webcvs = nil
@@ -424,9 +424,15 @@ def parse(argv)
424424

425425
opt.on("--quiet", "-q",
426426
"Don't show progress as we parse.") do |value|
427-
@quiet = value
427+
@verbosity = 0
428+
end
429+
430+
opt.on("--verbose", "-v",
431+
"Display extra progress as we parse.") do |value|
432+
@verbosity = 2
428433
end
429434

435+
430436
opt.separator nil
431437

432438
opt.on("--ri", "-r",
@@ -559,6 +565,17 @@ def title=(string)
559565
@title ||= string
560566
end
561567

568+
##
569+
# Don't display progress as we process the files
570+
571+
def quiet
572+
@verbosity.zero?
573+
end
574+
575+
def quiet=(bool)
576+
@verbosity = bool ? 0 : 1
577+
end
578+
562579
private
563580

564581
##

lib/rdoc/parser.rb

-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ class << self
4646
attr_reader :parsers
4747
end
4848

49-
attr_writer :progress
50-
5149
##
5250
# Alias an extension to another extension. After this call, files ending
5351
# "new_ext" will be parsed using the same parser as "old_ext"
@@ -103,7 +101,6 @@ def initialize(top_level, file_name, content, options, stats)
103101
@content = content
104102
@options = options
105103
@stats = stats
106-
@progress = $stderr unless options.quiet
107104
end
108105

109106
end

lib/rdoc/parser/c.rb

+9-20
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ class RDoc::Parser::C < RDoc::Parser
9595

9696
parse_files_matching(/\.(?:([CcHh])\1?|c([+xp])\2|y)\z/)
9797

98-
attr_writer :progress
99-
10098
@@enclosure_classes = {}
10199
@@known_bodies = {}
102100

@@ -115,11 +113,12 @@ def initialize(top_level, file_name, content, options, stats)
115113
def do_aliases
116114
@content.scan(%r{rb_define_alias\s*\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do
117115
|var_name, new_name, old_name|
118-
@stats.num_methods += 1
119116
class_name = @known_classes[var_name] || var_name
120117
class_obj = find_class(var_name, class_name)
121118

122-
class_obj.add_alias RDoc::Alias.new("", old_name, new_name, "")
119+
as = class_obj.add_alias RDoc::Alias.new("", old_name, new_name, "")
120+
121+
@stats.add_alias as
123122
end
124123
end
125124

@@ -306,7 +305,7 @@ def find_body(meth_name, meth_obj, body, quiet = false)
306305
meth_obj.comment = mangle_comment(comment) + meth_obj.comment
307306
when %r{^\s*\#\s*define\s+#{meth_name}\s+(\w+)}m
308307
unless find_body($1, meth_obj, body, true)
309-
warn "No definition for #{meth_name}" unless quiet
308+
warn "No definition for #{meth_name}" unless @options.quiet
310309
return false
311310
end
312311
else
@@ -318,7 +317,7 @@ def find_body(meth_name, meth_obj, body, quiet = false)
318317
find_modifiers(comment, meth_obj)
319318
meth_obj.comment = mangle_comment(comment)
320319
else
321-
warn "No definition for #{meth_name}" unless quiet
320+
warn "No definition for #{meth_name}" unless @options.quiet
322321
return false
323322
end
324323
end
@@ -460,8 +459,6 @@ def handle_attr(var_name, attr_name, reader, writer)
460459
end
461460

462461
def handle_class_module(var_name, class_mod, class_name, parent, in_module)
463-
progress(class_mod[0, 1])
464-
465462
parent_name = @known_classes[parent] || parent
466463

467464
if in_module
@@ -484,10 +481,10 @@ def handle_class_module(var_name, class_mod, class_name, parent, in_module)
484481

485482
if class_mod == "class" then
486483
cm = enclosure.add_class RDoc::NormalClass, class_name, parent_name
487-
@stats.num_classes += 1
484+
@stats.add_class cm
488485
else
489486
cm = enclosure.add_module RDoc::NormalModule, class_name
490-
@stats.num_modules += 1
487+
@stats.add_module cm
491488
end
492489

493490
cm.record_location(enclosure.toplevel)
@@ -561,9 +558,6 @@ def handle_ifdefs_in(body)
561558

562559
def handle_method(type, var_name, meth_name, meth_body, param_count,
563560
source_file = nil)
564-
progress(".")
565-
566-
@stats.num_methods += 1
567561
class_name = @known_classes[var_name]
568562

569563
return unless class_name
@@ -579,6 +573,8 @@ def handle_method(type, var_name, meth_name, meth_body, param_count,
579573
meth_obj.singleton =
580574
%w{singleton_method module_function}.include?(type)
581575

576+
@stats.add_method meth_obj
577+
582578
p_count = (Integer(param_count) rescue -1)
583579

584580
if p_count < 0
@@ -623,13 +619,6 @@ def mangle_comment(comment)
623619
comment
624620
end
625621

626-
def progress(char)
627-
unless @options.quiet
628-
@progress.print(char)
629-
@progress.flush
630-
end
631-
end
632-
633622
##
634623
# Removes lines that are commented out that might otherwise get picked up
635624
# when scanning for classes and methods

0 commit comments

Comments
 (0)