Class: RDoc::TopLevel
- Inherits:
-
Context
- Object
- CodeObject
- Context
- RDoc::TopLevel
- Defined in:
- lib/rdoc/code_object/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::SPACE_SEPARATED_LETTER_CLASS, RDoc::Text::TO_HTML_CHARACTERS
Instance Attribute Summary collapse
-
#absolute_name ⇒ Object
Absolute name of this file.
-
#base_name ⇒ Object
(also: #name)
readonly
Base name of this file.
-
#classes_or_modules ⇒ Object
readonly
All the classes or modules that were declared in this file.
-
#page_name ⇒ Object
readonly
Base name of this file without the extension.
-
#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, #mixin_from, #parent, #received_nodoc, #section, #store
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_aliastoObjectinstead ofself. -
#add_constant(constant) ⇒ Object
Adds
constanttoObjectinstead ofself. -
#add_include(include) ⇒ Object
Adds
includetoObjectinstead ofself. -
#add_method(method) ⇒ Object
Adds
methodtoObjectinstead ofself. -
#add_to_classes_or_modules(mod) ⇒ Object
Adds class or module
mod. -
#cvs_url ⇒ Object
Returns a URL for this source file on some web repository.
-
#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 ⇒ 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:.
-
#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.
-
#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, #display, #each_ancestor, #each_classmodule, #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_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
#display?, #documented?, #file_name, #full_name=, #ignore, #ignored?, #initialize_visibility, #options, #parent_name, #record_location, #start_doc, #stop_doc, #suppress, #suppressed?
Methods included from Generator::Markup
#aref_to, #as_href, #canonical_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
#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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rdoc/code_object/top_level.rb', line 46 def initialize(absolute_name, relative_name = absolute_name) super() @name = nil @absolute_name = absolute_name @relative_name = relative_name @parser = nil if relative_name @base_name = File.basename(relative_name) @page_name = @base_name.sub(/\.(rb|rdoc|txt|md)\z/i, '') else @base_name = nil @page_name = nil end @classes_or_modules = [] end |
Instance Attribute Details
#absolute_name ⇒ Object
Absolute name of this file
17 18 19 |
# File 'lib/rdoc/code_object/top_level.rb', line 17 def absolute_name @absolute_name end |
#base_name ⇒ Object (readonly) Also known as: name
Base name of this file
22 23 24 |
# File 'lib/rdoc/code_object/top_level.rb', line 22 def base_name @base_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.
34 35 36 |
# File 'lib/rdoc/code_object/top_level.rb', line 34 def classes_or_modules @classes_or_modules end |
#page_name ⇒ Object (readonly)
Base name of this file without the extension
27 28 29 |
# File 'lib/rdoc/code_object/top_level.rb', line 27 def page_name @page_name end |
#parser ⇒ Object
The parser class that processed this file
39 40 41 |
# File 'lib/rdoc/code_object/top_level.rb', line 39 def parser @parser end |
#relative_name ⇒ Object
Relative name of this file
12 13 14 |
# File 'lib/rdoc/code_object/top_level.rb', line 12 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
76 77 78 |
# File 'lib/rdoc/code_object/top_level.rb', line 76 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.
85 86 87 88 89 |
# File 'lib/rdoc/code_object/top_level.rb', line 85 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.
94 95 96 97 98 |
# File 'lib/rdoc/code_object/top_level.rb', line 94 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.
103 104 105 106 107 |
# File 'lib/rdoc/code_object/top_level.rb', line 103 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.
112 113 114 115 116 |
# File 'lib/rdoc/code_object/top_level.rb', line 112 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.
122 123 124 |
# File 'lib/rdoc/code_object/top_level.rb', line 122 def add_to_classes_or_modules(mod) @classes_or_modules << mod end |
#cvs_url ⇒ Object
Returns a URL for this source file on some web repository. Use the -W command line option to set.
161 162 163 164 165 166 167 168 169 |
# File 'lib/rdoc/generator/markup.rb', line 161 def cvs_url url = @store..webcvs if /%s/ =~ url then url % @relative_name else url + @relative_name end 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?
134 135 136 |
# File 'lib/rdoc/code_object/top_level.rb', line 134 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
141 142 143 |
# File 'lib/rdoc/code_object/top_level.rb', line 141 def find_local_symbol(symbol) find_class_or_module(symbol) || super end |
#find_module_named(name) ⇒ Object
Finds a module or class with name
148 149 150 |
# File 'lib/rdoc/code_object/top_level.rb', line 148 def find_module_named(name) find_class_or_module(name) end |
#full_name ⇒ Object
Returns the relative name of this file
155 156 157 |
# File 'lib/rdoc/code_object/top_level.rb', line 155 def full_name @relative_name end |
#hash ⇒ Object
An RDoc::TopLevel has the same hash as another with the same relative_name
163 164 165 |
# File 'lib/rdoc/code_object/top_level.rb', line 163 def hash @relative_name.hash end |
#http_url ⇒ Object
URL for this with a prefix
170 171 172 |
# File 'lib/rdoc/code_object/top_level.rb', line 170 def http_url @relative_name.tr('.', '_') + '.html' end |
#inspect ⇒ Object
:nodoc:
174 175 176 177 178 179 180 181 |
# File 'lib/rdoc/code_object/top_level.rb', line 174 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 |
#marshal_dump ⇒ Object
Dumps this TopLevel for use by ri. See also #marshal_load
186 187 188 189 190 191 192 193 |
# File 'lib/rdoc/code_object/top_level.rb', line 186 def marshal_dump [ MARSHAL_VERSION, @relative_name, @parser, parse(@comment), ] end |
#marshal_load(array) ⇒ Object
Loads this TopLevel from array.
198 199 200 201 202 203 |
# File 'lib/rdoc/code_object/top_level.rb', line 198 def marshal_load(array) # :nodoc: initialize array[1] @parser = array[2] @comment = RDoc::Comment.from_document array[3] end |
#object_class ⇒ Object
Returns the NormalClass “Object”, creating it if not found.
Records self as a location in “Object”.
210 211 212 213 214 215 216 |
# File 'lib/rdoc/code_object/top_level.rb', line 210 def object_class @object_class ||= begin oc = @store.find_class_named('Object') || add_class(RDoc::NormalClass, 'Object') oc.record_location self oc end end |
#path ⇒ Object
Path to this file for use with HTML generator output.
221 222 223 224 225 |
# File 'lib/rdoc/code_object/top_level.rb', line 221 def path prefix = .file_path_prefix return http_url unless prefix File.join(prefix, http_url) end |
#pretty_print(q) ⇒ Object
:nodoc:
227 228 229 230 231 232 233 234 235 236 |
# File 'lib/rdoc/code_object/top_level.rb', line 227 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
241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/rdoc/code_object/top_level.rb', line 241 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?
258 259 260 |
# File 'lib/rdoc/code_object/top_level.rb', line 258 def text? @parser and @parser.include? RDoc::Parser::Text end |
#to_s ⇒ Object
:nodoc:
262 263 264 |
# File 'lib/rdoc/code_object/top_level.rb', line 262 def to_s # :nodoc: "file #{full_name}" end |