class Decode::Definition
A symbol with attached documentation.
Attributes
The comment lines which directly preceeded the definition. @attribute [Array(String)]
The language the symbol is defined within. @attribute [Language::Generic]
The symbol name. e.g. `:Decode`. @attribute [Symbol]
The parent definition, defining lexical scope. @attribute [Definition | Nil]
Public Class Methods
Initialize the symbol. @parameter name [Symbol] The name of the definition. @parameter parent [Symbol] The parent lexical scope. @parameter language [Language] The language in which the symbol is defined in. @parameter comments [Array(String)] The comments associated with the definition.
# File lib/decode/definition.rb, line 29 def initialize(name, parent: nil, language: parent.language, comments: nil) @name = name @parent = parent @language = language @comments = comments @path = nil @qualified_name = nil end
Public Instance Methods
Whether this definition can contain nested definitions.
@returns [Boolean]
# File lib/decode/definition.rb, line 148 def container? false end
Convert this definition into another kind of definition.
# File lib/decode/definition.rb, line 87 def convert(kind) raise ArgumentError, "Unable to convert #{self} into #{kind}!" end
Structured access to the definitions comments.
@returns [Documentation | Nil] A {Documentation} instance if this definition has comments.
# File lib/decode/definition.rb, line 162 def documentation if @comments&.any? @documentation ||= Documentation.new(@comments, @language) end end
A long form of the definition. e.g. `def initialize(kind, name, comments, **options)`.
@returns [String | nil]
# File lib/decode/definition.rb, line 120 def long_form self.short_form end
Whether the definition spans multiple lines.
@returns [Boolean]
# File lib/decode/definition.rb, line 135 def multiline? false end
Whether this represents a single entity to be documented (along with it's contents).
@returns [Boolean]
# File lib/decode/definition.rb, line 155 def nested? container? end
The name of this definition plus the nesting prefix. @returns [String]
# File lib/decode/definition.rb, line 76 def nested_name "::#{@name}" end
The lexical scope as an array of names. e.g. `[:Decode, :Definition]` @returns [Array]
# File lib/decode/definition.rb, line 94 def path if @path # Cached version: @path elsif @parent # Merge with parent: @path = [*@parent.path, @name].freeze else # At top: @path = [@name].freeze end end
A long form which uses the qualified name if possible. Defaults to {long_form}.
@returns [String | nil]
# File lib/decode/definition.rb, line 128 def qualified_form self.long_form end
The qualified name is an absolute name which includes any and all namespacing. @returns [String]
# File lib/decode/definition.rb, line 64 def qualified_name @qualified_name ||= begin if @parent @parent.qualified_name + self.nested_name else @name.to_s end end end
A short form of the definition. e.g. `def short_form
`.
@returns [String | nil]
# File lib/decode/definition.rb, line 113 def short_form end
Does the definition name match the specified prefix? @returns [Boolean]
# File lib/decode/definition.rb, line 82 def start_with?(prefix) self.nested_name.start_with?(prefix) end
The full text of the definition.
@returns [String | nil]
# File lib/decode/definition.rb, line 142 def text end
# File lib/decode/definition.rb, line 41 def to_s "\#<#{self.class} #{qualified_name}>" end