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.

This is the base class for code object proxies. Code object proxies are via an attributes Hash and provide all methods necessary for the evaluation of its documentation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



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

def initialize(attributes = {})
  @attributes = attributes
end

Instance Attribute Details

#gradeSymbol

Returns:

  • (Symbol)


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

def grade
  @grade ||= Evaluation.new_grade_lists.find do |range|
    range.scores.include?(score)
  end.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



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

def object_lookup
  @object_lookup
end

Instance Method Details

#[](key) ⇒ Object

Returns the attribute for the given key

Parameters:

  • key (Symbol)


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

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

#alias?Boolean

Returns if the current object is an alias for something else.

Returns:

  • (Boolean)

    if the current object is an alias for something else



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

def alias?
  !aliased_object.nil?
end

#aliased_objectCodeObject::Proxy::Base

Returns the object the current object is an alias of.

Returns:



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

def aliased_object
  object_lookup.find(self[:aliased_object_fullname])
end

#api_tag?Boolean

Returns true if the object has an @api tag.

Returns:

  • (Boolean)

    true if the object has an @api tag



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

def api_tag?
  self[:api_tag?]
end

#childrenArray

Returns the children of the current object.

Returns:

  • (Array)

    the children of the current object



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

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



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

def constant?
  self[:constant?]
end

#core?Boolean

Returns:

  • (Boolean)


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

def core?
  self[:core?]
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?”

Returns:

  • (Fixnum)

    the depth of the object in terms of namespace



94
95
96
# File 'lib/inch/code_object/proxy/base.rb', line 94

def depth
  self[:depth]
end

#docstringDocstring

Returns:

  • (Docstring)


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

def docstring
  self[:docstring]
end

#evaluationEvaluation::Base

Returns:

  • (Evaluation::Base)


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

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



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

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

#filesObject



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

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”



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

def fullname
  self[:fullname]
end

#has_alias?Boolean

Returns:

  • (Boolean)


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

def has_alias?
  !self[:aliases_fullnames].empty?
end

#has_children?Boolean

Returns:

  • (Boolean)


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

def has_children?
  self[:has_children?]
end

#has_code_example?Boolean

Returns:

  • (Boolean)


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

def has_code_example?
  self[:has_code_example?]
end

#has_doc?Boolean

Returns:

  • (Boolean)


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

def has_doc?
  self[:has_doc?]
end

#has_multiple_code_examples?Boolean

Returns:

  • (Boolean)


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

def has_multiple_code_examples?
  self[:has_multiple_code_examples?]
end

#has_unconsidered_tags?Boolean

Returns:

  • (Boolean)


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

def has_unconsidered_tags?
  self[:has_unconsidered_tags?]
end

#in_root?Boolean

Returns:

  • (Boolean)


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

def in_root?
  self[:in_root?]
end

#inspectObject



237
238
239
# File 'lib/inch/code_object/proxy/base.rb', line 237

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

#marshal_dumpObject

Used to persist the code object



228
229
230
# File 'lib/inch/code_object/proxy/base.rb', line 228

def marshal_dump
  @attributes
end

#marshal_load(attributes) ⇒ Object

Used to load a persisted code object



233
234
235
# File 'lib/inch/code_object/proxy/base.rb', line 233

def marshal_load(attributes)
  @attributes = attributes
end

#method?Boolean

Returns true if the object represents a method.

Returns:

  • (Boolean)

    true if the object represents a method



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

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”



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

def name
  self[:name]
end

#namespace?Boolean

Returns true if the object represents a namespace.

Returns:

  • (Boolean)

    true if the object represents a namespace



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

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



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

def nodoc?
  self[:nodoc?]
end

#original_docstringObject



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

def original_docstring
  self[:original_docstring]
end

#parentCodeObject::Proxy::Base?

Returns the parent of the current object or nil.

Returns:



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

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

#private?Boolean

Returns:

  • (Boolean)


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

def private?
  self[:private?]
end

#protected?Boolean

Returns:

  • (Boolean)


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

def protected?
  self[:protected?]
end

#public?Boolean

Returns:

  • (Boolean)


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

def public?
  self[:public?]
end

#sourceObject



205
206
207
# File 'lib/inch/code_object/proxy/base.rb', line 205

def source
  self[:source]
end

#tagged_as_internal_api?Boolean

Returns true if the object or its parent is tagged as part of an internal api.

Returns:

  • (Boolean)

    true if the object or its parent is tagged as part of an internal api



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

def tagged_as_internal_api?
  self[:tagged_as_internal_api?]
end

#tagged_as_private?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



186
187
188
# File 'lib/inch/code_object/proxy/base.rb', line 186

def tagged_as_private?
  self[:tagged_as_private?]
end

#typeObject



209
210
211
# File 'lib/inch/code_object/proxy/base.rb', line 209

def type
  self.class.to_s.gsub(/Object$/, "")
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



219
220
221
# File 'lib/inch/code_object/proxy/base.rb', line 219

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



214
215
216
# File 'lib/inch/code_object/proxy/base.rb', line 214

def undocumented?
  self[:undocumented?]
end

#visibilityObject



223
224
225
# File 'lib/inch/code_object/proxy/base.rb', line 223

def visibility
  self[:visibility]
end