Class: Inch::Language::Ruby::Provider::YARD::Object::MethodObject

Inherits:
Base
  • Object
show all
Defined in:
lib/inch/language/ruby/provider/yard/object/method_object.rb

Overview

Proxy class for methods

Constant Summary collapse

UNUSABLE_RETURN_VALUES =
%w(nil nothing undefined void)

Constants inherited from Base

Base::AUTO_GENERATED_TAG_NAMES, Base::CONSIDERED_YARD_TAGS, Base::RUBY_CORE

Constants included from NodocHelper

NodocHelper::DOC_REGEX, NodocHelper::NO_DOC_ALL_REGEX, NodocHelper::NO_DOC_REGEX

Instance Attribute Summary

Attributes inherited from Base

#aliased_object_fullname, #api_tag, #base_dir, #object, #parent

Instance Method Summary collapse

Methods inherited from Base

#__parent, #api_tag?, #child, #children, #children_fullnames, #core?, #depth, #docstring, #filename, #files, #fullname, #has_children?, #has_multiple_code_examples?, #has_unconsidered_tags?, #in_root?, #initialize, #inspect, #name, #namespace?, #original_docstring, #private?, #protected?, #public?, #tagged_as_internal_api?, #tagged_as_private?, #unconsidered_tag_count, #undocumented?

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

This class inherits a constructor from Inch::Language::Ruby::Provider::YARD::Object::Base

Instance Method Details

#aliases_fullnamesObject



13
14
15
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 13

def aliases_fullnames
  object.aliases.map(&:path)
end

#bang_name?Boolean

Returns:

  • (Boolean)


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

def bang_name?
  name =~ /\!$/
end

#constructor?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 21

def constructor?
  name == :initialize
end

#getter?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 25

def getter?
  attr_info = object.attr_info || {}
  read_info = attr_info[:read]
  if read_info
    read_info.path == fullname
  else
    parent.child(:"#{name}=")
  end
end

#has_code_example?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 35

def has_code_example?
  signatures.any? { |s| s.has_code_example? }
end

#has_doc?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 39

def has_doc?
  signatures.any? { |s| s.has_doc? }
end

#method?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 43

def method?
  true
end

#overridden?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 55

def overridden?
  !!object.overridden_method
end

#overridden_methodObject



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

def overridden_method
  return unless overridden?
  @overridden_method ||= YARD::Object.for(object.overridden_method)
end

#overridden_method_fullnameObject



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

def overridden_method_fullname
  return unless overridden?
  overridden_method.fullname
end

#parameter(name) ⇒ Object



51
52
53
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 51

def parameter(name)
  parameters.find { |p| p.name == name.to_s }
end

#parametersObject



47
48
49
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 47

def parameters
  @parameters ||= signatures.map(&:parameters).flatten
end

#questioning_name?Boolean

Returns:

  • (Boolean)


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

def questioning_name?
  name =~ /\?$/
end

#return_described?Boolean

Returns true if a return value is described by words.

Returns:

  • (Boolean)


79
80
81
82
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 79

def return_described?
  return_described_via_tag? ||
    docstring.describes_return? && !implicit_docstring?
end

#return_mentioned?Boolean

Returns true if a return value is described by it’s type or mentioned in the docstring (e.g. “Returns a String”).

Returns:

  • (Boolean)


71
72
73
74
75
76
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 71

def return_mentioned?
  return_tags.any? do |t|
    !t.types.nil? && !t.types.empty? &&
      !YARD.implicit_tag?(t, self)
  end || docstring.mentions_return? && !implicit_docstring?
end

#return_typed?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 84

def return_typed?
  return_mentioned?
end

#setter?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 88

def setter?
  name =~ /\=$/ && parameters.size == 1
end

#signaturesObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/inch/language/ruby/provider/yard/object/method_object.rb', line 92

def signatures
  base = MethodSignature.new(self, nil)
  overloaded = overload_tags.map do |tag|
    MethodSignature.new(self, tag)
  end
  if overloaded.any? { |s| s.same?(base) }
    overloaded
  else
    [base] + overloaded
  end
end