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(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

Returns a new instance of Base.



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

def initialize(object)
  self.object = object
end

Instance Attribute Details

#gradeObject



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

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

#objectObject

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

#childrenArray?

To be overridden

Returns:

  • (Array, nil)

    the children of the current object or nil

See Also:



35
36
37
# File 'lib/inch/code_object/proxy/base.rb', line 35

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?”

Parameters:

  • i (Fixnum) (defaults to: 0)

    a counter for recursive method calls

Returns:

  • (Fixnum)

    the depth of the object in terms of namespace



109
110
111
112
113
114
115
# File 'lib/inch/code_object/proxy/base.rb', line 109

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

#docstringObject



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

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

#evaluationObject



43
44
45
# File 'lib/inch/code_object/proxy/base.rb', line 43

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

#filenameString

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

Returns:

  • (String)

    a filename



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

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

Returns:

  • (Boolean)


61
62
63
# File 'lib/inch/code_object/proxy/base.rb', line 61

def has_alias?
  !object.aliases.empty?
end

#has_code_example?Boolean

Returns:

  • (Boolean)


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

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

#has_doc?Boolean

Returns:

  • (Boolean)


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

def has_doc?
  !docstring.empty?
end

#has_multiple_code_examples?Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/inch/code_object/proxy/base.rb', line 74

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

Returns:

  • (Boolean)


88
89
90
# File 'lib/inch/code_object/proxy/base.rb', line 88

def has_unconsidered_tags?
  !unconsidered_tags.empty?
end

#in_root?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/inch/code_object/proxy/base.rb', line 92

def in_root?
  depth == 1
end

#inspectObject



161
162
163
# File 'lib/inch/code_object/proxy/base.rb', line 161

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

#method?Boolean

Returns true if the object represents a method.

Returns:

  • (Boolean)

    true if the object represents a method



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

def method?
  false
end

#namespace?Boolean

Returns true if the object represents a namespace.

Returns:

  • (Boolean)

    true if the object represents a namespace



123
124
125
# File 'lib/inch/code_object/proxy/base.rb', line 123

def namespace?
  false
end

#parentArray?

Returns the parent of the current object or nil.

Returns:

  • (Array, nil)

    the parent of the current object or nil



128
129
130
# File 'lib/inch/code_object/proxy/base.rb', line 128

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

#private?Boolean

Returns:

  • (Boolean)


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

def private?
  visibility == :private
end

#private_tag?Boolean

Returns:

  • (Boolean)


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

def private_tag?
  !!object.tag(:private)
end

#protected?Boolean

Returns:

  • (Boolean)


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

def protected?
  visibility == :protected
end

#public?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/inch/code_object/proxy/base.rb', line 144

def public?
  visibility == :public
end

#unconsidered_tagsArray

Returns YARD tags that are not already covered by other wrapper methods.

Returns:

  • (Array)

    YARD tags that are not already covered by other wrapper methods



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

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.

Returns:

  • (Boolean)

    true if the object has no documentation at all



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

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