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,4 +1,4 @@
1
- ### <%= name %>
1
+ ### <a name="<%= link %>"></a>`<%= name %>`
2
2
 
3
3
  <% if text -%>
4
4
  <%= text %>
@@ -1,4 +1,4 @@
1
- ### <%= name %>
1
+ ### <a name="<%= link %>"></a>`<%= name %>`
2
2
 
3
3
  <% if text -%>
4
4
  <%= text %>
@@ -24,10 +24,10 @@
24
24
  * **See also**
25
25
  <% see.each do |sa| -%>
26
26
  <% if sa[:name] -%>
27
- <%= sa[:name] %>
27
+ <%= " * #{sa[:name]}" %>
28
28
  <% end -%>
29
29
  <% if sa[:text] -%>
30
- <%= sa[:text] %>
30
+ <%= " * #{sa[:text]}" %>
31
31
  <% end -%>
32
32
  <% end -%>
33
33
 
@@ -44,16 +44,16 @@
44
44
 
45
45
  <% end -%>
46
46
  <% end -%>
47
- <% if properties -%>
47
+ <% if properties_and_checks -%>
48
48
  #### Properties
49
49
 
50
50
  The following properties are available in the `<%= name %>` <%= @type %>.
51
51
 
52
- <% properties.each do |prop| -%>
52
+ <% properties_and_checks.each do |prop| -%>
53
53
  ##### `<%= prop[:name] %>`
54
54
 
55
55
  <% if prop[:values] -%>
56
- Valid values: <%= prop[:values].map { |value| value_string(value) }.join(', ') %>
56
+ Valid values: `<%= prop[:values].map { |value| value_string(value) }.join('`, `') %>`
57
57
 
58
58
  <% end -%>
59
59
  <% if prop[:isnamevar] -%>
@@ -61,7 +61,7 @@ namevar
61
61
 
62
62
  <% end -%>
63
63
  <% if prop[:aliases] -%>
64
- Aliases: <%= prop[:aliases].to_s.delete('{').delete('}') %>
64
+ Aliases: `<%= prop[:aliases].to_s.delete('{').delete('}') %>`
65
65
 
66
66
  <% end -%>
67
67
  <% if prop[:data_type] -%>
@@ -87,7 +87,7 @@ Options:
87
87
 
88
88
  <% end -%>
89
89
  <% if prop[:default] -%>
90
- Default value: <%= prop[:default] %>
90
+ Default value: `<%= prop[:default] %>`
91
91
 
92
92
  <% end -%>
93
93
  <% end -%>
@@ -98,10 +98,14 @@ Default value: <%= prop[:default] %>
98
98
  The following parameters are available in the `<%= name %>` <%= @type %>.
99
99
 
100
100
  <% parameters.each do |param| -%>
101
- ##### `<%= param[:name] %>`
101
+ * [`<%= param[:name] %>`](#<%= param[:name] %>)
102
+ <% end -%>
103
+
104
+ <% parameters.each do |param| -%>
105
+ ##### <a name="<%= param[:name] %>"></a>`<%= param[:name] %>`
102
106
 
103
107
  <% if param[:values] -%>
104
- Valid values: <%= param[:values].map { |value| value_string(value) }.join(', ') %>
108
+ Valid values: `<%= param[:values].map { |value| value_string(value) }.join('`, `') %>`
105
109
 
106
110
  <% end -%>
107
111
  <% if param[:isnamevar] -%>
@@ -109,14 +113,16 @@ namevar
109
113
 
110
114
  <% end -%>
111
115
  <% if param[:aliases] -%>
112
- Aliases: <%= param[:aliases].to_s.delete('{').delete('}') %>
116
+ Aliases: `<%= param[:aliases].to_s.delete('{').delete('}') %>`
113
117
 
114
118
  <% end -%>
115
119
  <% if param[:data_type] -%>
116
120
  Data type: `<%= param[:data_type] %>`<%= "\n_\*this data type contains a regex that may not be accurately reflected in generated documentation_" if regex_in_data_type?(param[:data_type]) %>
117
121
 
118
122
  <% end -%>
119
- <%= param[:description] %>
123
+ <% if param[:description] -%>
124
+ <%= word_wrap(param[:description]) %>
125
+ <% end -%>
120
126
 
121
127
  <% if options_for_param(param[:name]) -%>
122
128
  Options:
@@ -135,7 +141,7 @@ Options:
135
141
 
136
142
  <% end -%>
137
143
  <% if param[:default] -%>
138
- Default value: <%= value_string(param[:default]) %>
144
+ Default value: `<%= value_string(param[:default]) %>`
139
145
 
140
146
  <% end -%>
141
147
  <% if param[:required_features] -%>
@@ -1,25 +1,25 @@
1
1
  <% if group.length > 0 -%>
2
- **<%= group_name %>**
2
+ ### <%= group_name %>
3
3
 
4
4
  <% if priv -%>
5
- _Public <%= group_name %>_
5
+ #### Public <%= group_name %>
6
6
 
7
7
  <% group.each do |item| -%>
8
8
  <% unless item[:private] -%>
9
- * [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
9
+ * [`<%= item[:name] %>`](#<%= item[:link] %>)<% unless item[:desc].nil? || item[:desc].empty? %>: <%= item[:desc] %><% end %>
10
10
  <% end -%>
11
11
  <% end -%>
12
12
 
13
- _Private <%= group_name %>_
13
+ #### Private <%= group_name %>
14
14
 
15
15
  <% group.each do |item| -%>
16
16
  <% if item[:private] -%>
17
- * `<%= item[:name] %>`: <%= item[:desc] %>
17
+ * `<%= item[:name] %>`<% unless item[:desc].nil? || item[:desc].empty? %>: <%= item[:desc] %><% end %>
18
18
  <% end -%>
19
19
  <% end -%>
20
20
  <% else -%>
21
21
  <% group.each do |item| -%>
22
- * [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
22
+ * [`<%= item[:name] %>`](#<%= item[:link] %>)<% unless item[:desc].nil? || item[:desc].empty? %>: <%= item[:desc] %><% end %>
23
23
  <% end -%>
24
24
  <% end -%>
25
25
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Monkey patch URL decoding in object displays. Usually :: is interpreted as a
2
4
  # namespace, but this is disabled in our base object, and so instead gets
3
5
  # URL-encoded.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  require 'rake/tasklib'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings'
2
4
 
3
5
  # Implements the strings:generate task.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/tasks'
2
4
 
3
5
  namespace :strings do
@@ -5,6 +7,7 @@ namespace :strings do
5
7
  task :checkout do
6
8
  if Dir.exist?('doc')
7
9
  fail "The 'doc' directory (#{File.expand_path('doc')}) is not a Git repository! Remove it and run the Rake task again." unless Dir.exist?('doc/.git')
10
+
8
11
  Dir.chdir('doc') do
9
12
  system 'git checkout gh-pages'
10
13
  system 'git pull --rebase origin gh-pages'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PuppetStrings
2
- VERSION = '2.4.0'.freeze
4
+ VERSION = '2.8.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yard'
2
4
 
3
5
  # Module for YARD related functionality.
@@ -102,6 +104,7 @@ class YARD::CLI::Stats
102
104
 
103
105
  def stats_for_puppet_plans
104
106
  return unless PuppetStrings.puppet_5?
107
+
105
108
  output 'Puppet Plans', *type_statistics_all(:puppet_plan)
106
109
  end
107
110
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The module for custom YARD code objects.
2
4
  module PuppetStrings::Yard::CodeObjects
3
5
  require 'puppet-strings/yard/code_objects/class'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Implements the base code object.
2
4
  class PuppetStrings::Yard::CodeObjects::Base < YARD::CodeObjects::NamespaceObject
3
5
  # Allocates a new code object.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet classes.
@@ -52,8 +54,8 @@ class PuppetStrings::Yard::CodeObjects::Class < PuppetStrings::Yard::CodeObjects
52
54
  hash[:inherits] = statement.parent_class if statement.parent_class
53
55
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
54
56
  defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
55
- hash[:defaults] = defaults unless defaults.empty?
56
- hash[:source] = source unless source && source.empty?
57
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
58
+ hash[:source] = source unless source.nil? || source.empty?
57
59
  hash
58
60
  end
59
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
  require 'puppet-strings/yard/util'
3
5
 
@@ -24,7 +26,6 @@ class PuppetStrings::Yard::CodeObjects::DataType < PuppetStrings::Yard::CodeObje
24
26
  # @return [void]
25
27
  def initialize(name)
26
28
  super(PuppetStrings::Yard::CodeObjects::DataTypes.instance, name)
27
- @parameters = []
28
29
  @defaults = {}
29
30
  end
30
31
 
@@ -41,10 +42,6 @@ class PuppetStrings::Yard::CodeObjects::DataType < PuppetStrings::Yard::CodeObje
41
42
  nil
42
43
  end
43
44
 
44
- def parameter_exist?(name)
45
- !docstring.tags(:param).find { |item| item.name == name }.nil?
46
- end
47
-
48
45
  def add_parameter(name, type, default)
49
46
  tag = docstring.tags(:param).find { |item| item.name == name }
50
47
  if tag.nil?
@@ -65,6 +62,24 @@ class PuppetStrings::Yard::CodeObjects::DataType < PuppetStrings::Yard::CodeObje
65
62
  docstring.tags(:param).map { |tag| [tag.name, defaults[tag.name]] }
66
63
  end
67
64
 
65
+ def add_function(name, return_type, parameter_types)
66
+ meth_obj = YARD::CodeObjects::MethodObject.new(self, name, :class)
67
+
68
+ # Add return tag
69
+ meth_obj.add_tag(YARD::Tags::Tag.new(:return, '', return_type))
70
+
71
+ # Add parameters
72
+ parameter_types.each_with_index do |param_type, index|
73
+ meth_obj.add_tag(YARD::Tags::Tag.new(:param, '', [param_type], "param#{index + 1}"))
74
+ end
75
+
76
+ self.meths << meth_obj
77
+ end
78
+
79
+ def functions
80
+ meths
81
+ end
82
+
68
83
  # Converts the code object to a hash representation.
69
84
  # @return [Hash] Returns a hash representation of the code object.
70
85
  def to_hash
@@ -72,9 +87,16 @@ class PuppetStrings::Yard::CodeObjects::DataType < PuppetStrings::Yard::CodeObje
72
87
  hash[:name] = name
73
88
  hash[:file] = file
74
89
  hash[:line] = line
75
- hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
76
- hash[:defaults] = defaults unless defaults.empty?
77
- hash[:source] = source unless source && source.empty?
90
+ hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example])
91
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
92
+ hash[:source] = source unless source.nil? || source.empty?
93
+ hash[:functions] = functions.map do |func|
94
+ {
95
+ name: func.name,
96
+ signature: func.signature,
97
+ docstring: PuppetStrings::Yard::Util.docstring_to_hash(func.docstring, %i[param option enum return example])
98
+ }
99
+ end
78
100
  hash
79
101
  end
80
102
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
  require 'puppet-strings/yard/util'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet defined types.
@@ -51,8 +53,8 @@ class PuppetStrings::Yard::CodeObjects::DefinedType < PuppetStrings::Yard::CodeO
51
53
  hash[:line] = line
52
54
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
53
55
  defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
54
- hash[:defaults] = defaults unless defaults.empty?
55
- hash[:source] = source unless source && source.empty?
56
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
57
+ hash[:source] = source unless source.nil? || source.empty?
56
58
  hash
57
59
  end
58
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet functions.
@@ -61,11 +63,12 @@ class PuppetStrings::Yard::CodeObjects::Function < PuppetStrings::Yard::CodeObje
61
63
  # @return [String] Returns the Puppet signature of the function.
62
64
  def signature
63
65
  return '' if self.has_tag? :overload
66
+
64
67
  tags = self.tags(:param)
65
68
  args = @parameters.map do |parameter|
66
69
  name, default = parameter
67
70
  tag = tags.find { |t| t.name == name } if tags
68
- type = tag && tag.types ? "#{tag.type} " : 'Any '
71
+ type = tag&.types ? "#{tag.type} " : 'Any '
69
72
  prefix = "#{name[0]}" if name.start_with?('*', '&')
70
73
  name = name[1..-1] if prefix
71
74
  default = " = #{default}" if default
@@ -96,8 +99,8 @@ class PuppetStrings::Yard::CodeObjects::Function < PuppetStrings::Yard::CodeObje
96
99
 
97
100
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
98
101
  defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
99
- hash[:defaults] = defaults unless defaults.empty?
100
- hash[:source] = source unless source && source.empty?
102
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
103
+ hash[:source] = source unless source.nil? || source.empty?
101
104
  hash
102
105
  end
103
106
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/base'
2
4
 
3
5
  # Implements the base class for "groups".
@@ -10,6 +12,7 @@ class PuppetStrings::Yard::CodeObjects::Group < PuppetStrings::Yard::CodeObjects
10
12
  def self.instance(key)
11
13
  instance = P(:root, key)
12
14
  return instance unless instance.is_a?(YARD::CodeObjects::Proxy)
15
+
13
16
  instance = self.new(:root, key)
14
17
  instance.visibility = :hidden
15
18
  P(:root).children << instance
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  class PuppetStrings::Yard::CodeObjects::Plans < PuppetStrings::Yard::CodeObjects::Group
@@ -49,8 +51,8 @@ class PuppetStrings::Yard::CodeObjects::Plan < PuppetStrings::Yard::CodeObjects:
49
51
  hash[:line] = line
50
52
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
51
53
  defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
52
- hash[:defaults] = defaults unless defaults.empty?
53
- hash[:source] = source unless source && source.empty?
54
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
55
+ hash[:source] = source unless source.nil? || source.empty?
54
56
  hash
55
57
  end
56
58
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet providers.
@@ -42,6 +44,7 @@ class PuppetStrings::Yard::CodeObjects::Provider < PuppetStrings::Yard::CodeObje
42
44
  # @return [void]
43
45
  def add_confine(key, value)
44
46
  return unless key && value
47
+
45
48
  @confines ||= {}
46
49
  @confines[key] = value
47
50
  end
@@ -51,6 +54,7 @@ class PuppetStrings::Yard::CodeObjects::Provider < PuppetStrings::Yard::CodeObje
51
54
  # @return [void]
52
55
  def add_feature(feature)
53
56
  return unless feature
57
+
54
58
  @features ||= []
55
59
  @features << feature
56
60
  end
@@ -60,6 +64,7 @@ class PuppetStrings::Yard::CodeObjects::Provider < PuppetStrings::Yard::CodeObje
60
64
  # @return [void]
61
65
  def add_default(constraints)
62
66
  return unless constraints
67
+
63
68
  @defaults ||= []
64
69
  @defaults << constraints
65
70
  end
@@ -70,6 +75,7 @@ class PuppetStrings::Yard::CodeObjects::Provider < PuppetStrings::Yard::CodeObje
70
75
  # @return [void]
71
76
  def add_command(key, value)
72
77
  return unless key && value
78
+
73
79
  @commands ||= {}
74
80
  @commands[key] = value
75
81
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet tasks.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
  require 'puppet-strings/yard/util'
3
5
 
@@ -73,6 +75,9 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
73
75
  class Property < Parameter
74
76
  end
75
77
 
78
+ class Check < Parameter
79
+ end
80
+
76
81
  # Represents a resource type feature.
77
82
  class Feature
78
83
  attr_reader :name, :docstring
@@ -95,7 +100,7 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
95
100
  end
96
101
  end
97
102
 
98
- attr_reader :properties, :parameters, :features
103
+ attr_reader :properties, :features, :checks
99
104
 
100
105
  # Initializes a new resource type.
101
106
  # @param [String] name The resource type name.
@@ -134,17 +139,57 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
134
139
  @features << feature
135
140
  end
136
141
 
142
+ # Adds a check to the resource type.
143
+ # @param [PuppetStrings::Yard::CodeObjects::Type::Check] check The check to add.
144
+ # @return [void]
145
+ def add_check(check)
146
+ @checks ||= []
147
+ @checks << check
148
+ end
149
+
150
+ def parameters
151
+ # just return params if there are no providers
152
+ return @parameters if providers.empty?
153
+
154
+ # return existing params if we have already added provider
155
+ return @parameters if @parameters&.any? { |p| p.name == 'provider' }
156
+
157
+ provider_param = Parameter.new(
158
+ 'provider',
159
+ "The specific backend to use for this `#{self.name.to_s}` resource. You will seldom need " + \
160
+ "to specify this --- Puppet will usually discover the appropriate provider for your platform."
161
+ )
162
+
163
+ @parameters ||= []
164
+ @parameters << provider_param
165
+ end
166
+
167
+ # Not sure if this is where this belongs or if providers should only be resolved at
168
+ # render-time. For now, this should re-resolve on every call.
169
+ # may be able to memoize this
170
+ def providers
171
+ providers = YARD::Registry.all("puppet_providers_#{name}".intern)
172
+ return providers if providers.empty?
173
+
174
+ providers.first.children
175
+ end
176
+
137
177
  # Converts the code object to a hash representation.
138
178
  # @return [Hash] Returns a hash representation of the code object.
139
179
  def to_hash
140
180
  hash = {}
181
+
141
182
  hash[:name] = name
142
183
  hash[:file] = file
143
184
  hash[:line] = line
144
- hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
145
- hash[:properties] = properties.map(&:to_hash) if properties && !properties.empty?
146
- hash[:parameters] = parameters.map(&:to_hash) if parameters && !parameters.empty?
147
- hash[:features] = features.map(&:to_hash) if features && !features.empty?
185
+
186
+ hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
187
+ hash[:properties] = properties.sort_by { |p| p.name }.map(&:to_hash) if properties && !properties.empty?
188
+ hash[:parameters] = parameters.sort_by { |p| p.name }.map(&:to_hash) if parameters && !parameters.empty?
189
+ hash[:checks] = checks.sort_by { |c| c.name }.map(&:to_hash) if checks && !checks.empty?
190
+ hash[:features] = features.sort_by { |f| f.name }.map(&:to_hash) if features && !features.empty?
191
+ hash[:providers] = providers.sort_by { |p| p.name }.map(&:to_hash) if providers && !providers.empty?
192
+
148
193
  hash
149
194
  end
150
195
  end