Class: Inch::CodeObject::Proxy::Base
Abstract
- Inherits:
-
Object
- Object
- Inch::CodeObject::Proxy::Base
show all
- Extended by:
- Forwardable
- Includes:
- NodocHelper
- Defined in:
- lib/inch/code_object/proxy/base.rb
Overview
Constant Summary
collapse
- CONSIDERED_YARD_TAGS =
%w(api example param private return)
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?, #files, #get_line_no, #implicit_nodoc_all_comment?, #implicit_nodoc_comment?, #nodoc?, #nodoc_comment?
Constructor Details
#initialize(object) ⇒ Base
Returns a new instance of Base.
29
30
31
|
# File 'lib/inch/code_object/proxy/base.rb', line 29
def initialize(object)
self.object = object
end
|
Instance Attribute Details
#grade ⇒ Symbol
67
68
69
70
71
|
# File 'lib/inch/code_object/proxy/base.rb', line 67
def grade
@grade ||= Evaluation.new_score_ranges.detect { |range|
range.range.include?(score)
}.grade
end
|
#object ⇒ YARD::CodeObjects::Base
Returns the actual (YARD) code object.
12
13
14
|
# File 'lib/inch/code_object/proxy/base.rb', line 12
def object
@object
end
|
Instance Method Details
#api_tag ⇒ Object
37
38
39
|
# File 'lib/inch/code_object/proxy/base.rb', line 37
def api_tag
object.tag(:api) || (parent && parent.api_tag)
end
|
#api_tag? ⇒ Boolean
33
34
35
|
# File 'lib/inch/code_object/proxy/base.rb', line 33
def api_tag?
!api_tag.nil?
end
|
#children ⇒ Array?
44
45
46
|
# File 'lib/inch/code_object/proxy/base.rb', line 44
def children
nil
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
^ ^ ^ ^
1 << 2 << 3 << 4
depth answers the question “how many layers of code objects are above this one?”
121
122
123
124
125
126
127
|
# File 'lib/inch/code_object/proxy/base.rb', line 121
def depth(i = 0)
if parent
parent.depth(i+1)
else
i
end
end
|
49
50
51
|
# File 'lib/inch/code_object/proxy/base.rb', line 49
def docstring
@docstring ||= Docstring.new(object.docstring)
end
|
54
55
56
|
# File 'lib/inch/code_object/proxy/base.rb', line 54
def evaluation
@evaluation ||= Evaluation.for(self)
end
|
#filename ⇒ String
Returns the name of the file where the object is declared first
60
61
62
63
64
|
# File 'lib/inch/code_object/proxy/base.rb', line 60
def filename
files.size > 0 ? files[0][0] : nil
end
|
#has_alias? ⇒ Boolean
73
74
75
|
# File 'lib/inch/code_object/proxy/base.rb', line 73
def has_alias?
!object.aliases.empty?
end
|
#has_code_example? ⇒ Boolean
77
78
79
80
|
# File 'lib/inch/code_object/proxy/base.rb', line 77
def has_code_example?
!object.tags(:example).empty? ||
docstring.contains_code_example?
end
|
#has_doc? ⇒ Boolean
82
83
84
|
# File 'lib/inch/code_object/proxy/base.rb', line 82
def has_doc?
!docstring.empty?
end
|
#has_multiple_code_examples? ⇒ Boolean
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/inch/code_object/proxy/base.rb', line 86
def has_multiple_code_examples?
if object.tags(:example).size > 1 || docstring.code_examples.size > 1
true
else
if tag = object.tag(:example)
multi_code_examples?(tag.text)
elsif text = docstring.code_examples.first
multi_code_examples?(text)
else
false
end
end
end
|
100
101
102
|
# File 'lib/inch/code_object/proxy/base.rb', line 100
def has_unconsidered_tags?
!unconsidered_tags.empty?
end
|
#in_root? ⇒ Boolean
104
105
106
|
# File 'lib/inch/code_object/proxy/base.rb', line 104
def in_root?
depth == 1
end
|
#inspect ⇒ Object
179
180
181
|
# File 'lib/inch/code_object/proxy/base.rb', line 179
def inspect
"#<#{self.class.to_s}: #{path}>"
end
|
#method? ⇒ Boolean
Returns true if the object represents a method.
130
131
132
|
# File 'lib/inch/code_object/proxy/base.rb', line 130
def method?
false
end
|
#namespace? ⇒ Boolean
Returns true if the object represents a namespace.
135
136
137
|
# File 'lib/inch/code_object/proxy/base.rb', line 135
def namespace?
false
end
|
#parent ⇒ Array?
Returns the parent of the current object or nil.
140
141
142
|
# File 'lib/inch/code_object/proxy/base.rb', line 140
def parent
Proxy.for(object.parent) if object.parent
end
|
#private? ⇒ Boolean
144
145
146
|
# File 'lib/inch/code_object/proxy/base.rb', line 144
def private?
visibility == :private
end
|
#private_api_tag? ⇒ Boolean
154
155
156
|
# File 'lib/inch/code_object/proxy/base.rb', line 154
def private_api_tag?
api_tag && api_tag.text == 'private'
end
|
#private_tag? ⇒ Boolean
Returns true if the object or its parent is tagged as @private.
150
151
152
|
# File 'lib/inch/code_object/proxy/base.rb', line 150
def private_tag?
!object.tag(:private).nil? || (parent && parent.private_tag?)
end
|
#protected? ⇒ Boolean
158
159
160
|
# File 'lib/inch/code_object/proxy/base.rb', line 158
def protected?
visibility == :protected
end
|
#public? ⇒ Boolean
162
163
164
|
# File 'lib/inch/code_object/proxy/base.rb', line 162
def public?
visibility == :public
end
|
Returns YARD tags that are not already covered by other wrapper methods.
173
174
175
176
177
|
# File 'lib/inch/code_object/proxy/base.rb', line 173
def unconsidered_tags
@unconsidered_tags ||= object.tags.reject do |tag|
CONSIDERED_YARD_TAGS.include?(tag.tag_name)
end
end
|
#undocumented? ⇒ Boolean
Returns true if the object has no documentation at all.
167
168
169
|
# File 'lib/inch/code_object/proxy/base.rb', line 167
def undocumented?
docstring.empty? && object.tags.empty?
end
|