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

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

Overview

This class is abstract.

Direct Known Subclasses

ConstantObject, MethodObject, NamespaceObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Base

Returns a new instance of Base.



23
24
25
# File 'lib/inch/code_object/proxy/base.rb', line 23

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#gradeSymbol

Returns:

  • (Symbol)


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

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

#object_lookup#find

Returns an object that responds to #find to look up objects by their full name.

Returns:

  • (#find)

    an object that responds to #find to look up objects by their full name



18
19
20
# File 'lib/inch/code_object/proxy/base.rb', line 18

def object_lookup
  @object_lookup
end

Instance Method Details

#[](key) ⇒ Object

Returns the attribute for the given key

Parameters:

  • key (Symbol)


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

def [](key)
  @attributes[key]
end

#api_tag?Boolean

Returns true if the object has an @api tag.

Returns:

  • (Boolean)

    true if the object has an @api tag



47
48
49
# File 'lib/inch/code_object/proxy/base.rb', line 47

def api_tag?
  self[:api_tag?]
end

#childrenArray

Returns the children of the current object.

Returns:

  • (Array)

    the children of the current object



52
53
54
55
56
# File 'lib/inch/code_object/proxy/base.rb', line 52

def children
  @children ||= self[:children_fullnames].map do |fullname|
    object_lookup.find(fullname)
  end
end

#constant?Boolean

Returns true if the object represents a constant.

Returns:

  • (Boolean)

    true if the object represents a constant



59
60
61
# File 'lib/inch/code_object/proxy/base.rb', line 59

def constant?
  self[:constant?]
end

#core?Boolean

Returns:

  • (Boolean)


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

def core?
  self[:api_tag?]
end

#depthFixnum

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)

    a counter for recursive method calls

Returns:

  • (Fixnum)

    the depth of the object in terms of namespace



80
81
82
# File 'lib/inch/code_object/proxy/base.rb', line 80

def depth
  self[:depth]
end

#docstringDocstring

Returns:

  • (Docstring)


85
86
87
# File 'lib/inch/code_object/proxy/base.rb', line 85

def docstring
  self[:docstring]
end

#evaluationEvaluation::Base

Returns:

  • (Evaluation::Base)


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

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

#filenameString

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

Returns:

  • (String)

    a filename



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

def filename
  # just checking the first file (which is the file where an object
  # is first declared)
  files.first
end

#filesObject



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

def files
  self[:files]
end

#fullnameString

Returns the fully qualified name of an object, e.g. “Inch::CodeObject::Provider::YARD::Docstring”.

Returns:

  • (String)

    the fully qualified name of an object, e.g. “Inch::CodeObject::Provider::YARD::Docstring”



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

def fullname
  self[:fullname]
end

#has_alias?Boolean

Returns:

  • (Boolean)


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

def has_alias?
  self[:has_alias?]
end

#has_children?Boolean

Returns:

  • (Boolean)


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

def has_children?
  self[:has_children?]
end

#has_code_example?Boolean

Returns:

  • (Boolean)


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

def has_code_example?
  self[:has_code_example?]
end

#has_doc?Boolean

Returns:

  • (Boolean)


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

def has_doc?
  self[:has_doc?]
end

#has_multiple_code_examples?Boolean

Returns:

  • (Boolean)


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

def has_multiple_code_examples?
  self[:has_multiple_code_examples?]
end

#has_unconsidered_tags?Boolean

Returns:

  • (Boolean)


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

def has_unconsidered_tags?
  self[:has_unconsidered_tags?]
end

#in_root?Boolean

Returns:

  • (Boolean)


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

def in_root?
  self[:in_root?]
end

#inspectObject



201
202
203
# File 'lib/inch/code_object/proxy/base.rb', line 201

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

#method?Boolean

Returns true if the object represents a method.

Returns:

  • (Boolean)

    true if the object represents a method



142
143
144
# File 'lib/inch/code_object/proxy/base.rb', line 142

def method?
  self[:method?]
end

#nameString

Returns the name of an object, e.g. “Docstring”.

Returns:

  • (String)

    the name of an object, e.g. “Docstring”



103
104
105
# File 'lib/inch/code_object/proxy/base.rb', line 103

def name
  self[:name]
end

#namespace?Boolean

Returns true if the object represents a namespace.

Returns:

  • (Boolean)

    true if the object represents a namespace



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

def namespace?
  self[:namespace?]
end

#nodoc?Boolean

Returns true if the object was tagged not to be documented.

Returns:

  • (Boolean)

    true if the object was tagged not to be documented



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

def nodoc?
  self[:nodoc?]
end

#parentArray?

Returns the parent of the current object or nil.

Returns:

  • (Array, nil)

    the parent of the current object or nil



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

def parent
  object_lookup.find( self[:parent_fullname] )
end

#private?Boolean

Returns:

  • (Boolean)


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

def private?
  self[:private?]
end

#private_api_tag?Boolean

Returns:

  • (Boolean)


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

def private_api_tag?
  self[:private_api_tag?]
end

#private_tag?Boolean

Returns true if the object or its parent is tagged as @private.

Returns:

  • (Boolean)

    true if the object or its parent is tagged as @private



167
168
169
# File 'lib/inch/code_object/proxy/base.rb', line 167

def private_tag?
  self[:private_tag?]
end

#protected?Boolean

Returns:

  • (Boolean)


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

def protected?
  self[:protected?]
end

#public?Boolean

Returns:

  • (Boolean)


179
180
181
# File 'lib/inch/code_object/proxy/base.rb', line 179

def public?
  self[:public?]
end

#sourceObject



183
184
185
# File 'lib/inch/code_object/proxy/base.rb', line 183

def source
  self[:source]
end

#unconsidered_tag_countFixnum

Returns the amount of tags not considered for this object.

Returns:

  • (Fixnum)

    the amount of tags not considered for this object



193
194
195
# File 'lib/inch/code_object/proxy/base.rb', line 193

def unconsidered_tag_count
  self[:unconsidered_tag_count]
end

#undocumented?Boolean

Returns true if the object has no documentation at all.

Returns:

  • (Boolean)

    true if the object has no documentation at all



188
189
190
# File 'lib/inch/code_object/proxy/base.rb', line 188

def undocumented?
  self[:undocumented?]
end

#visibilityObject



197
198
199
# File 'lib/inch/code_object/proxy/base.rb', line 197

def visibility
  self[:visibility]
end