Class: DuckTesting::YARD::MethodObject

Inherits:
CodeObject
  • Object
show all
Defined in:
lib/duck_testing/yard/method_object.rb

Overview

Encapsulate YARD::CodeObjects::MethodObject.

Instance Attribute Summary collapse

Attributes inherited from CodeObject

#path, #yard_object

Instance Method Summary collapse

Methods inherited from CodeObject

#initialize

Constructor Details

This class inherits a constructor from DuckTesting::YARD::CodeObject

Instance Attribute Details

#nameString (readonly)

Returns the name of the object.

Returns:

  • (String)


15
# File 'lib/duck_testing/yard/method_object.rb', line 15

def_delegators :@yard_object, "name", "scope"

#scopeSymbol (readonly)

Returns the scope of the object.

Returns:

  • (Symbol)


15
# File 'lib/duck_testing/yard/method_object.rb', line 15

def_delegators :@yard_object, "name", "scope"

Instance Method Details

#expected_return_typesArray<DuckTesting::Type::Base>

Returns:



53
54
55
# File 'lib/duck_testing/yard/method_object.rb', line 53

def expected_return_types
  return_tag ? DuckTesting::YARD.expected_types(return_tag.types) : []
end

#keyword_parametersArray<DuckTesting::YARD::MethodParameter>



43
44
45
# File 'lib/duck_testing/yard/method_object.rb', line 43

def keyword_parameters
  method_parameters.select(&:keyword?)
end

#method_parametersArray<DuckTesting::YARD::MethodParameter>



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/duck_testing/yard/method_object.rb', line 23

def method_parameters
  @method_parameters ||= begin
    if yard_object.parameters.any?
      yard_object.parameters.map do |name, default|
        MethodParameter.new(self, name, default, get_parameter_tag(name))
      end
    elsif parameter_tags.any?
      # Maybe the method is defined using a DSL and its signature is
      # declared with "@!method" directive.
      parameter_tags.map do |tag|
        MethodParameter.new(self, tag.name, nil, tag)
      end
    else
      # The method does not take any arguments.
      []
    end
  end
end

#public_class_method?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/duck_testing/yard/method_object.rb', line 63

def public_class_method?
  yard_object.scope == :class
end

#public_instance_method?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/duck_testing/yard/method_object.rb', line 58

def public_instance_method?
  yard_object.scope == :instance
end

#return_tagYARD::Tags::Tag

Returns:

  • (YARD::Tags::Tag)


48
49
50
# File 'lib/duck_testing/yard/method_object.rb', line 48

def return_tag
  @return_tag ||= yard_object.tags.find { |tag| tag.tag_name == "return" }
end

#signatureString

Returns:

  • (String)


18
19
20
# File 'lib/duck_testing/yard/method_object.rb', line 18

def signature
  "#{name}(#{parameters_signature})"
end