Class: Inch::CodeObject::Provider::YARD::Object::MethodSignature

Inherits:
Struct
  • Object
show all
Defined in:
lib/inch/code_object/provider/yard/object/method_signature.rb

Overview

Utility class to describe (overloaded) method signatures

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, yard_tag = nil) ⇒ MethodSignature

Returns a new instance of MethodSignature.

Parameters:



12
13
14
15
16
17
# File 'lib/inch/code_object/provider/yard/object/method_signature.rb', line 12

def initialize(method, yard_tag = nil)
  @method = method
  @yard_tag = yard_tag
  @docstring =
    Provider::YARD::Docstring.new(relevant_object.docstring)
end

Instance Attribute Details

#docstringObject (readonly)

Returns the value of attribute docstring.



8
9
10
# File 'lib/inch/code_object/provider/yard/object/method_signature.rb', line 8

def docstring
  @docstring
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



7
8
9
# File 'lib/inch/code_object/provider/yard/object/method_signature.rb', line 7

def method
  @method
end

#yard_tagObject

Returns the value of attribute yard_tag

Returns:

  • (Object)

    the current value of yard_tag



7
8
9
# File 'lib/inch/code_object/provider/yard/object/method_signature.rb', line 7

def yard_tag
  @yard_tag
end

Instance Method Details

#all_signature_parameter_namesObject



19
20
21
# File 'lib/inch/code_object/provider/yard/object/method_signature.rb', line 19

def all_signature_parameter_names
  relevant_object.parameters.map(&:first)
end

#has_code_example?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/inch/code_object/provider/yard/object/method_signature.rb', line 23

def has_code_example?
  if docstring.contains_code_example?
    true
  else
    !relevant_object.tags(:example).empty?
  end
end

#has_doc?Boolean

Returns:

  • (Boolean)


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

def has_doc?
  !docstring.empty? && !implicit_docstring?
end

#parameter(name) ⇒ MethodParameterObject

Returns the parameter with the given name.

Parameters:

  • name (String, Symbol)

Returns:



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

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

#parametersObject



35
36
37
38
39
40
41
# File 'lib/inch/code_object/provider/yard/object/method_signature.rb', line 35

def parameters
  @parameters ||= all_parameter_names.map do |name|
    signature_name = in_signature(name)
    tag = parameter_tag(name) || parameter_tag(signature_name)
    MethodParameterObject.new(method, name, signature_name, tag)
  end
end

#same?(other) ⇒ Boolean

Returns true if the other signature is identical to self

Parameters:

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/inch/code_object/provider/yard/object/method_signature.rb', line 53

def same?(other)
  all_signature_parameter_names ==
    other.all_signature_parameter_names
end

#signatureString

Returns the actual signature of the method.

Returns:

  • (String)


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

def signature
  relevant_object.signature.gsub(/^(def\ )/, "")
end