Class: RDoc::TopLevel
- Inherits:
-
Context
- Object
- CodeObject
- Context
- RDoc::TopLevel
- Defined in:
- lib/rdoc/top_level.rb,
lib/rdoc/generator/markup.rb
Overview
A TopLevel context is a representation of the contents of a single file
Constant Summary collapse
- MARSHAL_VERSION =
:nodoc:
0
Constants inherited from Context
Context::TOMDOC_TITLES, Context::TOMDOC_TITLES_SORT, Context::TYPES
Constants included from Text
RDoc::Text::MARKUP_FORMAT, RDoc::Text::TO_HTML_CHARACTERS
Instance Attribute Summary collapse
-
#absolute_name ⇒ Object
Absolute name of this file.
-
#classes_or_modules ⇒ Object
readonly
All the classes or modules that were declared in this file.
-
#diagram ⇒ Object
:nodoc:.
-
#file_stat ⇒ Object
This TopLevel’s File::Stat struct.
-
#parser ⇒ Object
The parser class that processed this file.
-
#relative_name ⇒ Object
Relative name of this file.
Attributes inherited from Context
#aliases, #attributes, #block_params, #constants, #constants_hash, #current_line_visibility, #current_section, #extends, #external_aliases, #in_files, #includes, #method_list, #methods_hash, #params, #requires, #temporary_section, #unmatched_alias_lists, #visibility
Attributes inherited from CodeObject
#comment, #document_children, #document_self, #done_documenting, #file, #force_documentation, #line, #metadata, #parent, #received_nodoc, #section, #store, #viewer
Attributes included from Text
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
An RDoc::TopLevel is equal to another with the same relative_name.
-
#add_alias(an_alias) ⇒ Object
Adds
an_alias
toObject
instead ofself
. -
#add_constant(constant) ⇒ Object
Adds
constant
toObject
instead ofself
. -
#add_include(include) ⇒ Object
Adds
include
toObject
instead ofself
. -
#add_method(method) ⇒ Object
Adds
method
toObject
instead ofself
. -
#add_to_classes_or_modules(mod) ⇒ Object
Adds class or module
mod
. -
#base_name ⇒ Object
(also: #name)
Base name of this file.
-
#cvs_url ⇒ Object
Returns a URL for this source file on some web repository.
-
#display? ⇒ Boolean
Only a TopLevel that contains text file) will be displayed.
-
#find_class_or_module(name) ⇒ Object
See RDoc::TopLevel::find_class_or_module – TODO Why do we search through all classes/modules found, not just the ones of this instance?.
-
#find_local_symbol(symbol) ⇒ Object
Finds a class or module named
symbol
. -
#find_module_named(name) ⇒ Object
Finds a module or class with
name
. -
#full_name ⇒ Object
Returns the relative name of this file.
-
#hash ⇒ Object
An RDoc::TopLevel has the same hash as another with the same relative_name.
-
#http_url(prefix) ⇒ Object
URL for this with a
prefix
. -
#initialize(absolute_name, relative_name = absolute_name) ⇒ TopLevel
constructor
Creates a new TopLevel for the file at
absolute_name
. -
#inspect ⇒ Object
:nodoc:.
-
#last_modified ⇒ Object
Time this file was last modified, if known.
-
#marshal_dump ⇒ Object
Dumps this TopLevel for use by ri.
-
#marshal_load(array) ⇒ Object
Loads this TopLevel from
array
. -
#object_class ⇒ Object
Returns the NormalClass “Object”, creating it if not found.
-
#page_name ⇒ Object
Base name of this file without the extension.
-
#path ⇒ Object
Path to this file for use with HTML generator output.
-
#pretty_print(q) ⇒ Object
:nodoc:.
-
#search_record ⇒ Object
Search record used by RDoc::Generator::JsonIndex.
-
#text? ⇒ Boolean
Is this TopLevel from a text file instead of a source code file?.
-
#to_s ⇒ Object
:nodoc:.
Methods inherited from Context
#<=>, #add, #add_attribute, #add_class, #add_class_or_module, #add_extend, #add_module, #add_module_alias, #add_module_by_normal_module, #add_require, #add_section, #add_to, #any_content, #child_name, #class_attributes, #class_method_list, #classes, #classes_and_modules, #classes_hash, #defined_in?, #display, #each_ancestor, #each_attribute, #each_classmodule, #each_constant, #each_extend, #each_include, #each_method, #each_section, #find_attribute, #find_attribute_named, #find_class_method_named, #find_constant_named, #find_enclosing_module_named, #find_external_alias, #find_external_alias_named, #find_file_named, #find_instance_method_named, #find_method, #find_method_named, #find_symbol, #find_symbol_module, #fully_documented?, #initialize_methods_etc, #instance_attributes, #instance_method_list, #instance_methods, #methods_by_type, #methods_matching, #modules, #modules_hash, #name_for_path, #ongoing_visibility=, #record_location, #remove_from_documentation?, #remove_invisible, #remove_invisible_in, #resolve_aliases, #section_contents, #sections, #sections_hash, #set_constant_visibility_for, #set_current_section, #set_visibility_for, #sort_sections, #top_level, #upgrade_to_class
Methods inherited from CodeObject
#documented?, #each_parent, #file_name, #full_name=, #ignore, #ignored?, #initialize_visibility, #options, #parent_file_name, #parent_name, #record_location, #start_doc, #stop_doc, #suppress, #suppressed?
Methods included from Generator::Markup
#aref_to, #as_href, #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
#initialize(absolute_name, relative_name = absolute_name) ⇒ TopLevel
Creates a new TopLevel for the file at absolute_name
. If documentation is being generated outside the source dir relative_name
is relative to the source directory.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rdoc/top_level.rb', line 43 def initialize absolute_name, relative_name = absolute_name super() @name = nil @absolute_name = absolute_name @relative_name = relative_name @file_stat = File.stat(absolute_name) rescue nil # HACK for testing @diagram = nil @parser = nil @classes_or_modules = [] end |
Instance Attribute Details
#absolute_name ⇒ Object
Absolute name of this file
22 23 24 |
# File 'lib/rdoc/top_level.rb', line 22 def absolute_name @absolute_name end |
#classes_or_modules ⇒ Object (readonly)
All the classes or modules that were declared in this file. These are assigned to either #classes_hash
or #modules_hash
once we know what they really are.
29 30 31 |
# File 'lib/rdoc/top_level.rb', line 29 def classes_or_modules @classes_or_modules end |
#diagram ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/rdoc/top_level.rb', line 31 def diagram @diagram end |
#file_stat ⇒ Object
This TopLevel’s File::Stat struct
12 13 14 |
# File 'lib/rdoc/top_level.rb', line 12 def file_stat @file_stat end |
#parser ⇒ Object
The parser class that processed this file
36 37 38 |
# File 'lib/rdoc/top_level.rb', line 36 def parser @parser end |
#relative_name ⇒ Object
Relative name of this file
17 18 19 |
# File 'lib/rdoc/top_level.rb', line 17 def relative_name @relative_name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
An RDoc::TopLevel is equal to another with the same relative_name
64 65 66 |
# File 'lib/rdoc/top_level.rb', line 64 def == other self.class === other and @relative_name == other.relative_name end |
#add_alias(an_alias) ⇒ Object
Adds an_alias
to Object
instead of self
.
73 74 75 76 77 |
# File 'lib/rdoc/top_level.rb', line 73 def add_alias(an_alias) object_class.record_location self return an_alias unless @document_self object_class.add_alias an_alias end |
#add_constant(constant) ⇒ Object
Adds constant
to Object
instead of self
.
82 83 84 85 86 |
# File 'lib/rdoc/top_level.rb', line 82 def add_constant constant object_class.record_location self return constant unless @document_self object_class.add_constant constant end |
#add_include(include) ⇒ Object
Adds include
to Object
instead of self
.
91 92 93 94 95 |
# File 'lib/rdoc/top_level.rb', line 91 def add_include(include) object_class.record_location self return include unless @document_self object_class.add_include include end |
#add_method(method) ⇒ Object
Adds method
to Object
instead of self
.
100 101 102 103 104 |
# File 'lib/rdoc/top_level.rb', line 100 def add_method(method) object_class.record_location self return method unless @document_self object_class.add_method method end |
#add_to_classes_or_modules(mod) ⇒ Object
Adds class or module mod
. Used in the building phase by the Ruby parser.
110 111 112 |
# File 'lib/rdoc/top_level.rb', line 110 def add_to_classes_or_modules mod @classes_or_modules << mod end |
#base_name ⇒ Object Also known as: name
Base name of this file
117 118 119 |
# File 'lib/rdoc/top_level.rb', line 117 def base_name File.basename @relative_name end |
#cvs_url ⇒ Object
Returns a URL for this source file on some web repository. Use the -W command line option to set.
149 150 151 152 153 154 155 156 157 |
# File 'lib/rdoc/generator/markup.rb', line 149 def cvs_url url = @store.rdoc..webcvs if /%s/ =~ url then url % @relative_name else url + @relative_name end end |
#display? ⇒ Boolean
Only a TopLevel that contains text file) will be displayed. See also RDoc::CodeObject#display?
127 128 129 |
# File 'lib/rdoc/top_level.rb', line 127 def display? text? and super end |
#find_class_or_module(name) ⇒ Object
See RDoc::TopLevel::find_class_or_module – TODO Why do we search through all classes/modules found, not just the
ones of this instance?
137 138 139 |
# File 'lib/rdoc/top_level.rb', line 137 def find_class_or_module name @store.find_class_or_module name end |
#find_local_symbol(symbol) ⇒ Object
Finds a class or module named symbol
144 145 146 |
# File 'lib/rdoc/top_level.rb', line 144 def find_local_symbol(symbol) find_class_or_module(symbol) || super end |
#find_module_named(name) ⇒ Object
Finds a module or class with name
151 152 153 |
# File 'lib/rdoc/top_level.rb', line 151 def find_module_named(name) find_class_or_module(name) end |
#full_name ⇒ Object
Returns the relative name of this file
158 159 160 |
# File 'lib/rdoc/top_level.rb', line 158 def full_name @relative_name end |
#hash ⇒ Object
An RDoc::TopLevel has the same hash as another with the same relative_name
166 167 168 |
# File 'lib/rdoc/top_level.rb', line 166 def hash @relative_name.hash end |
#http_url(prefix) ⇒ Object
URL for this with a prefix
173 174 175 176 177 |
# File 'lib/rdoc/top_level.rb', line 173 def http_url(prefix) path = [prefix, @relative_name.tr('.', '_')] File.join(*path.compact) + '.html' end |
#inspect ⇒ Object
:nodoc:
179 180 181 182 183 184 185 186 |
# File 'lib/rdoc/top_level.rb', line 179 def inspect # :nodoc: "#<%s:0x%x %p modules: %p classes: %p>" % [ self.class, object_id, base_name, @modules.map { |n,m| m }, @classes.map { |n,c| c } ] end |
#last_modified ⇒ Object
Time this file was last modified, if known
191 192 193 |
# File 'lib/rdoc/top_level.rb', line 191 def last_modified @file_stat ? file_stat.mtime : nil end |
#marshal_dump ⇒ Object
Dumps this TopLevel for use by ri. See also #marshal_load
198 199 200 201 202 203 204 205 |
# File 'lib/rdoc/top_level.rb', line 198 def marshal_dump [ MARSHAL_VERSION, @relative_name, @parser, parse(@comment), ] end |
#marshal_load(array) ⇒ Object
Loads this TopLevel from array
.
210 211 212 213 214 215 216 217 |
# File 'lib/rdoc/top_level.rb', line 210 def marshal_load array # :nodoc: initialize array[1] @parser = array[2] @comment = array[3] @file_stat = nil end |
#object_class ⇒ Object
Returns the NormalClass “Object”, creating it if not found.
Records self
as a location in “Object”.
224 225 226 227 228 229 230 |
# File 'lib/rdoc/top_level.rb', line 224 def object_class @object_class ||= begin oc = @store.find_class_named('Object') || add_class(RDoc::NormalClass, 'Object') oc.record_location self oc end end |
#page_name ⇒ Object
Base name of this file without the extension
235 236 237 238 239 240 |
# File 'lib/rdoc/top_level.rb', line 235 def page_name basename = File.basename @relative_name basename =~ /\.(rb|rdoc|txt|md)$/i $` || basename end |
#path ⇒ Object
Path to this file for use with HTML generator output.
245 246 247 |
# File 'lib/rdoc/top_level.rb', line 245 def path http_url @store.rdoc.generator.file_dir end |
#pretty_print(q) ⇒ Object
:nodoc:
249 250 251 252 253 254 255 256 257 258 |
# File 'lib/rdoc/top_level.rb', line 249 def pretty_print q # :nodoc: q.group 2, "[#{self.class}: ", "]" do q.text "base name: #{base_name.inspect}" q.breakable items = @modules.map { |n,m| m } items.concat @modules.map { |n,c| c } q.seplist items do |mod| q.pp mod end end end |
#search_record ⇒ Object
Search record used by RDoc::Generator::JsonIndex
263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/rdoc/top_level.rb', line 263 def search_record return unless @parser < RDoc::Parser::Text [ page_name, '', page_name, '', path, '', snippet(@comment), ] end |
#text? ⇒ Boolean
Is this TopLevel from a text file instead of a source code file?
280 281 282 |
# File 'lib/rdoc/top_level.rb', line 280 def text? @parser and @parser.include? RDoc::Parser::Text end |
#to_s ⇒ Object
:nodoc:
284 285 286 |
# File 'lib/rdoc/top_level.rb', line 284 def to_s # :nodoc: "file #{full_name}" end |