Class: RDoc::TopLevel
- Inherits:
-
Context
- Object
- CodeObject
- Context
- RDoc::TopLevel
- Defined in:
- lib/rdoc/code_objects.rb
Overview
A TopLevel context is a source file
Constant Summary collapse
- @@all_classes =
{}
- @@all_modules =
{}
Instance Attribute Summary collapse
-
#diagram ⇒ Object
Returns the value of attribute diagram.
-
#file_absolute_name ⇒ Object
Returns the value of attribute file_absolute_name.
-
#file_relative_name ⇒ Object
Returns the value of attribute file_relative_name.
-
#file_stat ⇒ Object
Returns the value of attribute file_stat.
Attributes inherited from Context
#aliases, #attributes, #constants, #in_files, #includes, #method_list, #name, #requires, #sections, #visibility
Attributes inherited from CodeObject
#comment, #document_children, #document_self, #done_documenting, #force_documentation, #parent, #section, #viewer
Class Method Summary collapse
Instance Method Summary collapse
-
#add_class_or_module(collection, class_type, name, superclass) ⇒ Object
Adding a class or module to a TopLevel is special, as we only want one copy of a particular top-level class.
- #find_class_or_module_named(symbol) ⇒ Object
- #find_local_symbol(symbol) ⇒ Object
-
#find_module_named(name) ⇒ Object
Find a named module.
- #full_name ⇒ Object
-
#initialize(file_name) ⇒ TopLevel
constructor
A new instance of TopLevel.
Methods inherited from Context
#<=>, #add_alias, #add_attribute, #add_class, #add_constant, #add_include, #add_method, #add_module, #add_require, #add_to, #classes, #defined_in?, #each_attribute, #each_classmodule, #each_constant, #each_method, #find_enclosing_module_named, #find_symbol, #initialize_classes_and_modules, #initialize_methods_etc, #modules, #ongoing_visibility=, #record_location, #remove_classes_and_modules, #remove_methods_etc, #set_current_section, #set_visibility_for, #toplevel
Methods inherited from CodeObject
attr_overridable, #remove_classes_and_modules, #remove_methods_etc, #start_doc, #stop_doc
Constructor Details
#initialize(file_name) ⇒ TopLevel
Returns a new instance of TopLevel.
477 478 479 480 481 482 483 484 |
# File 'lib/rdoc/code_objects.rb', line 477 def initialize(file_name) super() @name = "TopLevel" @file_relative_name = file_name @file_absolute_name = file_name @file_stat = File.stat(file_name) @diagram = nil end |
Instance Attribute Details
#diagram ⇒ Object
Returns the value of attribute diagram
467 468 469 |
# File 'lib/rdoc/code_objects.rb', line 467 def diagram @diagram end |
#file_absolute_name ⇒ Object
Returns the value of attribute file_absolute_name
466 467 468 |
# File 'lib/rdoc/code_objects.rb', line 466 def file_absolute_name @file_absolute_name end |
#file_relative_name ⇒ Object
Returns the value of attribute file_relative_name
465 466 467 |
# File 'lib/rdoc/code_objects.rb', line 465 def file_relative_name @file_relative_name end |
#file_stat ⇒ Object
Returns the value of attribute file_stat
464 465 466 |
# File 'lib/rdoc/code_objects.rb', line 464 def file_stat @file_stat end |
Class Method Details
.all_classes_and_modules ⇒ Object
518 519 520 |
# File 'lib/rdoc/code_objects.rb', line 518 def TopLevel.all_classes_and_modules @@all_classes.values + @@all_modules.values end |
.find_class_named(name) ⇒ Object
522 523 524 525 526 527 528 |
# File 'lib/rdoc/code_objects.rb', line 522 def TopLevel.find_class_named(name) @@all_classes.each_value do |c| res = c.find_class_named(name) return res if res end nil end |
.reset ⇒ Object
472 473 474 475 |
# File 'lib/rdoc/code_objects.rb', line 472 def TopLevel::reset @@all_classes = {} @@all_modules = {} end |
Instance Method Details
#add_class_or_module(collection, class_type, name, superclass) ⇒ Object
Adding a class or module to a TopLevel is special, as we only want one copy of a particular top-level class. For example, if both file A and file B implement class C, we only want one ClassModule object for C. This code arranges to share classes and modules between files.
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/rdoc/code_objects.rb', line 496 def add_class_or_module(collection, class_type, name, superclass) cls = collection[name] if cls puts "Reusing class/module #{name}" if $DEBUG else if class_type == NormalModule all = @@all_modules else all = @@all_classes end cls = all[name] if !cls cls = class_type.new(name, superclass) all[name] = cls unless @done_documenting end puts "Adding class/module #{name} to #@name" if $DEBUG collection[name] = cls unless @done_documenting cls.parent = self end cls end |
#find_class_or_module_named(symbol) ⇒ Object
534 535 536 537 538 |
# File 'lib/rdoc/code_objects.rb', line 534 def find_class_or_module_named(symbol) @@all_classes.each_value {|c| return c if c.name == symbol} @@all_modules.each_value {|m| return m if m.name == symbol} nil end |
#find_local_symbol(symbol) ⇒ Object
530 531 532 |
# File 'lib/rdoc/code_objects.rb', line 530 def find_local_symbol(symbol) find_class_or_module_named(symbol) || super end |
#find_module_named(name) ⇒ Object
Find a named module
541 542 543 |
# File 'lib/rdoc/code_objects.rb', line 541 def find_module_named(name) find_class_or_module_named(name) || find_enclosing_module_named(name) end |
#full_name ⇒ Object
486 487 488 |
# File 'lib/rdoc/code_objects.rb', line 486 def full_name nil end |