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.
Files changed (150) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +87 -1
  3. data/CONTRIBUTING.md +32 -2
  4. data/README.md +81 -17
  5. data/lib/puppet-strings.rb +5 -3
  6. data/lib/puppet-strings/describe.rb +2 -0
  7. data/lib/puppet-strings/json.rb +4 -0
  8. data/lib/puppet-strings/markdown.rb +13 -9
  9. data/lib/puppet-strings/markdown/base.rb +30 -3
  10. data/lib/puppet-strings/markdown/data_type.rb +36 -0
  11. data/lib/puppet-strings/markdown/data_types.rb +43 -0
  12. data/lib/puppet-strings/markdown/defined_type.rb +2 -0
  13. data/lib/puppet-strings/markdown/defined_types.rb +3 -1
  14. data/lib/puppet-strings/markdown/function.rb +9 -7
  15. data/lib/puppet-strings/markdown/functions.rb +3 -1
  16. data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
  17. data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
  18. data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
  19. data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
  20. data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
  21. data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
  22. data/lib/puppet-strings/markdown/resource_type.rb +21 -2
  23. data/lib/puppet-strings/markdown/resource_types.rb +3 -1
  24. data/lib/puppet-strings/markdown/table_of_contents.rb +4 -1
  25. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +18 -6
  26. data/lib/puppet-strings/markdown/templates/data_type.erb +101 -0
  27. data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
  28. data/lib/puppet-strings/markdown/templates/function.erb +10 -1
  29. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  30. data/lib/puppet-strings/markdown/templates/resource_type.erb +35 -13
  31. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
  32. data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
  33. data/lib/puppet-strings/tasks.rb +2 -0
  34. data/lib/puppet-strings/tasks/generate.rb +5 -2
  35. data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
  36. data/lib/puppet-strings/version.rb +3 -1
  37. data/lib/puppet-strings/yard.rb +19 -0
  38. data/lib/puppet-strings/yard/code_objects.rb +4 -0
  39. data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
  40. data/lib/puppet-strings/yard/code_objects/class.rb +5 -3
  41. data/lib/puppet-strings/yard/code_objects/data_type.rb +102 -0
  42. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +60 -0
  43. data/lib/puppet-strings/yard/code_objects/defined_type.rb +5 -3
  44. data/lib/puppet-strings/yard/code_objects/function.rb +9 -6
  45. data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
  46. data/lib/puppet-strings/yard/code_objects/plan.rb +5 -3
  47. data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
  48. data/lib/puppet-strings/yard/code_objects/task.rb +3 -1
  49. data/lib/puppet-strings/yard/code_objects/type.rb +49 -5
  50. data/lib/puppet-strings/yard/handlers.rb +4 -0
  51. data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
  52. data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
  53. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
  54. data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
  55. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
  56. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
  57. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
  58. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
  59. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
  60. data/lib/puppet-strings/yard/handlers/ruby/base.rb +7 -2
  61. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +409 -0
  62. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -9
  63. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
  64. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +6 -3
  65. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +25 -12
  66. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +6 -3
  67. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +18 -1
  68. data/lib/puppet-strings/yard/parsers.rb +2 -0
  69. data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -1
  70. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
  71. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +11 -2
  72. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +29 -0
  73. data/lib/puppet-strings/yard/tags.rb +4 -0
  74. data/lib/puppet-strings/yard/tags/enum_tag.rb +14 -0
  75. data/lib/puppet-strings/yard/tags/factory.rb +18 -0
  76. data/lib/puppet-strings/yard/tags/overload_tag.rb +5 -2
  77. data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
  78. data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
  79. data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
  80. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
  81. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
  82. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
  83. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
  84. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
  85. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
  86. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  87. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
  88. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
  89. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
  90. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
  91. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
  92. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
  93. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
  94. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
  95. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
  96. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
  97. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
  98. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
  99. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
  100. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
  101. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
  102. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +1 -1
  103. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
  104. data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
  105. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
  106. data/lib/puppet-strings/yard/util.rb +7 -4
  107. data/lib/puppet/application/strings.rb +2 -0
  108. data/lib/puppet/face/strings.rb +7 -4
  109. data/lib/puppet/feature/rgen.rb +2 -0
  110. data/lib/puppet/feature/yard.rb +2 -0
  111. metadata +35 -45
  112. data/Gemfile +0 -38
  113. data/HISTORY.md +0 -218
  114. data/JSON.md +0 -802
  115. data/Rakefile +0 -98
  116. data/codecov.yml +0 -3
  117. data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
  118. data/spec/acceptance/emit_json_options.rb +0 -71
  119. data/spec/acceptance/generate_markdown_spec.rb +0 -49
  120. data/spec/acceptance/lib/util.rb +0 -163
  121. data/spec/acceptance/running_strings_generate.rb +0 -54
  122. data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
  123. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
  124. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
  125. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
  126. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
  127. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
  128. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
  129. data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
  130. data/spec/fixtures/unit/markdown/output.md +0 -508
  131. data/spec/fixtures/unit/markdown/output_with_plan.md +0 -542
  132. data/spec/spec_helper.rb +0 -46
  133. data/spec/spec_helper_acceptance.rb +0 -28
  134. data/spec/unit/puppet-strings/describe_spec.rb +0 -141
  135. data/spec/unit/puppet-strings/json_spec.rb +0 -283
  136. data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
  137. data/spec/unit/puppet-strings/markdown_spec.rb +0 -296
  138. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
  139. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -116
  140. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
  141. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
  142. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
  143. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
  144. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
  145. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -235
  146. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -295
  147. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -72
  148. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
  149. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
  150. 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
- if params
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
- if params
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
- unless type
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.'.freeze
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 [ 'Puppet::ResourceApi' ].include? module_name
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
- [ value_from_node(assoc.children[0]), value_from_node(assoc.children[1]) ]
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
- if object.properties
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
- end
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.'.freeze
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[1].source
36
- return unless (module_name == 'Puppet::Type' || module_name == 'Type') && method1_name == 'type'
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.'.freeze
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
  # The module for custom YARD parsers.
2
4
  module PuppetStrings::Yard::Parsers
3
5
  # The module for custom YARD parsers for JSON.
@@ -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
  module PuppetStrings::Yard::Parsers::JSON
2
4
  # Represents the Puppet Task statement.
3
5
  class TaskStatement
@@ -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 => ex
30
- log.error "Failed to parse #{@file}: #{ex.message}"
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