Class: Inch::CodeObject::Provider::YARD::Object::Base Abstract
- Inherits:
-
Object
- Object
- Inch::CodeObject::Provider::YARD::Object::Base
- Extended by:
- Forwardable
- Includes:
- NodocHelper
- Defined in:
- lib/inch/code_object/provider/yard/object/base.rb
Overview
Direct Known Subclasses
ClassVariableObject, ConstantObject, MethodObject, NamespaceObject
Defined Under Namespace
Classes: CodeLocation
Constant Summary collapse
- CONSIDERED_YARD_TAGS =
Tags considered by wrapper methods like #has_code_example?
%w(api example param private return since)
- AUTO_GENERATED_TAG_NAMES =
%w(raise yield)
- RUBY_CORE =
%w( Array Bignum BasicObject Object Module Class Complex NilClass Numeric String Float Fiber FiberError Continuation Dir File Encoding Enumerator StopIteration Enumerator::Generator Enumerator::Yielder Exception SystemExit SignalException Interrupt StandardError TypeError ArgumentError IndexError KeyError RangeError ScriptError SyntaxError LoadError NotImplementedError NameError NoMethodError RuntimeError SecurityError NoMemoryError EncodingError SystemCallError Encoding::CompatibilityError File::Stat IO Hash ENV IOError EOFError ARGF RubyVM RubyVM::InstructionSequence Math::DomainError ZeroDivisionError FloatDomainError Integer Fixnum Data TrueClass FalseClass Mutex Thread Proc LocalJumpError SystemStackError Method UnboundMethod Binding Process::Status Random Range Rational RegexpError Regexp MatchData Symbol Struct ThreadGroup ThreadError Time Encoding::UndefinedConversionError Encoding::InvalidByteSequenceError Encoding::ConverterNotFoundError Encoding::Converter RubyVM::Env Comparable Kernel File::Constants Enumerable Errno FileTest GC ObjectSpace GC::Profiler IO::WaitReadable IO::WaitWritable Marshal Math Process Process::UID Process::GID Process::Sys Signal )
Constants included from NodocHelper
NodocHelper::DOC_REGEX, NodocHelper::NO_DOC_ALL_REGEX, NodocHelper::NO_DOC_REGEX
Instance Attribute Summary collapse
-
#aliased_object_fullname ⇒ Object
Returns the fullname of the object that the current object is an alias for.
-
#api_tag ⇒ Object
readonly
Returns the value of attribute api_tag.
-
#base_dir ⇒ String
The codebase’s directory.
-
#object ⇒ YARD::CodeObjects::Base
readonly
The actual (YARD) code object.
-
#parent ⇒ Array?
readonly
The parent of the current object or
nil
.
Instance Method Summary collapse
- #__parent ⇒ Object
-
#aliases_fullnames ⇒ Object
Returns the fullnames of the objects that are aliases for the current object.
- #api_tag? ⇒ Boolean
-
#child(_name) ⇒ CodeObject::Proxy::Base?
To be overridden.
-
#children ⇒ Object
To be overridden.
-
#children_fullnames ⇒ Array?
The full names of the children of the current object.
- #core? ⇒ Boolean
-
#depth ⇒ Fixnum
The depth of the following is 4:.
- #docstring ⇒ Docstring
-
#filename ⇒ String
Returns the name of the file where the object is declared first.
-
#files ⇒ Array<CodeLocation>
Returns all files declaring the object in the form of an Array of Arrays containing the location of their declaration.
- #fullname ⇒ Object
- #has_children? ⇒ Boolean
- #has_code_example? ⇒ Boolean
- #has_doc? ⇒ Boolean
- #has_multiple_code_examples? ⇒ Boolean
- #has_unconsidered_tags? ⇒ Boolean
- #in_in_root? ⇒ Boolean
- #in_root? ⇒ Boolean
-
#initialize(object) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
-
#method? ⇒ Boolean
true
if the object represents a method. - #name ⇒ Object
-
#namespace? ⇒ Boolean
true
if the object represents a namespace. -
#original_docstring ⇒ String
The documentation comments.
- #parameters ⇒ Object
- #private? ⇒ Boolean
- #protected? ⇒ Boolean
- #public? ⇒ Boolean
- #tagged_as_internal_api? ⇒ Boolean
- #tagged_as_private? ⇒ Boolean
- #unconsidered_tag_count ⇒ Object
-
#undocumented? ⇒ Boolean
true
if the object has no documentation at all.
Methods included from NodocHelper
#declarations, #explicit_doc_comment?, #explicit_nodoc_all_comment?, #explicit_nodoc_comment?, #get_line_no, #implicit_nodoc_all_comment?, #implicit_nodoc_comment?, #nodoc?, #nodoc_comment?
Constructor Details
#initialize(object) ⇒ Base
Returns a new instance of Base.
30 31 32 33 34 35 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 30 def initialize(object) @object = object @api_tag = __api_tag @parent = __parent @private_tag = __private_tag end |
Instance Attribute Details
#aliased_object_fullname ⇒ Object
Returns the fullname of the object that the current object is an alias for
39 40 41 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 39 def aliased_object_fullname @aliased_object_fullname end |
#api_tag ⇒ Object (readonly)
Returns the value of attribute api_tag.
51 52 53 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 51 def api_tag @api_tag end |
#base_dir ⇒ String
Returns the codebase’s directory.
17 18 19 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 17 def base_dir @base_dir end |
#object ⇒ YARD::CodeObjects::Base (readonly)
Returns the actual (YARD) code object.
14 15 16 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 14 def object @object end |
#parent ⇒ Array? (readonly)
Returns the parent of the current object or nil
.
214 215 216 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 214 def parent @parent end |
Instance Method Details
#__parent ⇒ Object
216 217 218 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 216 def __parent YARD::Object.for(object.parent) if object.parent end |
#aliases_fullnames ⇒ Object
Returns the fullnames of the objects that are aliases for the current object
43 44 45 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 43 def aliases_fullnames [] end |
#api_tag? ⇒ Boolean
47 48 49 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 47 def api_tag? !api_tag.nil? end |
#child(_name) ⇒ CodeObject::Proxy::Base?
To be overridden
57 58 59 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 57 def child(_name) nil end |
#children ⇒ Object
To be overridden
69 70 71 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 69 def children [] end |
#children_fullnames ⇒ Array?
Returns the full names of the children of the current object.
63 64 65 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 63 def children_fullnames [] end |
#core? ⇒ Boolean
96 97 98 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 96 def core? RUBY_CORE.include?(name.to_s) end |
#depth ⇒ Fixnum
top-level counts, that’s why Foo has depth 1!
The depth of the following is 4:
Foo::Bar::Baz#initialize
^ ^ ^ ^
1 << 2 << 3 << 4
depth
answers the question “how many layers of code objects are above this one?”
190 191 192 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 190 def depth @__depth ||= __depth end |
#docstring ⇒ Docstring
101 102 103 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 101 def docstring @docstring ||= Docstring.new(object.docstring) end |
#filename ⇒ String
Returns the name of the file where the object is declared first
129 130 131 132 133 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 129 def filename # just checking the first file (which is the file where an object # is first declared) files.first && files.first.filename end |
#files ⇒ Array<CodeLocation>
Returns all files declaring the object in the form of an Array of Arrays containing the location of their declaration.
109 110 111 112 113 114 115 116 117 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 109 def files object.files.map do |(filename, line_no)| CodeLocation.new(base_dir, filename, line_no) end rescue ::YARD::CodeObjects::ProxyMethodError # this error is raised by YARD # see broken.rb in test fixtures [] end |
#fullname ⇒ Object
135 136 137 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 135 def fullname @fullname ||= object.path end |
#has_children? ⇒ Boolean
143 144 145 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 143 def has_children? !children.empty? end |
#has_code_example? ⇒ Boolean
147 148 149 150 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 147 def has_code_example? !(:example).empty? || docstring.contains_code_example? end |
#has_doc? ⇒ Boolean
152 153 154 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 152 def has_doc? !docstring.empty? end |
#has_multiple_code_examples? ⇒ Boolean
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 156 def has_multiple_code_examples? if (:example).size > 1 || docstring.code_examples.size > 1 true else if (tag = tag(:example)) multi_code_examples?(tag.text) elsif (text = docstring.code_examples.first) multi_code_examples?(text) else false end end end |
#has_unconsidered_tags? ⇒ Boolean
170 171 172 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 170 def !.empty? end |
#in_in_root? ⇒ Boolean
174 175 176 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 174 def in_in_root? depth == 1 end |
#in_root? ⇒ Boolean
240 241 242 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 240 def in_root? depth == 1 end |
#inspect ⇒ Object
253 254 255 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 253 def inspect "#<#{self.class}: #{fullname}>" end |
#method? ⇒ Boolean
Returns true
if the object represents a method.
195 196 197 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 195 def method? false end |
#name ⇒ Object
139 140 141 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 139 def name @name ||= object.name end |
#namespace? ⇒ Boolean
Returns true
if the object represents a namespace.
200 201 202 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 200 def namespace? false end |
#original_docstring ⇒ String
Returns the documentation comments.
205 206 207 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 205 def original_docstring object.docstring.all.to_s end |
#parameters ⇒ Object
209 210 211 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 209 def parameters [] end |
#private? ⇒ Boolean
220 221 222 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 220 def private? visibility == :private end |
#protected? ⇒ Boolean
232 233 234 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 232 def protected? visibility == :protected end |
#public? ⇒ Boolean
236 237 238 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 236 def public? visibility == :public end |
#tagged_as_internal_api? ⇒ Boolean
224 225 226 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 224 def tagged_as_internal_api? private_api_tag? || docstring.describes_internal_api? end |
#tagged_as_private? ⇒ Boolean
228 229 230 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 228 def tagged_as_private? private_tag? || docstring.describes_private_object? end |
#unconsidered_tag_count ⇒ Object
249 250 251 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 249 def unconsidered_tag_count .size end |
#undocumented? ⇒ Boolean
Returns true
if the object has no documentation at all.
245 246 247 |
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 245 def undocumented? original_docstring.empty? end |