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::Alias, 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
Returns the value of attribute comments.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
- #The comment lines which directly preceeded the definition.(commentlineswhichdirectlypreceededthedefinition.) ⇒ Object readonly
- #The language the symbol is defined within.(languagethesymbolisdefinedwithin.) ⇒ Object readonly
- #The path to the definition, relative to the parent.(pathtothedefinition, relativetotheparent.) ⇒ Object readonly
- #The source file containing this definition.(sourcefilecontainingthisdefinition.) ⇒ Object readonly
-
#visibility ⇒ Object
The visibility of the definition.
Instance Method Summary collapse
-
#:public, :private, :protected=(: public, : private, : protected=(value)) ⇒ Object
The visibility of the definition.
-
#container? ⇒ Boolean
Whether this definition can contain nested definitions.
-
#convert(kind) ⇒ Object
Convert this definition into another kind of definition.
- #coverage_relevant? ⇒ Boolean
-
#documentation ⇒ Object
Structured access to the definitions comments.
-
#documented? ⇒ Boolean
Whether the definition has documentation.
-
#full_path ⇒ Object
(also: #lexical_path)
The full path to the definition.
-
#initialize(path, parent: nil, language: parent&.language, comments: nil, visibility: :public, source: parent&.source) ⇒ Definition
constructor
Initialize the symbol.
-
#inspect ⇒ Object
(also: #to_s)
Generate a debug representation of the definition.
-
#location ⇒ Object
The location of the definition.
-
#long_form ⇒ Object
A long form of the definition.
-
#multiline? ⇒ Boolean
Whether the definition spans multiple lines.
- #name ⇒ Object
-
#nested? ⇒ Boolean
Whether this represents a single entity to be documented (along with it’s contents).
- #nested_name ⇒ Object
-
#public? ⇒ Boolean
Whether the definition is considered part of the public interface.
-
#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.
- #The parent definition, defining lexical scope.=(parentdefinition, defininglexicalscope. = (value)) ⇒ Object
- #The symbol name e.g. `:Decode`.=(symbolnamee.g.`: Decode`.=(value)) ⇒ Object
Constructor Details
#initialize(path, parent: nil, language: parent&.language, comments: nil, visibility: :public, source: parent&.source) ⇒ Definition
Initialize the symbol.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/decode/definition.rb', line 18 def initialize(path, parent: nil, language: parent&.language, comments: nil, visibility: :public, source: parent&.source) @path = Array(path).map(&:to_sym) @parent = parent @language = language @source = source @comments = comments @visibility = visibility @documentation = nil @full_path = nil @qualified_name = nil @nested_name = nil end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
76 77 78 |
# File 'lib/decode/definition.rb', line 76 def comments @comments end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
70 71 72 |
# File 'lib/decode/definition.rb', line 70 def language @language end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
67 68 69 |
# File 'lib/decode/definition.rb', line 67 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
48 49 50 |
# File 'lib/decode/definition.rb', line 48 def path @path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
73 74 75 |
# File 'lib/decode/definition.rb', line 73 def source @source end |
#The comment lines which directly preceeded the definition.(commentlineswhichdirectlypreceededthedefinition.) ⇒ Object (readonly)
76 |
# File 'lib/decode/definition.rb', line 76 attr :comments |
#The language the symbol is defined within.(languagethesymbolisdefinedwithin.) ⇒ Object (readonly)
70 |
# File 'lib/decode/definition.rb', line 70 attr :language |
#The path to the definition, relative to the parent.(pathtothedefinition, relativetotheparent.) ⇒ Object (readonly)
48 |
# File 'lib/decode/definition.rb', line 48 attr :path |
#The source file containing this definition.(sourcefilecontainingthisdefinition.) ⇒ Object (readonly)
73 |
# File 'lib/decode/definition.rb', line 73 attr :source |
#visibility ⇒ Object
The visibility of the definition.
194 195 196 |
# File 'lib/decode/definition.rb', line 194 def visibility @visibility end |
Instance Method Details
#:public, :private, :protected=(: public, : private, : protected=(value)) ⇒ Object
The visibility of the definition.
194 |
# File 'lib/decode/definition.rb', line 194 attr_accessor :visibility |
#container? ⇒ Boolean
Whether this definition can contain nested definitions.
165 166 167 |
# File 'lib/decode/definition.rb', line 165 def container? false end |
#convert(kind) ⇒ Object
Convert this definition into another kind of definition.
122 123 124 |
# File 'lib/decode/definition.rb', line 122 def convert(kind) raise ArgumentError, "Unable to convert #{self} into #{kind}!" end |
#coverage_relevant? ⇒ Boolean
86 87 88 |
# File 'lib/decode/definition.rb', line 86 def coverage_relevant? self.public? end |
#documentation ⇒ Object
Structured access to the definitions comments.
179 180 181 182 183 |
# File 'lib/decode/definition.rb', line 179 def documentation if comments = @comments and comments.any? @documentation ||= Documentation.new(comments, @language) end end |
#documented? ⇒ Boolean
Whether the definition has documentation.
92 93 94 |
# File 'lib/decode/definition.rb', line 92 def documented? @comments&.any? || false end |
#full_path ⇒ Object Also known as: lexical_path
The full path to the definition.
52 53 54 55 56 57 58 59 60 |
# File 'lib/decode/definition.rb', line 52 def full_path @full_path ||= begin if parent = @parent parent.full_path + @path else @path end end end |
#inspect ⇒ Object Also known as: to_s
Generate a debug representation of the definition.
35 36 37 |
# File 'lib/decode/definition.rb', line 35 def inspect "\#<#{self.class} #{qualified_name}>" end |
#location ⇒ Object
The location of the definition.
188 189 190 |
# File 'lib/decode/definition.rb', line 188 def location nil end |
#long_form ⇒ Object
A long form of the definition. e.g. ‘def initialize(kind, name, comments, **options)`.
137 138 139 |
# File 'lib/decode/definition.rb', line 137 def long_form self.short_form end |
#multiline? ⇒ Boolean
Whether the definition spans multiple lines.
152 153 154 |
# File 'lib/decode/definition.rb', line 152 def multiline? false end |
#name ⇒ Object
43 44 45 |
# File 'lib/decode/definition.rb', line 43 def name @path.last end |
#nested? ⇒ Boolean
Whether this represents a single entity to be documented (along with it’s contents).
172 173 174 |
# File 'lib/decode/definition.rb', line 172 def nested? container? end |
#nested_name ⇒ Object
109 110 111 |
# File 'lib/decode/definition.rb', line 109 def nested_name @nested_name ||= "#{@path.join("::")}" end |
#public? ⇒ Boolean
Whether the definition is considered part of the public interface. This is used to determine whether the definition should be documented for coverage purposes.
81 82 83 |
# File 'lib/decode/definition.rb', line 81 def public? true end |
#qualified_form ⇒ Object
A long form which uses the qualified name if possible. Defaults to #long_form.
145 146 147 |
# File 'lib/decode/definition.rb', line 145 def qualified_form self.long_form end |
#qualified_name ⇒ Object
The qualified name is an absolute name which includes any and all namespacing.
98 99 100 101 102 103 104 105 106 |
# File 'lib/decode/definition.rb', line 98 def qualified_name @qualified_name ||= begin if parent = @parent [parent.qualified_name, self.nested_name].join("::") else self.nested_name end end end |
#short_form ⇒ Object
A short form of the definition. e.g. ‘def short_form`.
130 131 |
# File 'lib/decode/definition.rb', line 130 def short_form end |
#start_with?(prefix) ⇒ Boolean
Does the definition name match the specified prefix?
116 117 118 |
# File 'lib/decode/definition.rb', line 116 def start_with?(prefix) self.nested_name.start_with?(prefix) end |
#text ⇒ Object
The full text of the definition.
159 160 |
# File 'lib/decode/definition.rb', line 159 def text end |
#The parent definition, defining lexical scope.=(parentdefinition, defininglexicalscope. = (value)) ⇒ Object
67 |
# File 'lib/decode/definition.rb', line 67 attr :parent |
#The symbol name e.g. `:Decode`.=(symbolnamee.g.`: Decode`.=(value)) ⇒ Object
43 44 45 |
# File 'lib/decode/definition.rb', line 43 def name @path.last end |