Merge pull request #125 from whopper/PDOC-135/4x_dispatch_return_type

(PDOC-135) Detect `return_type` calls in 4.x function dispatches
This commit is contained in:
Jesse Scott 2016-11-14 11:37:05 -08:00 committed by GitHub
commit df8e58b0c8
4 changed files with 16 additions and 8 deletions

View File

@ -15,6 +15,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
block_param block_param
required_block_param required_block_param
optional_block_param optional_block_param
return_type
).freeze ).freeze
namespace_only namespace_only
@ -133,6 +134,11 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
method_name = child.method_name.source method_name = child.method_name.source
next unless DISPATCH_METHOD_NAMES.include?(method_name) next unless DISPATCH_METHOD_NAMES.include?(method_name)
if method_name == 'return_type'
overload_tag.tag(:return).types = [node_as_string(child.parameters[0])]
next
end
# Check for block # Check for block
if method_name.include?('block') if method_name.include?('block')
if block if block

View File

@ -84,7 +84,7 @@
{ {
"name": "database", "name": "database",
"file": "(stdin)", "file": "(stdin)",
"line": 44, "line": 46,
"docstring": { "docstring": {
"text": "An example database server resource type." "text": "An example database server resource type."
}, },
@ -154,7 +154,7 @@
"name": "linux", "name": "linux",
"type_name": "database", "type_name": "database",
"file": "(stdin)", "file": "(stdin)",
"line": 33, "line": 35,
"docstring": { "docstring": {
"text": "An example provider on Linux." "text": "An example provider on Linux."
}, },
@ -357,7 +357,7 @@
} }
] ]
}, },
"source": "Puppet::Functions.create_function(:func4x) do\n # The first overload.\n # @param param1 The first parameter.\n # @param param2 The second parameter.\n # @param param3 The third parameter.\n # @return [Undef] Returns nothing.\n dispatch :foo do\n param 'Integer', :param1\n param 'Any', :param2\n optional_param 'Array[String]', :param3\n end\n\n # The second overload.\n # @param param The first parameter.\n # @param block The block parameter.\n # @return [String] Returns a string.\n dispatch :other do\n param 'Boolean', :param\n block_param\n end\nend" "source": "Puppet::Functions.create_function(:func4x) do\n # The first overload.\n # @param param1 The first parameter.\n # @param param2 The second parameter.\n # @param param3 The third parameter.\n # @return Returns nothing.\n dispatch :foo do\n param 'Integer', :param1\n param 'Any', :param2\n optional_param 'Array[String]', :param3\n return_type 'Undef'\n end\n\n # The second overload.\n # @param param The first parameter.\n # @param block The block parameter.\n # @return Returns a string.\n dispatch :other do\n param 'Boolean', :param\n block_param\n return_type 'String'\n end\nend"
} }
] ]
} }

View File

@ -84,7 +84,7 @@
{ {
"name": "database", "name": "database",
"file": "(stdin)", "file": "(stdin)",
"line": 44, "line": 46,
"docstring": { "docstring": {
"text": "An example database server resource type." "text": "An example database server resource type."
}, },
@ -154,7 +154,7 @@
"name": "linux", "name": "linux",
"type_name": "database", "type_name": "database",
"file": "(stdin)", "file": "(stdin)",
"line": 33, "line": 35,
"docstring": { "docstring": {
"text": "An example provider on Linux." "text": "An example provider on Linux."
}, },
@ -310,7 +310,7 @@
} }
] ]
}, },
"source": "Puppet::Functions.create_function(:func4x) do\n # The first overload.\n # @param param1 The first parameter.\n # @param param2 The second parameter.\n # @param param3 The third parameter.\n # @return [Undef] Returns nothing.\n dispatch :foo do\n param 'Integer', :param1\n param 'Any', :param2\n optional_param 'Array[String]', :param3\n end\n\n # The second overload.\n # @param param The first parameter.\n # @param block The block parameter.\n # @return [String] Returns a string.\n dispatch :other do\n param 'Boolean', :param\n block_param\n end\nend" "source": "Puppet::Functions.create_function(:func4x) do\n # The first overload.\n # @param param1 The first parameter.\n # @param param2 The second parameter.\n # @param param3 The third parameter.\n # @return Returns nothing.\n dispatch :foo do\n param 'Integer', :param1\n param 'Any', :param2\n optional_param 'Array[String]', :param3\n return_type 'Undef'\n end\n\n # The second overload.\n # @param param The first parameter.\n # @param block The block parameter.\n # @return Returns a string.\n dispatch :other do\n param 'Boolean', :param\n block_param\n return_type 'String'\n end\nend"
} }
] ]
} }

View File

@ -48,20 +48,22 @@ Puppet::Functions.create_function(:func4x) do
# @param param1 The first parameter. # @param param1 The first parameter.
# @param param2 The second parameter. # @param param2 The second parameter.
# @param param3 The third parameter. # @param param3 The third parameter.
# @return [Undef] Returns nothing. # @return Returns nothing.
dispatch :foo do dispatch :foo do
param 'Integer', :param1 param 'Integer', :param1
param 'Any', :param2 param 'Any', :param2
optional_param 'Array[String]', :param3 optional_param 'Array[String]', :param3
return_type 'Undef'
end end
# The second overload. # The second overload.
# @param param The first parameter. # @param param The first parameter.
# @param block The block parameter. # @param block The block parameter.
# @return [String] Returns a string. # @return Returns a string.
dispatch :other do dispatch :other do
param 'Boolean', :param param 'Boolean', :param
block_param block_param
return_type 'String'
end end
end end