Class: RDoc::CodeObject

Inherits:
Object
  • Object
show all
Includes:
Generator::Markup, Text
Defined in:
lib/rdoc/code_object.rb,
lib/rdoc/generator/markup.rb

Overview

Base class for the RDoc code tree.

We contain the common stuff for contexts (which are containers) and other elements (methods, attributes and so on)

Here’s the tree of the CodeObject subclasses:

  • RDoc::Context

    • RDoc::TopLevel

    • RDoc::ClassModule

      • RDoc::AnonClass (never used so far)

      • RDoc::NormalClass

      • RDoc::NormalModule

      • RDoc::SingleClass

  • RDoc::MethodAttr

    • RDoc::Attr

    • RDoc::AnyMethod

      • RDoc::GhostMethod

      • RDoc::MetaMethod

  • RDoc::Alias

  • RDoc::Constant

  • RDoc::Mixin

    • RDoc::Require

    • RDoc::Include

Direct Known Subclasses

Alias, Constant, Context, MethodAttr, Mixin, Require

Constant Summary

Constants included from Text

Text::MARKUP_FORMAT, Text::SPACE_SEPARATED_LETTER_CLASS, Text::TO_HTML_CHARACTERS

Instance Attribute Summary collapse

Attributes included from Text

#language

Instance Method Summary collapse

Methods included from Generator::Markup

#aref_to, #as_href, #cvs_url, #description, #formatter

Methods included from Text

encode_fallback, #expand_tabs, #flush_left, #markup, #normalize_comment, #parse, #snippet, #strip_hashes, #strip_newlines, #strip_stars, #to_html, #wrap

Constructor Details

#initializeCodeObject

Creates a new CodeObject that will document itself and its children



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/rdoc/code_object.rb', line 107

def initialize
  @metadata         = {}
  @comment          = ''
  @parent           = nil
  @parent_name      = nil # for loading
  @parent_class     = nil # for loading
  @section          = nil
  @section_title    = nil # for loading
  @file             = nil
  @full_name        = nil
  @store            = nil
  @track_visibility = true
  @mixin_from       = nil

  initialize_visibility
end

Instance Attribute Details

#commentObject

Our comment



35
36
37
# File 'lib/rdoc/code_object.rb', line 35

def comment
  @comment
end

#document_childrenObject

Do we document our children?



40
41
42
# File 'lib/rdoc/code_object.rb', line 40

def document_children
  @document_children
end

#document_selfObject

Do we document ourselves?



45
46
47
# File 'lib/rdoc/code_object.rb', line 45

def document_self
  @document_self
end

#done_documentingObject

Are we done documenting (ie, did we come across a :enddoc:)?



50
51
52
# File 'lib/rdoc/code_object.rb', line 50

def done_documenting
  @done_documenting
end

#fileObject (readonly)

Which file this code object was defined in



55
56
57
# File 'lib/rdoc/code_object.rb', line 55

def file
  @file
end

#force_documentationObject

Force documentation of this CodeObject



60
61
62
# File 'lib/rdoc/code_object.rb', line 60

def force_documentation
  @force_documentation
end

#lineObject

Line in #file where this CodeObject was defined



65
66
67
# File 'lib/rdoc/code_object.rb', line 65

def line
  @line
end

#metadataObject (readonly)

Hash of arbitrary metadata for this CodeObject



70
71
72
# File 'lib/rdoc/code_object.rb', line 70

def 
  @metadata
end

#mixin_fromObject

When mixed-in to a class, this points to the Context in which it was originally defined.



102
103
104
# File 'lib/rdoc/code_object.rb', line 102

def mixin_from
  @mixin_from
end

#parentObject

Our parent CodeObject. The parent may be missing for classes loaded from legacy RI data stores.



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/rdoc/code_object.rb', line 315

def parent
  return @parent if @parent
  return nil unless @parent_name

  if @parent_class == RDoc::TopLevel then
    @parent = @store.add_file @parent_name
  else
    @parent = @store.find_class_or_module @parent_name

    return @parent if @parent

    begin
      @parent = @store.load_class @parent_name
    rescue RDoc::Store::MissingFileError
      nil
    end
  end
end

#received_nodocObject (readonly)

Did we ever receive a :nodoc: directive?



80
81
82
# File 'lib/rdoc/code_object.rb', line 80

def received_nodoc
  @received_nodoc
end

#sectionObject

The section this CodeObject is in. Sections allow grouping of constants, attributes and methods inside a class or module.



361
362
363
364
365
# File 'lib/rdoc/code_object.rb', line 361

def section
  return @section if @section

  @section = parent.add_section @section_title if parent
end

#storeObject

The RDoc::Store for this object.



90
91
92
# File 'lib/rdoc/code_object.rb', line 90

def store
  @store
end

#viewerObject

We are the model of the code, but we know that at some point we will be worked on by viewers. By implementing the Viewable protocol, viewers can associated themselves with these objects.



97
98
99
# File 'lib/rdoc/code_object.rb', line 97

def viewer
  @viewer
end

Instance Method Details

#display?Boolean

Should this CodeObject be displayed in output?

A code object should be displayed if:

  • The item didn’t have a nodoc or wasn’t in a container that had nodoc

  • The item wasn’t ignored

  • The item has documentation and was not suppressed

Returns:

  • (Boolean)


169
170
171
172
# File 'lib/rdoc/code_object.rb', line 169

def display?
  @document_self and not @ignored and
    (documented? or not @suppressed)
end

#documented?Boolean

Does this object have a comment with content or is #received_nodoc true?

Returns:

  • (Boolean)


200
201
202
# File 'lib/rdoc/code_object.rb', line 200

def documented?
  @received_nodoc or !@comment.empty?
end

#each_parentObject

Yields each parent of this CodeObject. See also RDoc::ClassModule#each_ancestor



224
225
226
227
228
229
230
231
232
# File 'lib/rdoc/code_object.rb', line 224

def each_parent
  code_object = self

  while code_object = code_object.parent do
    yield code_object
  end

  self
end

#file_nameObject

File name where this CodeObject was found.

See also RDoc::Context#in_files



239
240
241
242
243
# File 'lib/rdoc/code_object.rb', line 239

def file_name
  return unless @file

  @file.absolute_name
end

#full_name=(full_name) ⇒ Object

Sets the full_name overriding any computed full name.

Set to nil to clear RDoc’s cached value



260
261
262
# File 'lib/rdoc/code_object.rb', line 260

def full_name= full_name
  @full_name = full_name
end

#ignoreObject

Use this to ignore a CodeObject and all its children until found again (#record_location is called). An ignored item will not be displayed in documentation.

See github issue #55

The ignored status is temporary in order to allow implementation details to be hidden. At the end of processing a file RDoc allows all classes and modules to add new documentation to previously created classes.

If a class was ignored (via stopdoc) then reopened later with additional documentation it should be displayed. If a class was ignored and never reopened it should not be displayed. The ignore flag allows this to occur.



280
281
282
283
284
285
286
# File 'lib/rdoc/code_object.rb', line 280

def ignore
  return unless @track_visibility

  @ignored = true

  stop_doc
end

#ignored?Boolean

Has this class been ignored?

See also #ignore

Returns:

  • (Boolean)


293
294
295
# File 'lib/rdoc/code_object.rb', line 293

def ignored?
  @ignored
end

#initialize_visibilityObject

Initializes state for visibility of this CodeObject and its children.



127
128
129
130
131
132
133
134
135
136
# File 'lib/rdoc/code_object.rb', line 127

def initialize_visibility # :nodoc:
  @document_children   = true
  @document_self       = true
  @done_documenting    = false
  @force_documentation = false
  @received_nodoc      = false
  @ignored             = false
  @suppressed          = false
  @track_visibility    = true
end

#optionsObject

The options instance from the store this CodeObject is attached to, or a default options instance if the CodeObject is not attached.

This is used by Text#snippet



303
304
305
306
307
308
309
# File 'lib/rdoc/code_object.rb', line 303

def options
  if @store and @store.rdoc then
    @store.rdoc.options
  else
    RDoc::Options.new
  end
end

#parent_file_nameObject

File name of our parent



337
338
339
# File 'lib/rdoc/code_object.rb', line 337

def parent_file_name
  @parent ? @parent.base_name : '(unknown)'
end

#parent_nameObject

Name of our parent



344
345
346
# File 'lib/rdoc/code_object.rb', line 344

def parent_name
  @parent ? @parent.full_name : '(unknown)'
end

#record_location(top_level) ⇒ Object

Records the RDoc::TopLevel (file) where this code object was defined



351
352
353
354
355
# File 'lib/rdoc/code_object.rb', line 351

def record_location top_level
  @ignored    = false
  @suppressed = false
  @file       = top_level
end

#start_docObject

Enable capture of documentation unless documentation has been turned off by :enddoc:



371
372
373
374
375
376
377
378
# File 'lib/rdoc/code_object.rb', line 371

def start_doc
  return if @done_documenting

  @document_self = true
  @document_children = true
  @ignored    = false
  @suppressed = false
end

#stop_docObject

Disable capture of documentation



383
384
385
386
387
388
# File 'lib/rdoc/code_object.rb', line 383

def stop_doc
  return unless @track_visibility

  @document_self = false
  @document_children = false
end

#suppressObject

Use this to suppress a CodeObject and all its children until the next file it is seen in or documentation is discovered. A suppressed item with documentation will be displayed while an ignored item with documentation may not be displayed.



410
411
412
413
414
415
416
# File 'lib/rdoc/code_object.rb', line 410

def suppress
  return unless @track_visibility

  @suppressed = true

  stop_doc
end

#suppressed?Boolean

Has this class been suppressed?

See also #suppress

Returns:

  • (Boolean)


423
424
425
# File 'lib/rdoc/code_object.rb', line 423

def suppressed?
  @suppressed
end