class RDoc::TopLevel
TopLevel
上下文是单个文件内容的表示
属性
此文件的绝对名称
此文件中声明的所有类或模块。一旦我们知道它们的真实类型,它们会被分配到 #classes_hash
或 #modules_hash
。
此 TopLevel 的 File::Stat 结构体
处理此文件的解析器类
此文件的相对名称
公共类方法
为 absolute_name
处的文件创建新的 TopLevel
。 如果在源目录之外生成文档,则 relative_name
相对于源目录。
RDoc::Context::new
# File rdoc/code_object/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
公共实例方法
具有相同 relative_name
的 RDoc::TopLevel
与另一个相等
# File rdoc/code_object/top_level.rb, line 67 def == other self.class === other and @relative_name == other.relative_name end
将 an_alias
添加到 Object
而不是 self
。
# File rdoc/code_object/top_level.rb, line 76 def add_alias(an_alias) object_class.record_location self return an_alias unless @document_self object_class.add_alias an_alias end
将 constant
添加到 Object
而不是 self
。
# File rdoc/code_object/top_level.rb, line 85 def add_constant constant object_class.record_location self return constant unless @document_self object_class.add_constant constant end
将 include
添加到 Object
而不是 self
。
# File rdoc/code_object/top_level.rb, line 94 def add_include(include) object_class.record_location self return include unless @document_self object_class.add_include include end ## # Adds +method+ to +Object+ instead of +self+. def add_method(method) object_class.record_location self return method unless @document_self object_class.add_method method end ## # Adds class or module +mod+. Used in the building phase # by the Ruby parser. def add_to_classes_or_modules mod @classes_or_modules << mod end ## # Base name of this file def base_name File.basename @relative_name end alias name base_name ## # Only a TopLevel that contains text file) will be displayed. See also # RDoc::CodeObject#display? def display? text? and super end ## # See RDoc::TopLevel::find_class_or_module #-- # TODO Why do we search through all classes/modules found, not just the # ones of this instance? def find_class_or_module name @store.find_class_or_module name end ## # Finds a class or module named +symbol+ def find_local_symbol(symbol) find_class_or_module(symbol) || super end ## # Finds a module or class with +name+ def find_module_named(name) find_class_or_module(name) end ## # Returns the relative name of this file def full_name @relative_name end ## # An RDoc::TopLevel has the same hash as another with the same # relative_name def hash @relative_name.hash end ## # URL for this with a +prefix+ def http_url(prefix) path = [prefix, @relative_name.tr('.', '_')] File.join(*path.compact) + '.html' end 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 ## # Time this file was last modified, if known def last_modified @file_stat ? file_stat.mtime : nil end ## # Dumps this TopLevel for use by ri. See also #marshal_load def marshal_dump [ MARSHAL_VERSION, @relative_name, @parser, parse(@comment), ] end ## # Loads this TopLevel from +array+. def marshal_load array # :nodoc: initialize array[1] @parser = array[2] @comment = array[3] @file_stat = nil end ## # Returns the NormalClass "Object", creating it if not found. # # Records +self+ as a location in "Object". def object_class @object_class ||= begin oc = @store.find_class_named('Object') || add_class(RDoc::NormalClass, 'Object') oc.record_location self oc end end ## # Base name of this file without the extension def page_name basename = File.basename @relative_name basename =~ /\.(rb|rdoc|txt|md)$/i $` || basename end ## # Path to this file for use with HTML generator output. def path http_url @store.rdoc.generator.file_dir end 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 used by RDoc::Generator::JsonIndex def search_record return unless @parser < RDoc::Parser::Text [ page_name, '', page_name, '', path, '', snippet(@comment), ] end ## # Is this TopLevel from a text file instead of a source code file? def text? @parser and @parser.include? RDoc::Parser::Text end def to_s # :nodoc: "file #{full_name}" end end
将 method
添加到 Object
而不是 self
。
# File rdoc/code_object/top_level.rb, line 103 def add_method(method) object_class.record_location self return method unless @document_self object_class.add_method method end
添加类或模块 mod
。 在 Ruby 解析器的构建阶段使用。
# File rdoc/code_object/top_level.rb, line 113 def add_to_classes_or_modules mod @classes_or_modules << mod end
此文件的基本名称
# File rdoc/code_object/top_level.rb, line 120 def base_name File.basename @relative_name end
返回某些 Web 存储库上此源文件的 URL。 使用 -W 命令行选项进行设置。
# File rdoc/generator/markup.rb, line 149 def cvs_url url = @store.rdoc.options.webcvs if /%s/ =~ url then url % @relative_name else url + @relative_name end end
只会显示包含文本文件) 的 TopLevel
。另请参见 RDoc::CodeObject#display?
RDoc::CodeObject#display?
# File rdoc/code_object/top_level.rb, line 130 def display? text? and super end
请参阅 RDoc::TopLevel::find_class_or_module
# File rdoc/code_object/top_level.rb, line 140 def find_class_or_module name @store.find_class_or_module name end
查找名为 symbol
的类或模块
# File rdoc/code_object/top_level.rb, line 147 def find_local_symbol(symbol) find_class_or_module(symbol) || super end
查找具有 name
的模块或类
# File rdoc/code_object/top_level.rb, line 154 def find_module_named(name) find_class_or_module(name) end
返回此文件的相对名称
# File rdoc/code_object/top_level.rb, line 161 def full_name @relative_name end
具有相同 relative_name
的 RDoc::TopLevel
与另一个具有相同的哈希值
# File rdoc/code_object/top_level.rb, line 169 def hash @relative_name.hash end
带有 prefix
的 URL
# File rdoc/code_object/top_level.rb, line 176 def http_url(prefix) path = [prefix, @relative_name.tr('.', '_')] File.join(*path.compact) + '.html' end
此文件上次修改的时间(如果已知)
# File rdoc/code_object/top_level.rb, line 194 def last_modified @file_stat ? file_stat.mtime : nil end
转储此 TopLevel
以供 ri 使用。另请参见 marshal_load
# File rdoc/code_object/top_level.rb, line 201 def marshal_dump [ MARSHAL_VERSION, @relative_name, @parser, parse(@comment), ] end
返回 NormalClass “Object”,如果未找到则创建它。
将 self
记录为 “Object” 中的位置。
# File rdoc/code_object/top_level.rb, line 227 def object_class @object_class ||= begin oc = @store.find_class_named('Object') || add_class(RDoc::NormalClass, 'Object') oc.record_location self oc end end
此文件的基本名称,不带扩展名
# File rdoc/code_object/top_level.rb, line 238 def page_name basename = File.basename @relative_name basename =~ /\.(rb|rdoc|txt|md)$/i $` || basename end
为此顶级上下文设置解析器,也设置存储。
# File rdoc/code_object/top_level.rb, line 58 def parser=(val) @parser = val @store.update_parser_of_file(absolute_name, val) if @store @parser end
用于 HTML 生成器输出的此文件路径。
# File rdoc/code_object/top_level.rb, line 248 def path http_url @store.rdoc.generator.file_dir end
RDoc::Generator::JsonIndex
使用的搜索记录
# File rdoc/code_object/top_level.rb, line 266 def search_record return unless @parser < RDoc::Parser::Text [ page_name, '', page_name, '', path, '', snippet(@comment), ] end
这个 TopLevel
来自文本文件而不是源代码文件吗?
# File rdoc/code_object/top_level.rb, line 283 def text? @parser and @parser.include? RDoc::Parser::Text end