Class: Inch::CodeObject::Provider::YARD::Object::Base Abstract

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

Overview

This class is abstract.

Direct Known Subclasses

ConstantObject, MethodObject, NamespaceObject

Defined Under Namespace

Classes: CodeLocation

Constant Summary collapse

CONSIDERED_YARD_TAGS =

Tags considered by wrapper methods like #has_code_example?

%w(api example param private return since)
RUBY_CORE =
%w(Array Bignum BasicObject Object Module Class Complex NilClass Numeric String Float Fiber FiberError Continuation Dir File Encoding Enumerator StopIteration Enumerator::Generator Enumerator::Yielder Exception SystemExit SignalException Interrupt StandardError TypeError ArgumentError IndexError KeyError RangeError ScriptError SyntaxError LoadError NotImplementedError NameError NoMethodError RuntimeError SecurityError NoMemoryError EncodingError SystemCallError Encoding::CompatibilityError File::Stat IO Hash ENV IOError EOFError ARGF RubyVM RubyVM::InstructionSequence Math::DomainError ZeroDivisionError FloatDomainError Integer Fixnum Data TrueClass FalseClass Mutex Thread Proc LocalJumpError SystemStackError Method UnboundMethod Binding Process::Status Random Range Rational RegexpError Regexp MatchData Symbol Struct ThreadGroup ThreadError Time Encoding::UndefinedConversionError Encoding::InvalidByteSequenceError Encoding::ConverterNotFoundError Encoding::Converter RubyVM::Env) +
%w(Comparable Kernel File::Constants Enumerable Errno FileTest GC ObjectSpace GC::Profiler IO::WaitReadable IO::WaitWritable Marshal Math Process Process::UID Process::GID Process::Sys Signal)

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?, #get_line_no, #implicit_nodoc_all_comment?, #implicit_nodoc_comment?, #nodoc?, #nodoc_comment?

Constructor Details

#initialize(object) ⇒ Base

Returns a new instance of Base.

Parameters:

  • object (YARD::CodeObjects::Base)

    the actual (YARD) code object



26
27
28
29
30
31
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 26

def initialize(object)
  @object = object
  @__api_tag = __api_tag
  @__parent = __parent
  @__private_tag = __private_tag
end

Instance Attribute Details

#base_dirString

Returns the codebase’s directory.

Returns:

  • (String)

    the codebase’s directory



17
18
19
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 17

def base_dir
  @base_dir
end

#objectYARD::CodeObjects::Base (readonly)

Returns the actual (YARD) code object.

Returns:

  • (YARD::CodeObjects::Base)

    the actual (YARD) code object



14
15
16
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 14

def object
  @object
end

Instance Method Details

#__parentObject



181
182
183
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 181

def __parent
  YARD::Object.for(object.parent) if object.parent
end

#api_tagObject



37
38
39
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 37

def api_tag
  @__api_tag
end

#api_tag?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 33

def api_tag?
  !api_tag.nil?
end

#child(name) ⇒ CodeObject::Proxy::Base?

To be overridden

Returns:

See Also:



44
45
46
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 44

def child(name)
  nil
end

#childrenObject

To be overridden



55
56
57
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 55

def children
  []
end

#children_fullnamesArray?

Returns the full names of the children of the current object.

Returns:

  • (Array, nil)

    the full names of the children of the current object



49
50
51
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 49

def children_fullnames
  []
end

#core?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 61

def core?
  RUBY_CORE.include?(name.to_s)
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



158
159
160
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 158

def depth
  @__depth ||= __depth
end

#docstringDocstring

Returns:



66
67
68
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 66

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

#filenameString

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

Returns:

  • (String)

    a filename



93
94
95
96
97
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 93

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

#filesArray<CodeLocation>

Returns all files declaring the object in the form of an Array of Arrays containing the location of their declaration.

Returns:



74
75
76
77
78
79
80
81
82
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 74

def files
  object.files.map do |(filename, line_no)|
    CodeLocation.new(base_dir, filename, line_no)
  end
rescue ::YARD::CodeObjects::ProxyMethodError
  # this error is raised by YARD
  # see broken.rb in test fixtures
  []
end

#fullnameObject



99
100
101
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 99

def fullname
  @fullname ||= object.path
end

#has_alias?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 107

def has_alias?
  false
end

#has_children?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 111

def has_children?
  !children.empty?
end

#has_code_example?Boolean

Returns:

  • (Boolean)


115
116
117
118
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 115

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

#has_doc?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 120

def has_doc?
  !docstring.empty?
end

#has_multiple_code_examples?Boolean

Returns:

  • (Boolean)


124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 124

def has_multiple_code_examples?
  if tags(:example).size > 1 || docstring.code_examples.size > 1
    true
  else
    if tag = 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)


138
139
140
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 138

def has_unconsidered_tags?
  !unconsidered_tags.empty?
end

#in_in_root?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 142

def in_in_root?
  depth == 1
end

#in_root?Boolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 205

def in_root?
  depth == 1
end

#inspectObject



218
219
220
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 218

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



163
164
165
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 163

def method?
  false
end

#nameObject



103
104
105
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 103

def name
  @name ||= object.name
end

#namespace?Boolean

Returns true if the object represents a namespace.

Returns:

  • (Boolean)

    true if the object represents a namespace



168
169
170
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 168

def namespace?
  false
end

#parametersObject



172
173
174
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 172

def parameters
  []
end

#parentArray?

Returns the parent of the current object or nil.

Returns:

  • (Array, nil)

    the parent of the current object or nil



177
178
179
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 177

def parent
  @__parent
end

#private?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 185

def private?
  visibility == :private
end

#protected?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 197

def protected?
  visibility == :protected
end

#public?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 201

def public?
  visibility == :public
end

#tagged_as_internal_api?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 189

def tagged_as_internal_api?
  private_api_tag? || docstring.describes_internal_api?
end

#tagged_as_private?Boolean

Returns:

  • (Boolean)


193
194
195
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 193

def tagged_as_private?
  private_tag? || docstring.describes_private_object?
end

#unconsidered_tag_countObject



214
215
216
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 214

def unconsidered_tag_count
  unconsidered_tags.size
end

#undocumented?Boolean

Returns true if the object has no documentation at all.

Returns:

  • (Boolean)

    true if the object has no documentation at all



210
211
212
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 210

def undocumented?
  original_docstring.empty?
end