Class: Inch::CodeObject::Proxy::Base Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
NodocHelper
Defined in:
lib/inch/code_object/proxy/base.rb

Overview

This class is abstract.

Direct Known Subclasses

ConstantObject, MethodObject, NamespaceObject

Constant Summary collapse

CONSIDERED_YARD_TAGS =

Tags considered by wrapper methods like #has_code_example?

%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

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



29
30
31
# File 'lib/inch/code_object/proxy/base.rb', line 29

def initialize(object)
  self.object = object
end

Instance Attribute Details

#gradeSymbol



63
64
65
66
67
# File 'lib/inch/code_object/proxy/base.rb', line 63

def grade
  @grade ||= Evaluation.new_score_ranges.detect { |range|
        range.range.include?(score)
      }.grade
end

#objectYARD::CodeObjects::Base



12
13
14
# File 'lib/inch/code_object/proxy/base.rb', line 12

def object
  @object
end

Instance Method Details

#api_tag?Boolean



33
34
35
# File 'lib/inch/code_object/proxy/base.rb', line 33

def api_tag?
  !object.tag(:api).nil? || (parent && parent.api_tag?)
end

#childrenArray?

To be overridden

See Also:



40
41
42
# File 'lib/inch/code_object/proxy/base.rb', line 40

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#initialize
 ^    ^    ^      ^
 1 << 2 << 3  <<  4

depth answers the question “how many layers of code objects are above this one?”



117
118
119
120
121
122
123
# File 'lib/inch/code_object/proxy/base.rb', line 117

def depth(i = 0)
  if parent
    parent.depth(i+1)
  else
    i
  end
end

#docstringDocstring



45
46
47
# File 'lib/inch/code_object/proxy/base.rb', line 45

def docstring
  @docstring ||= Docstring.new(object.docstring)
end

#evaluationEvaluation::Base



50
51
52
# File 'lib/inch/code_object/proxy/base.rb', line 50

def evaluation
  @evaluation ||= Evaluation.for(self)
end

#filenameString

Returns the name of the file where the object is declared first



56
57
58
59
60
# File 'lib/inch/code_object/proxy/base.rb', line 56

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



69
70
71
# File 'lib/inch/code_object/proxy/base.rb', line 69

def has_alias?
  !object.aliases.empty?
end

#has_code_example?Boolean



73
74
75
76
# File 'lib/inch/code_object/proxy/base.rb', line 73

def has_code_example?
  !object.tags(:example).empty? ||
    docstring.contains_code_example?
end

#has_doc?Boolean



78
79
80
# File 'lib/inch/code_object/proxy/base.rb', line 78

def has_doc?
  !docstring.empty?
end

#has_multiple_code_examples?Boolean



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/inch/code_object/proxy/base.rb', line 82

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

#has_unconsidered_tags?Boolean



96
97
98
# File 'lib/inch/code_object/proxy/base.rb', line 96

def has_unconsidered_tags?
  !unconsidered_tags.empty?
end

#in_root?Boolean



100
101
102
# File 'lib/inch/code_object/proxy/base.rb', line 100

def in_root?
  depth == 1
end

#inspectObject



176
177
178
# File 'lib/inch/code_object/proxy/base.rb', line 176

def inspect
  "#<#{self.class.to_s}: #{path}>"
end

#method?Boolean



126
127
128
# File 'lib/inch/code_object/proxy/base.rb', line 126

def method?
  false
end

#namespace?Boolean



131
132
133
# File 'lib/inch/code_object/proxy/base.rb', line 131

def namespace?
  false
end

#parentArray?



136
137
138
# File 'lib/inch/code_object/proxy/base.rb', line 136

def parent
  Proxy.for(object.parent) if object.parent
end

#private?Boolean



140
141
142
# File 'lib/inch/code_object/proxy/base.rb', line 140

def private?
  visibility == :private
end

#private_api_tag?Boolean



150
151
152
153
# File 'lib/inch/code_object/proxy/base.rb', line 150

def private_api_tag?
  tag = object.tag(:api)
  tag.text == 'private'
end

#private_tag?Boolean



146
147
148
# File 'lib/inch/code_object/proxy/base.rb', line 146

def private_tag?
  !object.tag(:private).nil? || (parent && parent.private_tag?)
end

#protected?Boolean



155
156
157
# File 'lib/inch/code_object/proxy/base.rb', line 155

def protected?
  visibility == :protected
end

#public?Boolean



159
160
161
# File 'lib/inch/code_object/proxy/base.rb', line 159

def public?
  visibility == :public
end

#unconsidered_tagsArray



170
171
172
173
174
# File 'lib/inch/code_object/proxy/base.rb', line 170

def unconsidered_tags
  @unconsidered_tags ||= object.tags.reject do |tag|
      CONSIDERED_YARD_TAGS.include?(tag.tag_name)
    end
end

#undocumented?Boolean



164
165
166
# File 'lib/inch/code_object/proxy/base.rb', line 164

def undocumented?
  docstring.empty? && object.tags.empty?
end