@@ -40,9 +40,6 @@ def parser(*args) default_parser.new(*args) end
40
40
41
41
self . default_parser = DocstringParser
42
42
43
- # @return [Array<Tags::RefTag>] the list of reference tags
44
- attr_reader :ref_tags
45
-
46
43
# @return [CodeObjects::Base] the object that owns the docstring.
47
44
attr_accessor :object
48
45
@@ -131,8 +128,7 @@ def to_s
131
128
# @param [String] content the raw comments to be parsed
132
129
def replace ( content , parse = true )
133
130
content = content . join ( "\n " ) if content . is_a? ( Array )
134
- @tags = [ ]
135
- @ref_tags = [ ]
131
+ @all_tags = [ ]
136
132
if parse
137
133
super ( parse_comments ( content ) )
138
134
else
@@ -153,7 +149,7 @@ def replace(content, parse = true)
153
149
def dup
154
150
resolve_reference
155
151
obj = super
156
- %w( all summary tags ref_tags ) . each do |name |
152
+ %w( all summary all_tags ) . each do |name |
157
153
val = instance_variable_defined? ( "@#{ name } " ) && instance_variable_get ( "@#{ name } " )
158
154
obj . instance_variable_set ( "@#{ name } " , val ? val . dup : nil )
159
155
end
@@ -244,9 +240,9 @@ def add_tag(*tags)
244
240
case tag
245
241
when Tags ::Tag
246
242
tag . object = object
247
- @tags << tag
248
- when Tags ::RefTag , Tags :: RefTagList
249
- @ref_tags << tag
243
+ @all_tags << tag
244
+ when Tags ::RefTagList
245
+ @all_tags << tag
250
246
else
251
247
raise ArgumentError , "expected Tag or RefTag, got #{ tag . class } (at index #{ i } )"
252
248
end
@@ -271,11 +267,17 @@ def tag(name)
271
267
# @param [#to_s] name the tag name to return data for, or nil for all tags
272
268
# @return [Array<Tags::Tag>] the list of tags by the specified tag name
273
269
def tags ( name = nil )
274
- list = stable_sort_by ( @tags + convert_ref_tags , &:tag_name )
270
+ list = @all_tags . map { |tag | convert_ref_tag ( tag ) } . flatten
271
+ list = stable_sort_by ( list , &:tag_name )
275
272
return list unless name
276
273
list . select { |tag | tag . tag_name . to_s == name . to_s }
277
274
end
278
275
276
+ # @return [Array<Tags::RefTag, Tags::RefTagList>] the list of reference tags
277
+ def ref_tags
278
+ @all_tags . select { |tag | tag . is_a? ( Tags ::RefTag ) || tag . is_a? ( Tags ::RefTagList ) }
279
+ end
280
+
279
281
# Returns true if at least one tag by the name +name+ was declared
280
282
#
281
283
# @param [String] name the tag name to search for
@@ -298,8 +300,7 @@ def delete_tags(name)
298
300
# @return [void]
299
301
# @since 0.7.0
300
302
def delete_tag_if ( &block )
301
- @tags . delete_if ( &block )
302
- @ref_tags . delete_if ( &block )
303
+ @all_tags . delete_if ( &block )
303
304
end
304
305
305
306
# Returns true if the docstring has no content that is visible to a template.
@@ -311,7 +312,7 @@ def blank?(only_visible_tags = true)
311
312
if only_visible_tags
312
313
empty? && !tags . any? { |tag | Tags ::Library . visible_tags . include? ( tag . tag_name . to_sym ) }
313
314
else
314
- empty? && @tags . empty? && @ref_tags . empty?
315
+ empty? && @all_tags . empty?
315
316
end
316
317
end
317
318
@@ -340,20 +341,27 @@ def resolve_reference
340
341
341
342
# Maps valid reference tags
342
343
#
343
- # @return [Array<Tags::RefTag>] the list of valid reference tags
344
- def convert_ref_tags
345
- list = @ref_tags . reject { |t | CodeObjects ::Proxy === t . owner }
346
-
344
+ # @param tag [Tags::Tag, Tags::RefTagList]
345
+ # @return [Array<Tags::Tag>] dereferenced tags
346
+ def convert_ref_tag ( tag )
347
347
@ref_tag_recurse_count ||= 0
348
348
@ref_tag_recurse_count += 1
349
349
if @ref_tag_recurse_count > 2
350
350
log . error "#{ @object . file } :#{ @object . line } : Detected circular reference tag in " \
351
351
"`#{ @object } ', ignoring all reference tags for this object " \
352
- "(#{ @ref_tags . map { | t | "@ #{ t . tag_name } " } . join ( ", " ) } )."
352
+ "(@ #{ tag . tag_name } )."
353
353
@ref_tags = [ ]
354
354
return @ref_tags
355
355
end
356
- list = list . map ( &:tags ) . flatten
356
+ if tag . is_a? ( Tags ::RefTagList )
357
+ if CodeObjects ::Proxy === tag . owner
358
+ list = [ ]
359
+ else
360
+ list = tag . tags
361
+ end
362
+ else
363
+ list = [ tag ]
364
+ end
357
365
@ref_tag_recurse_count -= 1
358
366
list
359
367
end
0 commit comments