Class: Inch::Language::Ruby::Provider::YARD::Object::Base Abstract

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

Overview

This class is abstract.

Constant Summary collapse

CONSIDERED_YARD_TAGS =

Tags considered by wrapper methods like #has_code_example?

%w(api example param private return since)
AUTO_GENERATED_TAG_NAMES =
%w(raise yield)
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

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



32
33
34
35
36
37
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 32

def initialize(object)
  @object = object
  @api_tag = __api_tag
  @parent = __parent
  @private_tag = __private_tag
end

Instance Attribute Details

#aliased_object_fullnameObject

Returns the fullname of the object that the current object is an alias for



41
42
43
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 41

def aliased_object_fullname
  @aliased_object_fullname
end

#api_tagObject (readonly)

Returns the value of attribute api_tag



53
54
55
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 53

def api_tag
  @api_tag
end

#base_dirString

Returns the codebase's directory

Returns:

  • (String)

    the codebase's directory



19
20
21
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 19

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



16
17
18
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 16

def object
  @object
end

#parentArray? (readonly)

Returns the parent of the current object or nil

Returns:

  • (Array, nil)

    the parent of the current object or nil



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

def parent
  @parent
end

Instance Method Details

#__parentObject



212
213
214
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 212

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

#aliases_fullnamesObject

Returns the fullnames of the objects that are aliases for the current object



45
46
47
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 45

def aliases_fullnames
  []
end

#api_tag?Boolean

Returns:

  • (Boolean)


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

def api_tag?
  !api_tag.nil?
end

#child(_name) ⇒ CodeObject::Proxy?

To be overridden

Returns:

See Also:

  • Proxy::NamespaceObject


59
60
61
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 59

def child(_name)
  nil
end

#childrenObject

To be overridden

See Also:

  • Proxy::NamespaceObject


71
72
73
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 71

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



65
66
67
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 65

def children_fullnames
  []
end

#core?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 100

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



186
187
188
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 186

def depth
  @__depth ||= __depth
end

#docstringDocstring

Returns:



105
106
107
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 105

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



125
126
127
128
129
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 125

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:

  • (Array<CodeLocation>)


113
114
115
116
117
118
119
120
121
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 113

def files
  object.files.map do |(filename, line_no)|
    Inch::Utils::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



131
132
133
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 131

def fullname
  @fullname ||= object.path
end

#has_children?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 139

def has_children?
  !children.empty?
end

#has_code_example?Boolean

Returns:

  • (Boolean)


143
144
145
146
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 143

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

#has_doc?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 148

def has_doc?
  !docstring.empty?
end

#has_multiple_code_examples?Boolean

Returns:

  • (Boolean)


152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 152

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)


166
167
168
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 166

def has_unconsidered_tags?
  !unconsidered_tags.empty?
end

#in_root?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 170

def in_root?
  depth == 1
end

#inspectObject



250
251
252
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 250

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

#method?Boolean

Returns true if the object represents a method

Returns:

  • (Boolean)

    true if the object represents a method



191
192
193
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 191

def method?
  false
end

#nameObject



135
136
137
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 135

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



196
197
198
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 196

def namespace?
  false
end

#original_docstringString

Returns the documentation comments

Returns:

  • (String)

    the documentation comments



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

def original_docstring
  object.docstring.all.to_s
end

#parametersObject



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

def parameters
  []
end

#private?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 216

def private?
  visibility == :private
end

#protected?Boolean

Returns:

  • (Boolean)


228
229
230
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 228

def protected?
  visibility == :protected
end

#public?Boolean

Returns:

  • (Boolean)


232
233
234
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 232

def public?
  visibility == :public
end

#tagged_as_internal_api?Boolean

Returns:

  • (Boolean)


220
221
222
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 220

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

#tagged_as_private?Boolean

Returns:

  • (Boolean)


224
225
226
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 224

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

#unconsidered_tag_countObject



246
247
248
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 246

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



242
243
244
# File 'lib/inch/language/ruby/provider/yard/object/base.rb', line 242

def undocumented?
  original_docstring.empty?
end