class Definition
A symbol with attached documentation.
Definitions
def initialize(name, parent: nil, language: parent.language, comments: nil)
Initialize the symbol.
Signature
-
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.
Implementation
def initialize(name, parent: nil, language: parent.language, comments: nil)
@name = name
@parent = parent
@language = language
@comments = comments
@path = nil
@qualified_name = nil
end
attr :name
The symbol name.
e.g. :Decode
.
Signature
-
attribute
Symbol
attr :parent
The parent definition, defining lexical scope.
Signature
-
attribute
Definition | Nil
attr :language
The language the symbol is defined within.
Signature
-
attribute
Language::Generic
attr :comments
The comment lines which directly preceeded the definition.
Signature
-
attribute
Array(String)
def public?
Whether the definition is considered part of the public interface.
This is used to determine whether the definition should be documented for coverage purposes.
Signature
-
returns
Boolean
Implementation
def public?
true
end
def qualified_name
The qualified name is an absolute name which includes any and all namespacing.
Signature
-
returns
String
Implementation
def qualified_name
@qualified_name ||= begin
if @parent
@parent.qualified_name + self.nested_name
else
@name.to_s
end
end
end
def nested_name
The name of this definition plus the nesting prefix.
Signature
-
returns
String
Implementation
def nested_name
"::#{@name}"
end
def start_with?(prefix)
Does the definition name match the specified prefix?
Signature
-
returns
Boolean
Implementation
def start_with?(prefix)
self.nested_name.start_with?(prefix)
end
def convert(kind)
Convert this definition into another kind of definition.
Implementation
def convert(kind)
raise ArgumentError, "Unable to convert #{self} into #{kind}!"
end
def path
The lexical scope as an array of names.
e.g. [:Decode, :Definition]
Signature
-
returns
Array
Implementation
def path
if @path
# Cached version:
@path
elsif @parent
# Merge with parent:
@path = [*@parent.path, *path_name].freeze
else
# At top:
@path = path_name.freeze
end
end
def short_form
A short form of the definition.
e.g. def short_form
.
Signature
-
returns
String | nil
Implementation
def short_form
end
def long_form
A long form of the definition.
e.g. def initialize(kind, name, comments, **options)
.
Signature
-
returns
String | nil
Implementation
def long_form
self.short_form
end
def qualified_form
A long form which uses the qualified name if possible.
Defaults to Decode::Definition#long_form
.
Signature
-
returns
String | nil
Implementation
def qualified_form
self.long_form
end
def multiline?
Whether the definition spans multiple lines.
Signature
-
returns
Boolean
Implementation
def multiline?
false
end
def text
The full text of the definition.
Signature
-
returns
String | nil
Implementation
def text
end
def container?
Whether this definition can contain nested definitions.
Signature
-
returns
Boolean
Implementation
def container?
false
end
def nested?
Whether this represents a single entity to be documented (along with it's contents).
Signature
-
returns
Boolean
Implementation
def nested?
container?
end
def documentation
Structured access to the definitions comments.
Signature
-
returns
Documentation | Nil
A
class Decode::Documentation
instance if this definition has comments.
Implementation
def documentation
if @comments&.any?
@documentation ||= Documentation.new(@comments, @language)
end
end
def location
The location of the definition.
Signature
-
returns
Location | Nil
A
class Decode::Location
instance if this definition has a location.
Implementation
def location
nil
end