puppet-strings 2.4.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +97 -5
  3. data/COMMITTERS.md +17 -17
  4. data/CONTRIBUTING.md +6 -6
  5. data/README.md +10 -10
  6. data/lib/puppet-strings.rb +4 -2
  7. data/lib/puppet-strings/describe.rb +2 -0
  8. data/lib/puppet-strings/json.rb +2 -0
  9. data/lib/puppet-strings/markdown.rb +12 -10
  10. data/lib/puppet-strings/markdown/base.rb +17 -3
  11. data/lib/puppet-strings/markdown/data_type.rb +18 -0
  12. data/lib/puppet-strings/markdown/data_types.rb +3 -1
  13. data/lib/puppet-strings/markdown/defined_type.rb +2 -0
  14. data/lib/puppet-strings/markdown/defined_types.rb +3 -1
  15. data/lib/puppet-strings/markdown/function.rb +9 -7
  16. data/lib/puppet-strings/markdown/functions.rb +3 -1
  17. data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
  18. data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
  19. data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
  20. data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
  21. data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
  22. data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
  23. data/lib/puppet-strings/markdown/resource_type.rb +21 -2
  24. data/lib/puppet-strings/markdown/resource_types.rb +3 -1
  25. data/lib/puppet-strings/markdown/table_of_contents.rb +3 -1
  26. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +10 -6
  27. data/lib/puppet-strings/markdown/templates/data_type.erb +22 -7
  28. data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
  29. data/lib/puppet-strings/markdown/templates/function.erb +2 -1
  30. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  31. data/lib/puppet-strings/markdown/templates/resource_type.erb +19 -13
  32. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
  33. data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
  34. data/lib/puppet-strings/tasks.rb +2 -0
  35. data/lib/puppet-strings/tasks/generate.rb +2 -0
  36. data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
  37. data/lib/puppet-strings/version.rb +3 -1
  38. data/lib/puppet-strings/yard.rb +3 -0
  39. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  40. data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
  41. data/lib/puppet-strings/yard/code_objects/class.rb +4 -2
  42. data/lib/puppet-strings/yard/code_objects/data_type.rb +30 -8
  43. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +2 -0
  44. data/lib/puppet-strings/yard/code_objects/defined_type.rb +4 -2
  45. data/lib/puppet-strings/yard/code_objects/function.rb +6 -3
  46. data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
  47. data/lib/puppet-strings/yard/code_objects/plan.rb +4 -2
  48. data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
  49. data/lib/puppet-strings/yard/code_objects/task.rb +2 -0
  50. data/lib/puppet-strings/yard/code_objects/type.rb +50 -5
  51. data/lib/puppet-strings/yard/handlers.rb +2 -0
  52. data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
  53. data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
  54. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
  55. data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
  56. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
  57. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +2 -0
  58. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
  59. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
  60. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
  61. data/lib/puppet-strings/yard/handlers/ruby/base.rb +5 -0
  62. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +223 -60
  63. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -7
  64. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
  65. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +4 -1
  66. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +20 -6
  67. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +16 -6
  68. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +18 -1
  69. data/lib/puppet-strings/yard/parsers.rb +2 -0
  70. data/lib/puppet-strings/yard/parsers/json/parser.rb +2 -0
  71. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
  72. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +18 -14
  73. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +4 -0
  74. data/lib/puppet-strings/yard/tags.rb +2 -0
  75. data/lib/puppet-strings/yard/tags/enum_tag.rb +2 -0
  76. data/lib/puppet-strings/yard/tags/factory.rb +2 -0
  77. data/lib/puppet-strings/yard/tags/overload_tag.rb +4 -1
  78. data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
  79. data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
  80. data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
  81. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  82. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +9 -1
  83. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +1 -1
  84. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
  85. data/lib/puppet-strings/yard/util.rb +4 -1
  86. data/lib/puppet/application/strings.rb +2 -0
  87. data/lib/puppet/face/strings.rb +4 -1
  88. data/lib/puppet/feature/rgen.rb +2 -0
  89. data/lib/puppet/feature/yard.rb +2 -0
  90. metadata +11 -52
  91. data/CODEOWNERS +0 -1
  92. data/Gemfile +0 -53
  93. data/HISTORY.md +0 -218
  94. data/JSON.md +0 -832
  95. data/Rakefile +0 -160
  96. data/codecov.yml +0 -3
  97. data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
  98. data/spec/acceptance/emit_json_options_spec.rb +0 -69
  99. data/spec/acceptance/generate_markdown_spec.rb +0 -47
  100. data/spec/acceptance/running_strings_generate_spec.rb +0 -88
  101. data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
  102. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
  103. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
  104. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
  105. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
  106. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -31
  107. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
  108. data/spec/fixtures/acceptance/modules/test/metadata.json +0 -10
  109. data/spec/fixtures/acceptance/modules/test/types/elephant.pp +0 -2
  110. data/spec/fixtures/unit/markdown/output.md +0 -561
  111. data/spec/fixtures/unit/markdown/output_with_data_types.md +0 -606
  112. data/spec/fixtures/unit/markdown/output_with_plan.md +0 -595
  113. data/spec/spec_helper.rb +0 -49
  114. data/spec/spec_helper_acceptance.rb +0 -58
  115. data/spec/spec_helper_acceptance_local.rb +0 -10
  116. data/spec/unit/puppet-strings/describe_spec.rb +0 -141
  117. data/spec/unit/puppet-strings/json_spec.rb +0 -302
  118. data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
  119. data/spec/unit/puppet-strings/markdown_spec.rb +0 -374
  120. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
  121. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -116
  122. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
  123. data/spec/unit/puppet-strings/yard/handlers/puppet/data_type_alias_handler_spec.rb +0 -65
  124. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
  125. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
  126. data/spec/unit/puppet-strings/yard/handlers/ruby/data_type_handler_spec.rb +0 -309
  127. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -746
  128. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -158
  129. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -235
  130. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -311
  131. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -72
  132. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
  133. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -251
  134. 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,7 +300,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
301
300
  name = '&' + name
302
301
  end
303
302
 
304
- type ||= tag && tag.types ? tag.type : 'Any'
303
+ type ||= tag&.types ? tag.type : 'Any'
305
304
  type = optional ? "Optional[#{type}]" : type
306
305
 
307
306
  object.parameters << [name, to_puppet_literal(default)]
@@ -328,6 +327,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
328
327
  # Validate that tags have matching parameters
329
328
  overload.tags(:param).each do |tag|
330
329
  next if overload.parameters.find { |p| tag.name == p[0] }
330
+
331
331
  log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{file}:#{line}."
332
332
  end
333
333
  end
@@ -338,9 +338,11 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
338
338
  parameters[1].each do |kvp|
339
339
  next unless kvp.count == 2
340
340
  next unless node_as_string(kvp[0]) == 'doc'
341
+
341
342
  docstring = node_as_string(kvp[1])
342
343
 
343
344
  log.error "Failed to parse docstring for 3.x Puppet function '#{name}' near #{statement.file}:#{statement.line}." and return nil unless docstring
345
+
344
346
  return PuppetStrings::Yard::Util.scrub_string(docstring)
345
347
  end
346
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,6 +16,7 @@ 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
21
  return unless ['Puppet::ResourceApi'].include? module_name
19
22
 
@@ -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
@@ -22,8 +24,10 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
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,6 +111,7 @@ 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
116
  object.add('true') unless object.values.include? 'true' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
102
117
  object.add('false') unless object.values.include? 'false' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
@@ -111,19 +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
@@ -1,16 +1,19 @@
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'
4
6
  require 'puppet-strings/yard/util'
5
7
 
6
- # Implements the handler for Puppet resource type newparam/newproperty calls written in Ruby.
8
+ # Implements the handler for Puppet resource type newparam/newproperty/ensurable 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)
13
15
  handles method_call(:newproperty)
16
+ handles method_call(:ensurable)
14
17
 
15
18
  process do
16
19
 
@@ -31,13 +34,20 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
31
34
  # propertyname: "content"
32
35
 
33
36
  return unless (statement.count > 1) && (statement[0].children.count > 2)
37
+
34
38
  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'
39
+ method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source
40
+ return unless ['Type', 'Puppet::Type'].include?(module_name) && method1_name == 'type'
37
41
 
42
+ # ensurable is syntatic sugar for newproperty
38
43
  typename = get_name(statement[0], 'Puppet::Type.type')
39
- method2_name = caller_method
40
- propertyname = get_name(statement, "Puppet::Type.type().#{method2_name}")
44
+ if caller_method == 'ensurable'
45
+ method2_name = 'newproperty'
46
+ propertyname = 'ensure'
47
+ else
48
+ method2_name = caller_method
49
+ propertyname = get_name(statement, "Puppet::Type.type().#{method2_name}")
50
+ end
41
51
 
42
52
  typeobject = get_type_yard_object(typename)
43
53
 
@@ -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
@@ -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'
@@ -20,14 +22,16 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
20
22
  # @return [void]
21
23
  def parse
22
24
  begin
23
- Puppet[:tasks] = true if Puppet.settings.include?(:tasks)
24
- if Puppet::Util::Package.versioncmp(Puppet.version, "5.0.0") < 0 && @file.to_s.match(/^plans\//)
25
- log.warn "Skipping #{@file}: Puppet Plans require Puppet 5 or greater."
26
- return
25
+ if @file.to_s.match(/^plans|\/plans\//)
26
+ if Puppet::Util::Package.versioncmp(Puppet.version, "5.0.0") < 0
27
+ log.warn "Skipping #{@file}: Puppet Plans require Puppet 5 or greater."
28
+ return
29
+ end
30
+ Puppet[:tasks] = true if Puppet.settings.include?(:tasks)
27
31
  end
28
32
  @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}"
33
+ rescue ::Puppet::ParseError => e
34
+ log.error "Failed to parse #{@file}: #{e.message}"
31
35
  @statements = []
32
36
  end
33
37
  @statements.freeze
@@ -42,47 +46,47 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
42
46
 
43
47
  private
44
48
 
45
- def transform_Program(o) # rubocop:disable Naming/UncommunicativeMethodParamName
49
+ def transform_Program(o)
46
50
  # Cache the lines of the source text; we'll use this to locate comments
47
51
  @lines = o.source_text.lines.to_a
48
52
  o.definitions.map { |d| @visitor.visit(d) }
49
53
  end
50
54
 
51
- def transform_Factory(o) # rubocop:disable Naming/UncommunicativeMethodParamName
55
+ def transform_Factory(o)
52
56
  @visitor.visit(o.current)
53
57
  end
54
58
 
55
- def transform_HostClassDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
59
+ def transform_HostClassDefinition(o)
56
60
  statement = PuppetStrings::Yard::Parsers::Puppet::ClassStatement.new(o, @file)
57
61
  statement.extract_docstring(@lines)
58
62
  statement
59
63
  end
60
64
 
61
- def transform_ResourceTypeDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
65
+ def transform_ResourceTypeDefinition(o)
62
66
  statement = PuppetStrings::Yard::Parsers::Puppet::DefinedTypeStatement.new(o, @file)
63
67
  statement.extract_docstring(@lines)
64
68
  statement
65
69
  end
66
70
 
67
- def transform_FunctionDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
71
+ def transform_FunctionDefinition(o)
68
72
  statement = PuppetStrings::Yard::Parsers::Puppet::FunctionStatement.new(o, @file)
69
73
  statement.extract_docstring(@lines)
70
74
  statement
71
75
  end
72
76
 
73
- def transform_PlanDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
77
+ def transform_PlanDefinition(o)
74
78
  statement = PuppetStrings::Yard::Parsers::Puppet::PlanStatement.new(o, @file)
75
79
  statement.extract_docstring(@lines)
76
80
  statement
77
81
  end
78
82
 
79
- def transform_TypeAlias(o) # rubocop:disable Naming/UncommunicativeMethodParamName
83
+ def transform_TypeAlias(o)
80
84
  statement = PuppetStrings::Yard::Parsers::Puppet::DataTypeAliasStatement.new(o, @file)
81
85
  statement.extract_docstring(@lines)
82
86
  statement
83
87
  end
84
88
 
85
- def transform_Object(o) # rubocop:disable Naming/UncommunicativeMethodParamName
89
+ def transform_Object(o)
86
90
  # Ignore anything else (will be compacted out of the resulting array)
87
91
  end
88
92
  end