Class: Inch::CodeObject::Proxy::MethodParameterObject

Inherits:
Object
  • Object
show all
Defined in:
lib/inch/code_object/proxy/method_parameter_object.rb

Constant Summary collapse

BAD_NAME_EXCEPTIONS =
%w(id)
BAD_NAME_THRESHOLD =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, name, tag, in_signature) ⇒ MethodParameterObject

Returns a new instance of MethodParameterObject.

Parameters:

  • method (Inch::CodeObject::Proxy::MethodObject)

    the method the parameter belongs_to

  • name (String)

    the name of the parameter

  • tag (YARD::Tags::Tag)

    the Tag object for the parameter

  • in_signature (Boolean)

    true if the method’s signature contains the parameter



11
12
13
14
15
16
# File 'lib/inch/code_object/proxy/method_parameter_object.rb', line 11

def initialize(method, name, tag, in_signature)
  @method = method
  @name = name
  @tag = tag
  @in_signature = in_signature
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/inch/code_object/proxy/method_parameter_object.rb', line 5

def name
  @name
end

Instance Method Details

#bad_name?Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/inch/code_object/proxy/method_parameter_object.rb', line 20

def bad_name?
  return false if BAD_NAME_EXCEPTIONS.include?(name)
  name.size < BAD_NAME_THRESHOLD || name =~ /[0-9]$/
end

#block?Boolean

Returns true if the parameter is a block.

Returns:

  • (Boolean)

    true if the parameter is a block



26
27
28
# File 'lib/inch/code_object/proxy/method_parameter_object.rb', line 26

def block?
  name =~ /^\&/
end

#described?Boolean

Returns true if an additional description given?.

Returns:

  • (Boolean)

    true if an additional description given?



31
32
33
# File 'lib/inch/code_object/proxy/method_parameter_object.rb', line 31

def described?
  described_by_tag? || described_by_docstring?
end

#mentioned?Boolean

Returns true if the parameter is mentioned in the docs.

Returns:

  • (Boolean)

    true if the parameter is mentioned in the docs



36
37
38
# File 'lib/inch/code_object/proxy/method_parameter_object.rb', line 36

def mentioned?
  !!@tag || mentioned_by_docstring?
end

#splat?Boolean

Returns true if the parameter is a splat argument.

Returns:

  • (Boolean)

    true if the parameter is a splat argument



41
42
43
# File 'lib/inch/code_object/proxy/method_parameter_object.rb', line 41

def splat?
  name =~ /^\*/
end

#typed?Boolean

Returns true if the type of the parameter is defined.

Returns:

  • (Boolean)

    true if the type of the parameter is defined



46
47
48
# File 'lib/inch/code_object/proxy/method_parameter_object.rb', line 46

def typed?
  @tag && @tag.types && !@tag.types.empty?
end

#wrongly_mentioned?Boolean

Returns true if the parameter is mentioned in the docs, but not present in the method’s signature.

Returns:

  • (Boolean)

    true if the parameter is mentioned in the docs, but not present in the method’s signature



51
52
53
# File 'lib/inch/code_object/proxy/method_parameter_object.rb', line 51

def wrongly_mentioned?
  mentioned? && !@in_signature
end