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)
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
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 26

def initialize(object)
  @object = object
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

#api_tagObject



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

def api_tag
  tag(:api) || (parent && parent.api_tag)
end

#api_tag?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 30

def api_tag?
  !api_tag.nil?
end

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

To be overridden

Returns:

See Also:



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

def child(name)
  nil
end

#childrenObject

To be overridden



52
53
54
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 52

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



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

def children_fullnames
  []
end

#core?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 58

def core?
  RUBY_CORE.include?(name.to_s)
end

#depth(i = 0) ⇒ Fixnum

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) (defaults to: 0)

    a counter for recursive method calls

Returns:

  • (Fixnum)

    the depth of the object in terms of namespace



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

def depth(i = 0)
  if parent
    parent.depth(i+1)
  else
    i
  end
end

#docstringDocstring

Returns:



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

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



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

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

#filesArray<Array(String, Fixnum)>

Returns all files declaring the object in the form of an Array of Arrays containing the filename and the line number of their declaration.

Examples:

files # => [["lib/inch.rb", 3],
             ["lib/inch/cli.rb", 1],
              ["lib/inch/version.rb", 1],

Returns:

  • (Array<Array(String, Fixnum)>)


77
78
79
80
81
82
83
84
85
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 77

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



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

def fullname
  object.path
end

#has_alias?Boolean

Returns:

  • (Boolean)


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

def has_alias?
  false
end

#has_children?Boolean

Returns:

  • (Boolean)


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

def has_children?
  !children.empty?
end

#has_code_example?Boolean

Returns:

  • (Boolean)


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

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

#has_doc?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 123

def has_doc?
  !docstring.empty?
end

#has_multiple_code_examples?Boolean

Returns:

  • (Boolean)


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

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)


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

def has_unconsidered_tags?
  !unconsidered_tags.empty?
end

#in_in_root?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/inch/code_object/provider/yard/object/base.rb', line 145

def in_in_root?
  depth == 1
end

#in_root?Boolean

Returns:

  • (Boolean)


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

def in_root?
  depth == 1
end

#inspectObject



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

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



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

def method?
  false
end

#nameObject



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

def name
  object.name
end

#namespace?Boolean

Returns true if the object represents a namespace.

Returns:

  • (Boolean)

    true if the object represents a namespace



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

def namespace?
  false
end

#parametersObject



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

def parameters
  []
end

#parentArray?

Returns the parent of the current object or nil.

Returns:

  • (Array, nil)

    the parent of the current object or nil



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

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

#private?Boolean

Returns:

  • (Boolean)


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

def private?
  visibility == :private
end

#private_api_tag?Boolean

Returns:

  • (Boolean)


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

def private_api_tag?
  api_tag && api_tag.text == 'private'
end

#private_tagObject



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

def private_tag
  tag(:private) || (parent && parent.private_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



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

def private_tag?
  !private_tag.nil?
end

#protected?Boolean

Returns:

  • (Boolean)


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

def protected?
  visibility == :protected
end

#public?Boolean

Returns:

  • (Boolean)


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

def public?
  visibility == :public
end

#unconsidered_tag_countObject



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

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



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

def undocumented?
  docstring.empty? && tags.empty?
end