Class: Inch::CodeObject::Provider::YARD::Object::Base
Abstract
- Inherits:
-
Object
- Object
- Inch::CodeObject::Provider::YARD::Object::Base
show all
- Extended by:
- Forwardable
- Includes:
- NodocHelper
- Defined in:
- lib/inch/code_object/provider/yard/object/base.rb
Overview
Defined Under Namespace
Classes: CodeLocation
Constant Summary
collapse
- CONSIDERED_YARD_TAGS =
%w(api example param private return)
- 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) +
%w(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
Instance Method Summary
collapse
#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.
26
27
28
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 26
def initialize(object)
@object = object
end
|
Instance Attribute Details
#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
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
|
Instance Method Details
34
35
36
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 34
def api_tag
tag(:api) || (parent && parent.api_tag)
end
|
#api_tag? ⇒ Boolean
30
31
32
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 30
def api_tag?
!api_tag.nil?
end
|
41
42
43
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 41
def child(name)
nil
end
|
52
53
54
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 52
def children
[]
end
|
#children_fullnames ⇒ Array?
Returns the full names of the children of the current object.
46
47
48
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 46
def children_fullnames
[]
end
|
#core? ⇒ Boolean
58
59
60
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 58
def core?
RUBY_CORE.include?(name.to_s)
end
|
#depth(i = 0) ⇒ Fixnum
Note:
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?”
162
163
164
165
166
167
168
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 162
def depth(i = 0)
if parent
parent.depth(i+1)
else
i
end
end
|
63
64
65
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 63
def docstring
@docstring ||= Docstring.new(object.docstring)
end
|
#filename ⇒ String
Returns the name of the file where the object is declared first
96
97
98
99
100
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 96
def filename
files.first && files.first.filename
end
|
#files ⇒ Array<Array(String, Fixnum)>
Returns all files declaring the object in the form of an Array of Arrays containing the filename and the line number of their declaration.
77
78
79
80
81
82
83
84
85
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 77
def files
object.files.map do |(filename, line_no)|
CodeLocation.new(base_dir, filename, line_no)
end
rescue ::YARD::CodeObjects::ProxyMethodError
[]
end
|
102
103
104
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 102
def fullname
object.path
end
|
#has_alias? ⇒ Boolean
110
111
112
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 110
def has_alias?
false
end
|
#has_children? ⇒ Boolean
114
115
116
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 114
def has_children?
!children.empty?
end
|
#has_code_example? ⇒ Boolean
118
119
120
121
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 118
def has_code_example?
!tags(:example).empty? ||
docstring.contains_code_example?
end
|
#has_doc? ⇒ Boolean
123
124
125
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 123
def has_doc?
!docstring.empty?
end
|
#has_multiple_code_examples? ⇒ Boolean
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 127
def has_multiple_code_examples?
if tags(: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
|
141
142
143
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 141
def has_unconsidered_tags?
!unconsidered_tags.empty?
end
|
#in_in_root? ⇒ Boolean
145
146
147
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 145
def in_in_root?
depth == 1
end
|
#in_root? ⇒ Boolean
215
216
217
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 215
def in_root?
depth == 1
end
|
228
229
230
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 228
def inspect
"#<#{self.class.to_s}: #{path}>"
end
|
#method? ⇒ Boolean
Returns true if the object represents a method.
171
172
173
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 171
def method?
false
end
|
106
107
108
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 106
def name
object.name
end
|
#namespace? ⇒ Boolean
Returns true if the object represents a namespace.
176
177
178
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 176
def namespace?
false
end
|
#parameters ⇒ Object
180
181
182
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 180
def parameters
[]
end
|
#parent ⇒ Array?
Returns the parent of the current object or nil.
185
186
187
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 185
def parent
YARD::Object.for(object.parent) if object.parent
end
|
#private? ⇒ Boolean
189
190
191
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 189
def private?
visibility == :private
end
|
#private_api_tag? ⇒ Boolean
203
204
205
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 203
def private_api_tag?
api_tag && api_tag.text == 'private'
end
|
#private_tag ⇒ Object
199
200
201
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 199
def private_tag
tag(:private) || (parent && parent.private_tag)
end
|
#private_tag? ⇒ Boolean
Returns true if the object or its parent is tagged as @private.
195
196
197
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 195
def private_tag?
!private_tag.nil?
end
|
#protected? ⇒ Boolean
207
208
209
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 207
def protected?
visibility == :protected
end
|
#public? ⇒ Boolean
211
212
213
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 211
def public?
visibility == :public
end
|
#unconsidered_tag_count ⇒ Object
224
225
226
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 224
def unconsidered_tag_count
unconsidered_tags.size
end
|
#undocumented? ⇒ Boolean
Returns true if the object has no documentation at all.
220
221
222
|
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 220
def undocumented?
docstring.empty? && tags.empty?
end
|