Class: Inch::CodeObject::Proxy::Base
- Inherits:
-
Object
- Object
- Inch::CodeObject::Proxy::Base
- Extended by:
- Forwardable
- Includes:
- NodocHelper
- Defined in:
- lib/inch/code_object/proxy/base.rb
Direct Known Subclasses
Constant Summary collapse
- CONSIDERED_YARD_TAGS =
Tags considered by wrapper methods like #has_code_example?
%w(example param private return)
Constants included from NodocHelper
NodocHelper::DOC_REGEX, NodocHelper::NO_DOC_ALL_REGEX, NodocHelper::NO_DOC_REGEX
Instance Attribute Summary collapse
- #grade ⇒ Object
-
#object ⇒ Object
the actual (YARD) code object.
Instance Method Summary collapse
-
#children ⇒ Array?
To be overridden.
-
#depth(i = 0) ⇒ Fixnum
The depth of the following is 4:.
- #docstring ⇒ Object
- #evaluation ⇒ Object
-
#filename ⇒ String
Returns the name of the file where the object is declared first.
- #has_alias? ⇒ Boolean
- #has_code_example? ⇒ Boolean
- #has_doc? ⇒ Boolean
- #has_multiple_code_examples? ⇒ Boolean
- #has_unconsidered_tags? ⇒ Boolean
-
#height(i = 0) ⇒ Fixnum
In the following example, the height of
Foo
is 3 (the height of the top-level is 4):. - #in_root? ⇒ Boolean
-
#initialize(object) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
-
#method? ⇒ Boolean
true
if the object represents a method. -
#namespace? ⇒ Boolean
true
if the object represents a namespace. -
#parent ⇒ Array?
The parent of the current object or
nil
. - #private? ⇒ Boolean
- #private_tag? ⇒ Boolean
- #protected? ⇒ Boolean
- #public? ⇒ Boolean
-
#unconsidered_tags ⇒ Array
YARD tags that are not already covered by other wrapper methods.
-
#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?, #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.
27 28 29 |
# File 'lib/inch/code_object/proxy/base.rb', line 27 def initialize(object) self.object = object end |
Instance Attribute Details
#grade ⇒ Object
54 55 56 57 58 |
# File 'lib/inch/code_object/proxy/base.rb', line 54 def grade @grade ||= Evaluation.new_score_ranges.detect { |range| range.range.include?(score) }.grade end |
#object ⇒ Object
the actual (YARD) code object
11 12 13 |
# File 'lib/inch/code_object/proxy/base.rb', line 11 def object @object end |
Instance Method Details
#children ⇒ Array?
To be overridden
34 35 36 |
# File 'lib/inch/code_object/proxy/base.rb', line 34 def children nil end |
#depth(i = 0) ⇒ 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?”
108 109 110 111 112 113 114 |
# File 'lib/inch/code_object/proxy/base.rb', line 108 def depth(i = 0) if parent parent.depth(i+1) else i end end |
#docstring ⇒ Object
38 39 40 |
# File 'lib/inch/code_object/proxy/base.rb', line 38 def docstring @docstring ||= Docstring.new(object.docstring) end |
#evaluation ⇒ Object
42 43 44 |
# File 'lib/inch/code_object/proxy/base.rb', line 42 def evaluation @evaluation ||= Evaluation.for(self) end |
#filename ⇒ String
Returns the name of the file where the object is declared first
48 49 50 51 52 |
# File 'lib/inch/code_object/proxy/base.rb', line 48 def filename # just checking the first file (which is the file where an object # is first declared) files.size > 0 ? files[0][0] : nil end |
#has_alias? ⇒ Boolean
60 61 62 |
# File 'lib/inch/code_object/proxy/base.rb', line 60 def has_alias? !object.aliases.empty? end |
#has_code_example? ⇒ Boolean
64 65 66 67 |
# File 'lib/inch/code_object/proxy/base.rb', line 64 def has_code_example? !object.(:example).empty? || docstring.contains_code_example? end |
#has_doc? ⇒ Boolean
69 70 71 |
# File 'lib/inch/code_object/proxy/base.rb', line 69 def has_doc? !docstring.empty? end |
#has_multiple_code_examples? ⇒ Boolean
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/inch/code_object/proxy/base.rb', line 73 def has_multiple_code_examples? if object.(: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 |
#has_unconsidered_tags? ⇒ Boolean
87 88 89 |
# File 'lib/inch/code_object/proxy/base.rb', line 87 def !.empty? end |
#height(i = 0) ⇒ Fixnum
In the following example, the height of Foo
is 3 (the height of the top-level is 4):
Foo::Bar::Baz#initialize
^ ^ ^ ^
0 >> 1 >> 2 >> 3
height
answers the question “how many layers of code objects are underneath this one?”
128 129 130 131 132 133 134 135 136 |
# File 'lib/inch/code_object/proxy/base.rb', line 128 def height(i = 0) if children && !children.empty? children.map do |child| child.height(i+1) end.max else i end end |
#in_root? ⇒ Boolean
91 92 93 |
# File 'lib/inch/code_object/proxy/base.rb', line 91 def in_root? depth == 1 end |
#inspect ⇒ Object
182 183 184 |
# File 'lib/inch/code_object/proxy/base.rb', line 182 def inspect "#<#{self.class.to_s}: #{path}>" end |
#method? ⇒ Boolean
Returns true
if the object represents a method.
139 140 141 |
# File 'lib/inch/code_object/proxy/base.rb', line 139 def method? false end |
#namespace? ⇒ Boolean
Returns true
if the object represents a namespace.
144 145 146 |
# File 'lib/inch/code_object/proxy/base.rb', line 144 def namespace? false end |
#parent ⇒ Array?
Returns the parent of the current object or nil
.
149 150 151 |
# File 'lib/inch/code_object/proxy/base.rb', line 149 def parent Proxy.for(object.parent) if object.parent end |
#private? ⇒ Boolean
153 154 155 |
# File 'lib/inch/code_object/proxy/base.rb', line 153 def private? visibility == :private end |
#private_tag? ⇒ Boolean
157 158 159 |
# File 'lib/inch/code_object/proxy/base.rb', line 157 def private_tag? !!object.tag(:private) end |
#protected? ⇒ Boolean
161 162 163 |
# File 'lib/inch/code_object/proxy/base.rb', line 161 def protected? visibility == :protected end |
#public? ⇒ Boolean
165 166 167 |
# File 'lib/inch/code_object/proxy/base.rb', line 165 def public? visibility == :public end |
#unconsidered_tags ⇒ Array
Returns YARD tags that are not already covered by other wrapper methods.
176 177 178 179 180 |
# File 'lib/inch/code_object/proxy/base.rb', line 176 def @unconsidered_tags ||= object..reject do |tag| CONSIDERED_YARD_TAGS.include?(tag.tag_name) end end |
#undocumented? ⇒ Boolean
Returns true
if the object has no documentation at all.
170 171 172 |
# File 'lib/inch/code_object/proxy/base.rb', line 170 def undocumented? docstring.empty? && object..empty? end |