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.

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.



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



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:



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

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



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

def api_tag?
  self[:api_tag?]
end

#childrenArray

Returns the children of the current object.

Returns:

  • (Array)

    the children of the current object



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

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



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

def constant?
  self[:constant?]
end

#core?Boolean

Returns:

  • (Boolean)


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

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



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

def depth
  self[:depth]
end

#docstringDocstring

Returns:

  • (Docstring)


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

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



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

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

#filesObject



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

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”



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

def fullname
  self[:fullname]
end

#has_alias?Boolean

Returns:

  • (Boolean)


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

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

#has_children?Boolean

Returns:

  • (Boolean)


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

def has_children?
  self[:has_children?]
end

#has_code_example?Boolean

Returns:

  • (Boolean)


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

def has_code_example?
  self[:has_code_example?]
end

#has_doc?Boolean

Returns:

  • (Boolean)


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

def has_doc?
  self[:has_doc?]
end

#has_multiple_code_examples?Boolean

Returns:

  • (Boolean)


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

def has_multiple_code_examples?
  self[:has_multiple_code_examples?]
end

#has_unconsidered_tags?Boolean

Returns:

  • (Boolean)


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

def has_unconsidered_tags?
  self[:has_unconsidered_tags?]
end

#in_root?Boolean

Returns:

  • (Boolean)


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

def in_root?
  self[:in_root?]
end

#inspectObject



235
236
237
# File 'lib/inch/code_object/proxy/base.rb', line 235

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

#marshal_dumpObject

Used to persist the code object



226
227
228
# File 'lib/inch/code_object/proxy/base.rb', line 226

def marshal_dump
  @attributes
end

#marshal_load(attributes) ⇒ Object

Used to load a persisted code object



231
232
233
# File 'lib/inch/code_object/proxy/base.rb', line 231

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



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

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”



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

def name
  self[:name]
end

#namespace?Boolean

Returns true if the object represents a namespace.

Returns:

  • (Boolean)

    true if the object represents a namespace



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

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



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

def nodoc?
  self[:nodoc?]
end

#original_docstringObject



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

def original_docstring
  self[:original_docstring]
end

#parentCodeObject::Proxy::Base?

Returns the parent of the current object or nil.

Returns:



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

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

#private?Boolean

Returns:

  • (Boolean)


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

def private?
  self[:private?]
end

#protected?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/inch/code_object/proxy/base.rb', line 195

def protected?
  self[:protected?]
end

#public?Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/inch/code_object/proxy/base.rb', line 199

def public?
  self[:public?]
end

#sourceObject



203
204
205
# File 'lib/inch/code_object/proxy/base.rb', line 203

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



191
192
193
# File 'lib/inch/code_object/proxy/base.rb', line 191

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



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

def tagged_as_private?
  self[:tagged_as_private?]
end

#typeObject



207
208
209
# File 'lib/inch/code_object/proxy/base.rb', line 207

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



217
218
219
# File 'lib/inch/code_object/proxy/base.rb', line 217

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



212
213
214
# File 'lib/inch/code_object/proxy/base.rb', line 212

def undocumented?
  self[:undocumented?]
end

#visibilityObject



221
222
223
# File 'lib/inch/code_object/proxy/base.rb', line 221

def visibility
  self[:visibility]
end