Class: Decode::Definition
- Inherits:
-
Object
- Object
- Decode::Definition
- Defined in:
- lib/decode/definition.rb
Overview
A symbol with attached documentation.
Direct Known Subclasses
Language::Ruby::Attribute, Language::Ruby::Block, Language::Ruby::Call, Language::Ruby::Class, Language::Ruby::Constant, Language::Ruby::Definition, Language::Ruby::Method, Language::Ruby::Module, Language::Ruby::Singleton, Scope
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
The comment lines which directly preceeded the definition.
-
#language ⇒ Object
readonly
The language the symbol is defined within.
-
#name ⇒ Object
The symbol name.
-
#parent ⇒ Object
The parent definition, defining lexical scope.
Instance Method Summary collapse
-
#container? ⇒ Boolean
Whether this definition can contain nested definitions.
-
#convert(kind) ⇒ Object
Convert this definition into another kind of definition.
-
#documentation ⇒ Object
Structured access to the definitions comments.
-
#initialize(name, parent: nil, language: parent.language, comments: nil) ⇒ Definition
constructor
Initialize the symbol.
-
#long_form ⇒ Object
A long form of the definition.
-
#multiline? ⇒ Boolean
Whether the definition spans multiple lines.
-
#nested? ⇒ Boolean
Whether this represents a single entity to be documented (along with it’s contents).
-
#nested_name ⇒ Object
The name of this definition plus the nesting prefix.
-
#path ⇒ Object
(also: #lexical_path)
The lexical scope as an array of names.
-
#qualified_form ⇒ Object
A long form which uses the qualified name if possible.
-
#qualified_name ⇒ Object
The qualified name is an absolute name which includes any and all namespacing.
-
#short_form ⇒ Object
A short form of the definition.
-
#start_with?(prefix) ⇒ Boolean
Does the definition name match the specified prefix?.
-
#text ⇒ Object
The full text of the definition.
- #to_s ⇒ Object
Constructor Details
#initialize(name, parent: nil, language: parent.language, comments: nil) ⇒ Definition
Initialize the symbol.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/decode/definition.rb', line 29 def initialize(name, parent: nil, language: parent.language, comments: nil) @name = name @comments = comments @language = language @parent = parent @path = nil @qualified_name = nil @documentation = nil end |
Instance Attribute Details
#comments ⇒ Object (readonly)
The comment lines which directly preceeded the definition.
60 61 62 |
# File 'lib/decode/definition.rb', line 60 def comments @comments end |
#language ⇒ Object (readonly)
The language the symbol is defined within.
56 57 58 |
# File 'lib/decode/definition.rb', line 56 def language @language end |
#name ⇒ Object
The symbol name. e.g. ‘:Decode`.
48 49 50 |
# File 'lib/decode/definition.rb', line 48 def name @name end |
#parent ⇒ Object
The parent definition, defining lexical scope.
52 53 54 |
# File 'lib/decode/definition.rb', line 52 def parent @parent end |
Instance Method Details
#container? ⇒ Boolean
Whether this definition can contain nested definitions.
148 149 150 |
# File 'lib/decode/definition.rb', line 148 def container? false end |
#convert(kind) ⇒ Object
Convert this definition into another kind of definition.
87 88 89 |
# File 'lib/decode/definition.rb', line 87 def convert(kind) raise ArgumentError, "Unable to convert #{self} into #{kind}!" end |
#documentation ⇒ Object
Structured access to the definitions comments.
162 163 164 165 166 |
# File 'lib/decode/definition.rb', line 162 def documentation if @comments&.any? @documentation ||= Documentation.new(@comments, @language) end end |
#long_form ⇒ Object
A long form of the definition. e.g. ‘def initialize(kind, name, comments, **options)`.
120 121 122 |
# File 'lib/decode/definition.rb', line 120 def long_form self.short_form end |
#multiline? ⇒ Boolean
Whether the definition spans multiple lines.
135 136 137 |
# File 'lib/decode/definition.rb', line 135 def multiline? false end |
#nested? ⇒ Boolean
Whether this represents a single entity to be documented (along with it’s contents).
155 156 157 |
# File 'lib/decode/definition.rb', line 155 def nested? container? end |
#nested_name ⇒ Object
The name of this definition plus the nesting prefix.
76 77 78 |
# File 'lib/decode/definition.rb', line 76 def nested_name "::#{@name}" end |
#path ⇒ Object Also known as: lexical_path
The lexical scope as an array of names. e.g. ‘[:Decode, :Definition]`
94 95 96 97 98 99 100 101 102 103 104 105 |
# 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 |
#qualified_form ⇒ Object
A long form which uses the qualified name if possible. Defaults to #long_form.
128 129 130 |
# File 'lib/decode/definition.rb', line 128 def qualified_form self.long_form end |
#qualified_name ⇒ Object
The qualified name is an absolute name which includes any and all namespacing.
64 65 66 67 68 69 70 71 72 |
# 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 |
#short_form ⇒ Object
A short form of the definition. e.g. ‘def short_form`.
113 114 |
# File 'lib/decode/definition.rb', line 113 def short_form end |
#start_with?(prefix) ⇒ Boolean
Does the definition name match the specified prefix?
82 83 84 |
# File 'lib/decode/definition.rb', line 82 def start_with?(prefix) self.nested_name.start_with?(prefix) end |
#text ⇒ Object
The full text of the definition.
142 143 |
# File 'lib/decode/definition.rb', line 142 def text end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/decode/definition.rb', line 41 def to_s "\#<#{self.class} #{qualified_name}>" end |