class RDoc::CodeObject
RDoc
代码树的基类。
我们包含了上下文(容器)和其他元素(方法、属性等)的通用内容
这是 CodeObject
子类的树
-
RDoc::Context
-
RDoc::TopLevel
-
RDoc::ClassModule
-
RDoc::AnonClass (目前未使用)
-
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
-
属性
我们的注释
我们是否记录我们的子类?
我们是否记录自己?
我们是否已完成文档记录(即,我们是否遇到了 :enddoc:)?
此代码对象在哪个文件中定义
此 CodeObject
在 file
中定义的行号
此 CodeObject
的任意元数据的 Hash
当混入到类中时,此项指向它最初定义的上下文。
设置父 CodeObject
我们是否曾经收到过 :nodoc:
指令?
将此 CodeObject
所属的节设置为 Set
此对象的 RDoc::Store
。
我们是代码的模型,但我们知道在某个时候,查看器会处理我们。通过实现 Viewable 协议,查看器可以将自己与这些对象关联起来。
公共类方法
源
# 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
创建一个新的 CodeObject
,它将记录自身及其子类
公共实例方法
源
# File lib/rdoc/code_object.rb, line 141 def comment=(comment) @comment = case comment when NilClass then '' when RDoc::Markup::Document then comment when RDoc::Comment then comment.normalize else if comment and not comment.empty? then normalize_comment comment else # HACK correct fix is to have #initialize create @comment # with the correct encoding if String === @comment and @comment.empty? then @comment = RDoc::Encoding.change_encoding @comment, comment.encoding end @comment end end end
用 comment
替换我们的注释,除非它为空。
源
# File lib/rdoc/code_object.rb, line 169 def display? @document_self and not @ignored and (documented? or not @suppressed) end
是否应在输出中显示此 CodeObject
?
如果满足以下条件,则应显示代码对象
-
该项没有 nodoc,或者不在具有 nodoc 的容器中
-
该项未被忽略
-
该项有文档且未被抑制
源
# File lib/rdoc/code_object.rb, line 178 def document_children=(document_children) return unless @track_visibility @document_children = document_children unless @done_documenting end
启用或禁用此 CodeObject 的子类的文档记录,除非已被 :enddoc 关闭
源
# File lib/rdoc/code_object.rb, line 189 def document_self=(document_self) return unless @track_visibility return if @done_documenting @document_self = document_self @received_nodoc = true if document_self.nil? end
启用或禁用此 CodeObject
的文档记录,除非已被 :enddoc: 关闭。如果参数为 nil
,则表示文档记录被 :nodoc:
关闭。
源
# File lib/rdoc/code_object.rb, line 200 def documented? @received_nodoc or !@comment.empty? end
此对象是否有带内容的注释,或者 received_nodoc
为真?
源
# File lib/rdoc/code_object.rb, line 213 def done_documenting=(value) return unless @track_visibility @done_documenting = value @document_self = !value @document_children = @document_self end
打开/关闭文档记录,并打开/关闭 document_self
和 document_children
。
一旦文档记录被关闭(通过 :enddoc:
),该对象将拒绝打开 document_self
或 document_children
,因此 :doc:
和 :start_doc:
指令在当前文件中将不起作用。
源
# 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
生成此 CodeObject
的每个父类。另请参阅 RDoc::ClassModule#each_ancestor
源
# File lib/rdoc/code_object.rb, line 239 def file_name return unless @file @file.absolute_name end
发现此 CodeObject
的 File
名称。
另请参阅 RDoc::Context#in_files
源
# File lib/rdoc/code_object.rb, line 251 def force_documentation=(value) @force_documentation = value unless @done_documenting end
强制记录此对象,除非文档记录已被 :enddoc 关闭
源
# File lib/rdoc/code_object.rb, line 260 def full_name= full_name @full_name = full_name end
设置全名,覆盖任何计算的全名。
将 Set
设置为 nil
以清除 RDoc 的缓存值
源
# File lib/rdoc/code_object.rb, line 280 def ignore return unless @track_visibility @ignored = true stop_doc end
使用此项可忽略 CodeObject
及其所有子类,直到再次找到它们(调用 record_location
)。忽略的项将不会显示在文档中。
请参阅 github 问题 #55
忽略状态是临时的,以便可以隐藏实现细节。在处理文件结束时,RDoc
允许所有类和模块向先前创建的类添加新的文档。
如果一个类被忽略(通过 stopdoc)然后稍后重新打开并添加了额外的文档,则应显示该类。如果一个类被忽略并且从未重新打开,则不应显示该类。ignore 标志允许发生这种情况。
源
源
# 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
来自此 CodeObject
所附加到的存储的选项实例,或者如果 CodeObject
未附加,则为默认选项实例。
这由 Text#snippet 使用
源
# 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
我们的父 CodeObject
。对于从旧的 RI 数据存储加载的类,父类可能缺失。
源
# File lib/rdoc/code_object.rb, line 337 def parent_file_name @parent ? @parent.base_name : '(unknown)' end
我们父类的 File
名称
源
# File lib/rdoc/code_object.rb, line 344 def parent_name @parent ? @parent.full_name : '(unknown)' end
我们父类的名称
源
# File lib/rdoc/code_object.rb, line 351 def record_location top_level @ignored = false @suppressed = false @file = top_level end
记录定义此代码对象的 RDoc::TopLevel(文件)
源
# File lib/rdoc/code_object.rb, line 361 def section return @section if @section @section = parent.add_section @section_title if parent end
此 CodeObject
所属的节。节允许对类或模块内的常量、属性和方法进行分组。
源
# 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
启用文档捕获,除非文档记录已被 :enddoc 关闭
源
# File lib/rdoc/code_object.rb, line 383 def stop_doc return unless @track_visibility @document_self = false @document_children = false end
禁用文档捕获
源
# File lib/rdoc/code_object.rb, line 393 def store= store @store = store return unless @track_visibility if :nodoc == options.visibility then initialize_visibility @track_visibility = false end end
设置包含此 CodeObject
的 store
源
# File lib/rdoc/code_object.rb, line 410 def suppress return unless @track_visibility @suppressed = true stop_doc end
使用此项可抑制 CodeObject
及其所有子类,直到在下一个文件中看到它或发现文档。具有文档的抑制项将显示,而具有文档的忽略项可能不会显示。