puppet-strings 2.2.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +87 -1
- data/CONTRIBUTING.md +32 -2
- data/README.md +81 -17
- data/lib/puppet-strings.rb +5 -3
- data/lib/puppet-strings/describe.rb +2 -0
- data/lib/puppet-strings/json.rb +4 -0
- data/lib/puppet-strings/markdown.rb +13 -9
- data/lib/puppet-strings/markdown/base.rb +30 -3
- data/lib/puppet-strings/markdown/data_type.rb +36 -0
- data/lib/puppet-strings/markdown/data_types.rb +43 -0
- data/lib/puppet-strings/markdown/defined_type.rb +2 -0
- data/lib/puppet-strings/markdown/defined_types.rb +3 -1
- data/lib/puppet-strings/markdown/function.rb +9 -7
- data/lib/puppet-strings/markdown/functions.rb +3 -1
- data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
- data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
- data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
- data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
- data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
- data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
- data/lib/puppet-strings/markdown/resource_type.rb +21 -2
- data/lib/puppet-strings/markdown/resource_types.rb +3 -1
- data/lib/puppet-strings/markdown/table_of_contents.rb +4 -1
- data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +18 -6
- data/lib/puppet-strings/markdown/templates/data_type.erb +101 -0
- data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
- data/lib/puppet-strings/markdown/templates/function.erb +10 -1
- data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
- data/lib/puppet-strings/markdown/templates/resource_type.erb +35 -13
- data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
- data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
- data/lib/puppet-strings/tasks.rb +2 -0
- data/lib/puppet-strings/tasks/generate.rb +5 -2
- data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
- data/lib/puppet-strings/version.rb +3 -1
- data/lib/puppet-strings/yard.rb +19 -0
- data/lib/puppet-strings/yard/code_objects.rb +4 -0
- data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
- data/lib/puppet-strings/yard/code_objects/class.rb +5 -3
- data/lib/puppet-strings/yard/code_objects/data_type.rb +102 -0
- data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +60 -0
- data/lib/puppet-strings/yard/code_objects/defined_type.rb +5 -3
- data/lib/puppet-strings/yard/code_objects/function.rb +9 -6
- data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
- data/lib/puppet-strings/yard/code_objects/plan.rb +5 -3
- data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
- data/lib/puppet-strings/yard/code_objects/task.rb +3 -1
- data/lib/puppet-strings/yard/code_objects/type.rb +49 -5
- data/lib/puppet-strings/yard/handlers.rb +4 -0
- data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
- data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
- data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
- data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
- data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
- data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
- data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
- data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
- data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
- data/lib/puppet-strings/yard/handlers/ruby/base.rb +7 -2
- data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +409 -0
- data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -9
- data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
- data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +6 -3
- data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +25 -12
- data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +6 -3
- data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +18 -1
- data/lib/puppet-strings/yard/parsers.rb +2 -0
- data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -1
- data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
- data/lib/puppet-strings/yard/parsers/puppet/parser.rb +11 -2
- data/lib/puppet-strings/yard/parsers/puppet/statement.rb +29 -0
- data/lib/puppet-strings/yard/tags.rb +4 -0
- data/lib/puppet-strings/yard/tags/enum_tag.rb +14 -0
- data/lib/puppet-strings/yard/tags/factory.rb +18 -0
- data/lib/puppet-strings/yard/tags/overload_tag.rb +5 -2
- data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
- data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
- data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
- data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
- data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +1 -1
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
- data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
- data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
- data/lib/puppet-strings/yard/util.rb +7 -4
- data/lib/puppet/application/strings.rb +2 -0
- data/lib/puppet/face/strings.rb +7 -4
- data/lib/puppet/feature/rgen.rb +2 -0
- data/lib/puppet/feature/yard.rb +2 -0
- metadata +35 -45
- data/Gemfile +0 -38
- data/HISTORY.md +0 -218
- data/JSON.md +0 -802
- data/Rakefile +0 -98
- data/codecov.yml +0 -3
- data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
- data/spec/acceptance/emit_json_options.rb +0 -71
- data/spec/acceptance/generate_markdown_spec.rb +0 -49
- data/spec/acceptance/lib/util.rb +0 -163
- data/spec/acceptance/running_strings_generate.rb +0 -54
- data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
- data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
- data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
- data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
- data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
- data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
- data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
- data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
- data/spec/fixtures/unit/markdown/output.md +0 -508
- data/spec/fixtures/unit/markdown/output_with_plan.md +0 -542
- data/spec/spec_helper.rb +0 -46
- data/spec/spec_helper_acceptance.rb +0 -28
- data/spec/unit/puppet-strings/describe_spec.rb +0 -141
- data/spec/unit/puppet-strings/json_spec.rb +0 -283
- data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
- data/spec/unit/puppet-strings/markdown_spec.rb +0 -296
- data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
- data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -116
- data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
- data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
- data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
- data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
- data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
- data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -235
- data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -295
- data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -72
- data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
- data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
- data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppet-strings/yard/handlers/helpers'
|
2
4
|
require 'puppet-strings/yard/handlers/ruby/base'
|
3
5
|
require 'puppet-strings/yard/code_objects'
|
@@ -29,6 +31,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
29
31
|
# newline, YARD ignores the namespace and uses `newfunction` as the source of the
|
30
32
|
# first statement.
|
31
33
|
return unless statement.count > 1
|
34
|
+
|
32
35
|
module_name = statement[0].source
|
33
36
|
return unless module_name == 'Puppet::Functions' || module_name == 'Puppet::Parser::Functions' || module_name == 'newfunction'
|
34
37
|
|
@@ -219,8 +222,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
219
222
|
|
220
223
|
# Populate the required parameters
|
221
224
|
params = parameters.unnamed_required_params
|
222
|
-
|
223
|
-
params.each do |parameter|
|
225
|
+
params&.each do |parameter|
|
224
226
|
add_param_tag(
|
225
227
|
overload_tag,
|
226
228
|
param_tags,
|
@@ -229,12 +231,10 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
229
231
|
parameter.line
|
230
232
|
)
|
231
233
|
end
|
232
|
-
end
|
233
234
|
|
234
235
|
# Populate the optional parameters
|
235
236
|
params = parameters.unnamed_optional_params
|
236
|
-
|
237
|
-
params.each do |parameter|
|
237
|
+
params&.each do |parameter|
|
238
238
|
add_param_tag(
|
239
239
|
overload_tag,
|
240
240
|
param_tags,
|
@@ -246,7 +246,6 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
246
246
|
true
|
247
247
|
)
|
248
248
|
end
|
249
|
-
end
|
250
249
|
|
251
250
|
# Populate the splat parameter
|
252
251
|
param = parameters.splat_param
|
@@ -301,9 +300,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
301
300
|
name = '&' + name
|
302
301
|
end
|
303
302
|
|
304
|
-
|
305
|
-
type = tag && tag.types ? tag.type : 'Any'
|
306
|
-
end
|
303
|
+
type ||= tag&.types ? tag.type : 'Any'
|
307
304
|
type = optional ? "Optional[#{type}]" : type
|
308
305
|
|
309
306
|
object.parameters << [name, to_puppet_literal(default)]
|
@@ -330,6 +327,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
330
327
|
# Validate that tags have matching parameters
|
331
328
|
overload.tags(:param).each do |tag|
|
332
329
|
next if overload.parameters.find { |p| tag.name == p[0] }
|
330
|
+
|
333
331
|
log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{file}:#{line}."
|
334
332
|
end
|
335
333
|
end
|
@@ -340,9 +338,11 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
340
338
|
parameters[1].each do |kvp|
|
341
339
|
next unless kvp.count == 2
|
342
340
|
next unless node_as_string(kvp[0]) == 'doc'
|
341
|
+
|
343
342
|
docstring = node_as_string(kvp[1])
|
344
343
|
|
345
344
|
log.error "Failed to parse docstring for 3.x Puppet function '#{name}' near #{statement.file}:#{statement.line}." and return nil unless docstring
|
345
|
+
|
346
346
|
return PuppetStrings::Yard::Util.scrub_string(docstring)
|
347
347
|
end
|
348
348
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppet-strings/yard/handlers/helpers'
|
2
4
|
require 'puppet-strings/yard/handlers/ruby/base'
|
3
5
|
require 'puppet-strings/yard/code_objects'
|
@@ -20,6 +22,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
20
22
|
# Extract the type name
|
21
23
|
type_call_parameters = type_call.parameters(false)
|
22
24
|
return unless type_call_parameters.count >= 1
|
25
|
+
|
23
26
|
type_name = node_as_string(type_call_parameters.first)
|
24
27
|
raise YARD::Parser::UndocumentableError, "Could not determine the resource type name for the provider defined at #{statement.file}:#{statement.line}." unless type_name
|
25
28
|
|
@@ -47,8 +50,10 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
47
50
|
if child.type == :assign
|
48
51
|
ivar = child.jump(:ivar)
|
49
52
|
next unless ivar != child && ivar.source == '@doc'
|
53
|
+
|
50
54
|
docstring = node_as_string(child[1])
|
51
55
|
log.error "Failed to parse docstring for Puppet provider '#{object.name}' (resource type '#{object.type_name}') near #{child.file}:#{child.line}." and return nil unless docstring
|
56
|
+
|
52
57
|
register_docstring(object, PuppetStrings::Yard::Util.scrub_string(docstring), nil)
|
53
58
|
return nil
|
54
59
|
elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
|
@@ -60,6 +65,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
60
65
|
|
61
66
|
docstring = node_as_string(child.parameters[0])
|
62
67
|
log.error "Failed to parse docstring for Puppet provider '#{object.name}' (resource type '#{object.type_name}') near #{child.file}:#{child.line}." and return nil unless docstring
|
68
|
+
|
63
69
|
register_docstring(object, PuppetStrings::Yard::Util.scrub_string(docstring), nil)
|
64
70
|
return nil
|
65
71
|
end
|
@@ -71,6 +77,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
71
77
|
# Traverse the block looking for confines/defaults/commands
|
72
78
|
block = statement.block
|
73
79
|
return unless block && block.count >= 2
|
80
|
+
|
74
81
|
block[1].children.each do |node|
|
75
82
|
next unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) && node.method_name
|
76
83
|
|
@@ -80,8 +87,10 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
80
87
|
if method_name == 'confine'
|
81
88
|
# Add a confine to the object
|
82
89
|
next unless parameters.count >= 1
|
90
|
+
|
83
91
|
parameters[0].each do |kvp|
|
84
92
|
next unless kvp.count == 2
|
93
|
+
|
85
94
|
object.add_confine(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source)
|
86
95
|
end
|
87
96
|
elsif method_name == 'has_feature' || method_name == 'has_features'
|
@@ -92,9 +101,11 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
92
101
|
elsif method_name == 'defaultfor'
|
93
102
|
# Add a default to the object
|
94
103
|
next unless parameters.count >= 1
|
104
|
+
|
95
105
|
# Some defaultfor statements contain multiple constraints.
|
96
106
|
parameters.each do |kvps|
|
97
107
|
next unless kvps.count >= 1
|
108
|
+
|
98
109
|
defaultfor = []
|
99
110
|
kvps.each do |kvp|
|
100
111
|
defaultfor << [node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source]
|
@@ -104,8 +115,10 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
104
115
|
elsif method_name == 'commands'
|
105
116
|
# Add the commands to the object
|
106
117
|
next unless parameters.count >= 1
|
118
|
+
|
107
119
|
parameters[0].each do |kvp|
|
108
120
|
next unless kvp.count == 2
|
121
|
+
|
109
122
|
object.add_command(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source)
|
110
123
|
end
|
111
124
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppet-strings/yard/handlers/helpers'
|
2
4
|
require 'puppet-strings/yard/handlers/ruby/base'
|
3
5
|
require 'puppet-strings/yard/code_objects'
|
@@ -6,7 +8,7 @@ require 'puppet-strings/yard/util'
|
|
6
8
|
# Implements the handler for Puppet resource types written in Ruby.
|
7
9
|
class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::Handlers::Ruby::Base
|
8
10
|
# The default docstring when ensurable is used without given a docstring.
|
9
|
-
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
|
11
|
+
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
|
10
12
|
|
11
13
|
namespace_only
|
12
14
|
handles method_call(:register_type)
|
@@ -14,8 +16,9 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
|
|
14
16
|
process do
|
15
17
|
# Only accept calls to Puppet::ResourceApi
|
16
18
|
return unless statement.count > 1
|
19
|
+
|
17
20
|
module_name = statement[0].source
|
18
|
-
return unless [
|
21
|
+
return unless ['Puppet::ResourceApi'].include? module_name
|
19
22
|
|
20
23
|
schema = extract_schema
|
21
24
|
|
@@ -92,7 +95,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
|
|
92
95
|
# puts "hash from #{node.inspect}"
|
93
96
|
|
94
97
|
kv_pairs = node.children.collect do |assoc|
|
95
|
-
[
|
98
|
+
[value_from_node(assoc.children[0]), value_from_node(assoc.children[1])]
|
96
99
|
end
|
97
100
|
Hash[kv_pairs]
|
98
101
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppet-strings/yard/handlers/ruby/base'
|
2
4
|
|
3
5
|
class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handlers::Ruby::Base
|
@@ -15,15 +17,17 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
15
17
|
register object
|
16
18
|
object
|
17
19
|
end
|
18
|
-
|
20
|
+
|
19
21
|
def find_docstring(node, kind)
|
20
22
|
# Walk the tree searching for assignments or calls to desc/doc=
|
21
23
|
node.traverse do |child|
|
22
24
|
if child.type == :assign
|
23
25
|
ivar = child.jump(:ivar)
|
24
26
|
next unless ivar != child && ivar.source == '@doc'
|
27
|
+
|
25
28
|
docstring = node_as_string(child[1])
|
26
29
|
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
|
30
|
+
|
27
31
|
return PuppetStrings::Yard::Util.scrub_string(docstring)
|
28
32
|
elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
|
29
33
|
# Look for a call to a dispatch method with a block
|
@@ -33,6 +37,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
33
37
|
|
34
38
|
docstring = node_as_string(child.parameters[0])
|
35
39
|
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
|
40
|
+
|
36
41
|
return PuppetStrings::Yard::Util.scrub_string(docstring)
|
37
42
|
end
|
38
43
|
end
|
@@ -52,6 +57,12 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
52
57
|
property
|
53
58
|
end
|
54
59
|
|
60
|
+
def create_check(name, node)
|
61
|
+
check = PuppetStrings::Yard::CodeObjects::Type::Check.new(name, find_docstring(node, "Puppet resource check '#{name}'"))
|
62
|
+
set_values(node, check)
|
63
|
+
check
|
64
|
+
end
|
65
|
+
|
55
66
|
def set_values(node, object)
|
56
67
|
return unless node.block && node.block.count >= 2
|
57
68
|
|
@@ -63,6 +74,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
63
74
|
|
64
75
|
if method_name == 'newvalue'
|
65
76
|
next unless parameters.count >= 1
|
77
|
+
|
66
78
|
object.add(node_as_string(parameters[0]) || parameters[0].source)
|
67
79
|
elsif method_name == 'newvalues'
|
68
80
|
parameters.each do |p|
|
@@ -70,9 +82,11 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
70
82
|
end
|
71
83
|
elsif method_name == 'aliasvalue'
|
72
84
|
next unless parameters.count >= 2
|
85
|
+
|
73
86
|
object.alias(node_as_string(parameters[0]) || parameters[0].source, node_as_string(parameters[1]) || parameters[1].source)
|
74
87
|
elsif method_name == 'defaultto'
|
75
88
|
next unless parameters.count >= 1
|
89
|
+
|
76
90
|
object.default = node_as_string(parameters[0]) || parameters[0].source
|
77
91
|
elsif method_name == 'isnamevar'
|
78
92
|
object.isnamevar = true
|
@@ -97,11 +111,12 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
97
111
|
parameters[1].each do |kvp|
|
98
112
|
next unless kvp.count == 2
|
99
113
|
next unless node_as_string(kvp[0]) == 'parent'
|
114
|
+
|
100
115
|
if kvp[1].source == 'Puppet::Parameter::Boolean'
|
101
|
-
object.add('true') unless object.values.include? 'true'
|
102
|
-
object.add('false') unless object.values.include? 'false'
|
103
|
-
object.add('yes') unless object.values.include? 'yes'
|
104
|
-
object.add('no') unless object.values.include? 'no'
|
116
|
+
object.add('true') unless object.values.include? 'true' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
|
117
|
+
object.add('false') unless object.values.include? 'false' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
|
118
|
+
object.add('yes') unless object.values.include? 'yes' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
|
119
|
+
object.add('no') unless object.values.include? 'no' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
|
105
120
|
end
|
106
121
|
break
|
107
122
|
end
|
@@ -111,20 +126,18 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
111
126
|
|
112
127
|
def set_default_namevar(object)
|
113
128
|
return unless object.properties || object.parameters
|
129
|
+
|
114
130
|
default = nil
|
115
|
-
|
116
|
-
object.properties.each do |property|
|
131
|
+
object.properties&.each do |property|
|
117
132
|
return nil if property.isnamevar
|
133
|
+
|
118
134
|
default = property if property.name == 'name'
|
119
135
|
end
|
120
|
-
|
121
|
-
if object.parameters
|
122
|
-
object.parameters.each do |parameter|
|
136
|
+
object.parameters&.each do |parameter|
|
123
137
|
return nil if parameter.isnamevar
|
138
|
+
|
124
139
|
default ||= parameter if parameter.name == 'name'
|
125
140
|
end
|
126
|
-
end
|
127
141
|
default.isnamevar = true if default
|
128
142
|
end
|
129
143
|
end
|
130
|
-
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppet-strings/yard/handlers/helpers'
|
2
4
|
require 'puppet-strings/yard/handlers/ruby/type_base'
|
3
5
|
require 'puppet-strings/yard/code_objects'
|
@@ -6,7 +8,7 @@ require 'puppet-strings/yard/util'
|
|
6
8
|
# Implements the handler for Puppet resource type newparam/newproperty calls written in Ruby.
|
7
9
|
class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Yard::Handlers::Ruby::TypeBase
|
8
10
|
# The default docstring when ensurable is used without given a docstring.
|
9
|
-
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
|
11
|
+
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
|
10
12
|
|
11
13
|
namespace_only
|
12
14
|
handles method_call(:newparam)
|
@@ -31,9 +33,10 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
|
|
31
33
|
# propertyname: "content"
|
32
34
|
|
33
35
|
return unless (statement.count > 1) && (statement[0].children.count > 2)
|
36
|
+
|
34
37
|
module_name = statement[0].children[0].source
|
35
|
-
method1_name = statement[0].children
|
36
|
-
return unless
|
38
|
+
method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source
|
39
|
+
return unless ['Type', 'Puppet::Type'].include?(module_name) && method1_name == 'type'
|
37
40
|
|
38
41
|
typename = get_name(statement[0], 'Puppet::Type.type')
|
39
42
|
method2_name = caller_method
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppet-strings/yard/handlers/helpers'
|
2
4
|
require 'puppet-strings/yard/handlers/ruby/type_base'
|
3
5
|
require 'puppet-strings/yard/code_objects'
|
@@ -6,7 +8,7 @@ require 'puppet-strings/yard/util'
|
|
6
8
|
# Implements the handler for Puppet resource types written in Ruby.
|
7
9
|
class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Handlers::Ruby::TypeBase
|
8
10
|
# The default docstring when ensurable is used without given a docstring.
|
9
|
-
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
|
11
|
+
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
|
10
12
|
|
11
13
|
namespace_only
|
12
14
|
handles method_call(:newtype)
|
@@ -14,6 +16,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
14
16
|
process do
|
15
17
|
# Only accept calls to Puppet::Type
|
16
18
|
return unless statement.count > 1
|
19
|
+
|
17
20
|
module_name = statement[0].source
|
18
21
|
return unless module_name == 'Puppet::Type' || module_name == 'Type'
|
19
22
|
|
@@ -40,6 +43,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
40
43
|
# Traverse the block looking for properties/parameters/features
|
41
44
|
block = statement.block
|
42
45
|
return unless block && block.count >= 2
|
46
|
+
|
43
47
|
block[1].children.each do |node|
|
44
48
|
next unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) &&
|
45
49
|
node.method_name
|
@@ -50,18 +54,31 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
50
54
|
if method_name == 'newproperty'
|
51
55
|
# Add a property to the object
|
52
56
|
next unless parameters.count >= 1
|
57
|
+
|
53
58
|
name = node_as_string(parameters[0])
|
54
59
|
next unless name
|
60
|
+
|
55
61
|
object.add_property(create_property(name, node))
|
56
62
|
elsif method_name == 'newparam'
|
57
63
|
# Add a parameter to the object
|
58
64
|
next unless parameters.count >= 1
|
65
|
+
|
59
66
|
name = node_as_string(parameters[0])
|
60
67
|
next unless name
|
68
|
+
|
61
69
|
object.add_parameter(create_parameter(name, node))
|
70
|
+
elsif method_name == 'newcheck'
|
71
|
+
# Add a check to the object
|
72
|
+
next unless parameters.count >= 1
|
73
|
+
|
74
|
+
name = node_as_string(parameters[0])
|
75
|
+
next unless name
|
76
|
+
|
77
|
+
object.add_check(create_check(name, node))
|
62
78
|
elsif method_name == 'feature'
|
63
79
|
# Add a feature to the object
|
64
80
|
next unless parameters.count >= 2
|
81
|
+
|
65
82
|
name = node_as_string(parameters[0])
|
66
83
|
next unless name
|
67
84
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppet-strings/yard/parsers/json/task_statement'
|
2
4
|
|
3
5
|
class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
|
@@ -25,7 +27,7 @@ class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
|
|
25
27
|
# TODO: this should compare json to a Task metadata json-schema or perform some other hueristics
|
26
28
|
# to determine what type of statement it represents
|
27
29
|
@statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) unless json.empty?
|
28
|
-
rescue
|
30
|
+
rescue # rubocop:disable Style/RescueStandardError Just catch everything
|
29
31
|
log.error "Failed to parse #{@file}: "
|
30
32
|
@statements = []
|
31
33
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppet'
|
2
4
|
require 'puppet/pops'
|
3
5
|
require 'puppet-strings/yard/parsers/puppet/statement'
|
@@ -26,8 +28,8 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
|
|
26
28
|
return
|
27
29
|
end
|
28
30
|
@statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact
|
29
|
-
rescue ::Puppet::ParseError =>
|
30
|
-
log.error "Failed to parse #{@file}: #{
|
31
|
+
rescue ::Puppet::ParseError => e
|
32
|
+
log.error "Failed to parse #{@file}: #{e.message}"
|
31
33
|
@statements = []
|
32
34
|
end
|
33
35
|
@statements.freeze
|
@@ -41,6 +43,7 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
|
|
41
43
|
end
|
42
44
|
|
43
45
|
private
|
46
|
+
|
44
47
|
def transform_Program(o)
|
45
48
|
# Cache the lines of the source text; we'll use this to locate comments
|
46
49
|
@lines = o.source_text.lines.to_a
|
@@ -75,6 +78,12 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
|
|
75
78
|
statement
|
76
79
|
end
|
77
80
|
|
81
|
+
def transform_TypeAlias(o)
|
82
|
+
statement = PuppetStrings::Yard::Parsers::Puppet::DataTypeAliasStatement.new(o, @file)
|
83
|
+
statement.extract_docstring(@lines)
|
84
|
+
statement
|
85
|
+
end
|
86
|
+
|
78
87
|
def transform_Object(o)
|
79
88
|
# Ignore anything else (will be compacted out of the resulting array)
|
80
89
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppet'
|
2
4
|
require 'puppet/pops'
|
3
5
|
|
@@ -32,11 +34,13 @@ module PuppetStrings::Yard::Parsers::Puppet
|
|
32
34
|
comment = []
|
33
35
|
(0..@line-2).reverse_each do |index|
|
34
36
|
break unless index <= lines.count
|
37
|
+
|
35
38
|
line = lines[index].strip
|
36
39
|
count = line.size
|
37
40
|
line.gsub!(COMMENT_REGEX, '')
|
38
41
|
# Break out if nothing was removed (wasn't a comment line)
|
39
42
|
break unless line.size < count
|
43
|
+
|
40
44
|
comment << line
|
41
45
|
end
|
42
46
|
@comments_range = (@line - comment.size - 1..@line - 1)
|
@@ -165,4 +169,29 @@ module PuppetStrings::Yard::Parsers::Puppet
|
|
165
169
|
end
|
166
170
|
end
|
167
171
|
|
172
|
+
# Implements the Puppet data type alias statement.
|
173
|
+
class DataTypeAliasStatement < Statement
|
174
|
+
attr_reader :name
|
175
|
+
attr_reader :alias_of
|
176
|
+
|
177
|
+
# Initializes the Puppet data type alias statement.
|
178
|
+
# @param [Puppet::Pops::Model::TypeAlias] object The model object for the type statement.
|
179
|
+
# @param [String] file The file containing the statement.
|
180
|
+
def initialize(object, file)
|
181
|
+
super(object, file)
|
182
|
+
|
183
|
+
type_expr = object.type_expr
|
184
|
+
case type_expr
|
185
|
+
when Puppet::Pops::Model::AccessExpression
|
186
|
+
# TODO: I don't like rebuilding the source from the AST, but AccessExpressions don't expose the original source
|
187
|
+
@alias_of = ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(type_expr.left_expr).extract_text + '['
|
188
|
+
@alias_of << type_expr.keys.map { |key| ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(key).extract_text }.join(', ')
|
189
|
+
@alias_of << ']'
|
190
|
+
else
|
191
|
+
adapter = ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(type_expr)
|
192
|
+
@alias_of = adapter.extract_text
|
193
|
+
end
|
194
|
+
@name = object.name
|
195
|
+
end
|
196
|
+
end
|
168
197
|
end
|