openvox-strings 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +407 -0
  3. data/LICENSE +177 -0
  4. data/README.md +116 -0
  5. data/lib/openvox-strings/describe.rb +75 -0
  6. data/lib/openvox-strings/json.rb +33 -0
  7. data/lib/openvox-strings/markdown/base.rb +236 -0
  8. data/lib/openvox-strings/markdown/data_type.rb +39 -0
  9. data/lib/openvox-strings/markdown/defined_type.rb +20 -0
  10. data/lib/openvox-strings/markdown/function.rb +59 -0
  11. data/lib/openvox-strings/markdown/helpers.rb +21 -0
  12. data/lib/openvox-strings/markdown/puppet_class.rb +20 -0
  13. data/lib/openvox-strings/markdown/puppet_plan.rb +20 -0
  14. data/lib/openvox-strings/markdown/puppet_task.rb +29 -0
  15. data/lib/openvox-strings/markdown/resource_type.rb +56 -0
  16. data/lib/openvox-strings/markdown/templates/classes_and_defines.erb +94 -0
  17. data/lib/openvox-strings/markdown/templates/data_type.erb +101 -0
  18. data/lib/openvox-strings/markdown/templates/data_type_function.erb +67 -0
  19. data/lib/openvox-strings/markdown/templates/function.erb +106 -0
  20. data/lib/openvox-strings/markdown/templates/puppet_task.erb +28 -0
  21. data/lib/openvox-strings/markdown/templates/resource_type.erb +156 -0
  22. data/lib/openvox-strings/markdown/templates/table_of_contents.erb +26 -0
  23. data/lib/openvox-strings/markdown.rb +81 -0
  24. data/lib/openvox-strings/monkey_patches/display_object_command.rb +16 -0
  25. data/lib/openvox-strings/tasks/generate.rb +54 -0
  26. data/lib/openvox-strings/tasks/gh_pages.rb +72 -0
  27. data/lib/openvox-strings/tasks/validate.rb +42 -0
  28. data/lib/openvox-strings/tasks.rb +14 -0
  29. data/lib/openvox-strings/version.rb +5 -0
  30. data/lib/openvox-strings/yard/code_objects/base.rb +16 -0
  31. data/lib/openvox-strings/yard/code_objects/class.rb +60 -0
  32. data/lib/openvox-strings/yard/code_objects/data_type.rb +102 -0
  33. data/lib/openvox-strings/yard/code_objects/data_type_alias.rb +60 -0
  34. data/lib/openvox-strings/yard/code_objects/defined_type.rb +59 -0
  35. data/lib/openvox-strings/yard/code_objects/function.rb +106 -0
  36. data/lib/openvox-strings/yard/code_objects/group.rb +33 -0
  37. data/lib/openvox-strings/yard/code_objects/plan.rb +59 -0
  38. data/lib/openvox-strings/yard/code_objects/provider.rb +98 -0
  39. data/lib/openvox-strings/yard/code_objects/task.rb +69 -0
  40. data/lib/openvox-strings/yard/code_objects/type.rb +196 -0
  41. data/lib/openvox-strings/yard/code_objects.rb +14 -0
  42. data/lib/openvox-strings/yard/handlers/helpers.rb +10 -0
  43. data/lib/openvox-strings/yard/handlers/json/base.rb +8 -0
  44. data/lib/openvox-strings/yard/handlers/json/task_handler.rb +34 -0
  45. data/lib/openvox-strings/yard/handlers/puppet/base.rb +52 -0
  46. data/lib/openvox-strings/yard/handlers/puppet/class_handler.rb +29 -0
  47. data/lib/openvox-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
  48. data/lib/openvox-strings/yard/handlers/puppet/defined_type_handler.rb +29 -0
  49. data/lib/openvox-strings/yard/handlers/puppet/function_handler.rb +54 -0
  50. data/lib/openvox-strings/yard/handlers/puppet/plan_handler.rb +29 -0
  51. data/lib/openvox-strings/yard/handlers/ruby/base.rb +55 -0
  52. data/lib/openvox-strings/yard/handlers/ruby/data_type_handler.rb +411 -0
  53. data/lib/openvox-strings/yard/handlers/ruby/function_handler.rb +386 -0
  54. data/lib/openvox-strings/yard/handlers/ruby/provider_handler.rb +127 -0
  55. data/lib/openvox-strings/yard/handlers/ruby/rsapi_handler.rb +157 -0
  56. data/lib/openvox-strings/yard/handlers/ruby/type_base.rb +146 -0
  57. data/lib/openvox-strings/yard/handlers/ruby/type_extras_handler.rb +65 -0
  58. data/lib/openvox-strings/yard/handlers/ruby/type_handler.rb +105 -0
  59. data/lib/openvox-strings/yard/handlers.rb +28 -0
  60. data/lib/openvox-strings/yard/parsers/json/parser.rb +38 -0
  61. data/lib/openvox-strings/yard/parsers/json/task_statement.rb +37 -0
  62. data/lib/openvox-strings/yard/parsers/puppet/parser.rb +89 -0
  63. data/lib/openvox-strings/yard/parsers/puppet/statement.rb +182 -0
  64. data/lib/openvox-strings/yard/parsers.rb +14 -0
  65. data/lib/openvox-strings/yard/tags/enum_tag.rb +13 -0
  66. data/lib/openvox-strings/yard/tags/factory.rb +18 -0
  67. data/lib/openvox-strings/yard/tags/overload_tag.rb +112 -0
  68. data/lib/openvox-strings/yard/tags/parameter_directive.rb +25 -0
  69. data/lib/openvox-strings/yard/tags/property_directive.rb +25 -0
  70. data/lib/openvox-strings/yard/tags/summary_tag.rb +10 -0
  71. data/lib/openvox-strings/yard/tags.rb +11 -0
  72. data/lib/openvox-strings/yard/templates/default/fulldoc/html/css/common.css +8 -0
  73. data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb +9 -0
  74. data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
  75. data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb +9 -0
  76. data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb +10 -0
  77. data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_plan.erb +9 -0
  78. data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +10 -0
  79. data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_task.erb +9 -0
  80. data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +9 -0
  81. data/lib/openvox-strings/yard/templates/default/fulldoc/html/setup.rb +93 -0
  82. data/lib/openvox-strings/yard/templates/default/layout/html/footer.erb +3 -0
  83. data/lib/openvox-strings/yard/templates/default/layout/html/objects.erb +37 -0
  84. data/lib/openvox-strings/yard/templates/default/layout/html/setup.rb +231 -0
  85. data/lib/openvox-strings/yard/templates/default/puppet_class/html/box_info.erb +26 -0
  86. data/lib/openvox-strings/yard/templates/default/puppet_class/html/deprecated.erb +6 -0
  87. data/lib/openvox-strings/yard/templates/default/puppet_class/html/header.erb +1 -0
  88. data/lib/openvox-strings/yard/templates/default/puppet_class/html/note.erb +6 -0
  89. data/lib/openvox-strings/yard/templates/default/puppet_class/html/overview.erb +6 -0
  90. data/lib/openvox-strings/yard/templates/default/puppet_class/html/setup.rb +16 -0
  91. data/lib/openvox-strings/yard/templates/default/puppet_class/html/source.erb +12 -0
  92. data/lib/openvox-strings/yard/templates/default/puppet_class/html/summary.erb +4 -0
  93. data/lib/openvox-strings/yard/templates/default/puppet_class/html/todo.erb +6 -0
  94. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
  95. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/deprecated.erb +6 -0
  96. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
  97. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  98. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
  99. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
  100. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/setup.rb +15 -0
  101. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
  102. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
  103. data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
  104. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
  105. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
  106. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/deprecated.erb +6 -0
  107. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
  108. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
  109. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
  110. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +19 -0
  111. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
  112. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
  113. data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
  114. data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/box_info.erb +10 -0
  115. data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/deprecated.erb +6 -0
  116. data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/header.erb +1 -0
  117. data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/note.erb +6 -0
  118. data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/overview.erb +6 -0
  119. data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/setup.rb +7 -0
  120. data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/source.erb +12 -0
  121. data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/summary.erb +4 -0
  122. data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/todo.erb +6 -0
  123. data/lib/openvox-strings/yard/templates/default/puppet_function/html/box_info.erb +14 -0
  124. data/lib/openvox-strings/yard/templates/default/puppet_function/html/deprecated.erb +6 -0
  125. data/lib/openvox-strings/yard/templates/default/puppet_function/html/header.erb +1 -0
  126. data/lib/openvox-strings/yard/templates/default/puppet_function/html/note.erb +6 -0
  127. data/lib/openvox-strings/yard/templates/default/puppet_function/html/overview.erb +18 -0
  128. data/lib/openvox-strings/yard/templates/default/puppet_function/html/setup.rb +7 -0
  129. data/lib/openvox-strings/yard/templates/default/puppet_function/html/source.erb +12 -0
  130. data/lib/openvox-strings/yard/templates/default/puppet_function/html/summary.erb +4 -0
  131. data/lib/openvox-strings/yard/templates/default/puppet_function/html/todo.erb +6 -0
  132. data/lib/openvox-strings/yard/templates/default/puppet_plan/html/box_info.erb +10 -0
  133. data/lib/openvox-strings/yard/templates/default/puppet_plan/html/deprecated.erb +6 -0
  134. data/lib/openvox-strings/yard/templates/default/puppet_plan/html/header.erb +1 -0
  135. data/lib/openvox-strings/yard/templates/default/puppet_plan/html/note.erb +6 -0
  136. data/lib/openvox-strings/yard/templates/default/puppet_plan/html/overview.erb +6 -0
  137. data/lib/openvox-strings/yard/templates/default/puppet_plan/html/setup.rb +13 -0
  138. data/lib/openvox-strings/yard/templates/default/puppet_plan/html/source.erb +12 -0
  139. data/lib/openvox-strings/yard/templates/default/puppet_plan/html/summary.erb +4 -0
  140. data/lib/openvox-strings/yard/templates/default/puppet_plan/html/todo.erb +6 -0
  141. data/lib/openvox-strings/yard/templates/default/puppet_provider/html/box_info.erb +14 -0
  142. data/lib/openvox-strings/yard/templates/default/puppet_provider/html/collection.erb +17 -0
  143. data/lib/openvox-strings/yard/templates/default/puppet_provider/html/features.erb +12 -0
  144. data/lib/openvox-strings/yard/templates/default/puppet_provider/html/header.erb +1 -0
  145. data/lib/openvox-strings/yard/templates/default/puppet_provider/html/overview.erb +6 -0
  146. data/lib/openvox-strings/yard/templates/default/puppet_provider/html/setup.rb +31 -0
  147. data/lib/openvox-strings/yard/templates/default/puppet_provider/html/summary.erb +4 -0
  148. data/lib/openvox-strings/yard/templates/default/puppet_task/html/box_info.erb +9 -0
  149. data/lib/openvox-strings/yard/templates/default/puppet_task/html/header.erb +1 -0
  150. data/lib/openvox-strings/yard/templates/default/puppet_task/html/input.erb +5 -0
  151. data/lib/openvox-strings/yard/templates/default/puppet_task/html/overview.erb +6 -0
  152. data/lib/openvox-strings/yard/templates/default/puppet_task/html/parameters.erb +16 -0
  153. data/lib/openvox-strings/yard/templates/default/puppet_task/html/setup.rb +24 -0
  154. data/lib/openvox-strings/yard/templates/default/puppet_task/html/supports_noop.erb +3 -0
  155. data/lib/openvox-strings/yard/templates/default/puppet_type/html/box_info.erb +20 -0
  156. data/lib/openvox-strings/yard/templates/default/puppet_type/html/deprecated.erb +6 -0
  157. data/lib/openvox-strings/yard/templates/default/puppet_type/html/features.erb +13 -0
  158. data/lib/openvox-strings/yard/templates/default/puppet_type/html/header.erb +1 -0
  159. data/lib/openvox-strings/yard/templates/default/puppet_type/html/note.erb +6 -0
  160. data/lib/openvox-strings/yard/templates/default/puppet_type/html/overview.erb +6 -0
  161. data/lib/openvox-strings/yard/templates/default/puppet_type/html/parameters.erb +35 -0
  162. data/lib/openvox-strings/yard/templates/default/puppet_type/html/setup.rb +36 -0
  163. data/lib/openvox-strings/yard/templates/default/puppet_type/html/summary.erb +4 -0
  164. data/lib/openvox-strings/yard/templates/default/puppet_type/html/todo.erb +6 -0
  165. data/lib/openvox-strings/yard/templates/default/tags/html/enum.erb +17 -0
  166. data/lib/openvox-strings/yard/templates/default/tags/html/puppet_overload.erb +12 -0
  167. data/lib/openvox-strings/yard/templates/default/tags/setup.rb +20 -0
  168. data/lib/openvox-strings/yard/util.rb +87 -0
  169. data/lib/openvox-strings/yard.rb +132 -0
  170. data/lib/openvox-strings.rb +88 -0
  171. data/lib/puppet/application/strings.rb +7 -0
  172. data/lib/puppet/face/strings.rb +185 -0
  173. data/lib/puppet/feature/rgen.rb +5 -0
  174. data/lib/puppet/feature/yard.rb +5 -0
  175. metadata +263 -0
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openvox-strings/yard/code_objects/group'
4
+
5
+ # Implements the group for Puppet functions.
6
+ class OpenvoxStrings::Yard::CodeObjects::Functions < OpenvoxStrings::Yard::CodeObjects::Group
7
+ # Gets the singleton instance of the group.
8
+ # @param [Symbol] type The function type to get the group for.
9
+ # @return Returns the singleton instance of the group.
10
+ def self.instance(type)
11
+ super(:"puppet_functions_#{type}")
12
+ end
13
+
14
+ # Gets the display name of the group.
15
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
16
+ # @return [String] Returns the display name of the group.
17
+ def name(_prefix = false)
18
+ 'Puppet Functions'
19
+ end
20
+ end
21
+
22
+ # Implements the Puppet function code object.
23
+ class OpenvoxStrings::Yard::CodeObjects::Function < OpenvoxStrings::Yard::CodeObjects::Base
24
+ # Identifier for 3.x Ruby API functions
25
+ RUBY_3X = :ruby3x
26
+ # Identifier for 4.x Ruby API functions
27
+ RUBY_4X = :ruby4x
28
+ # Identifier for Puppet language functions
29
+ PUPPET = :puppet
30
+
31
+ attr_accessor :parameters
32
+
33
+ # Initializes a Puppet function code object.
34
+ # @param [String] name The name of the function.
35
+ # @param [Symbol] function_type The type of function (e.g. :ruby3x, :ruby4x, :puppet)
36
+ # @return [void]
37
+ def initialize(name, function_type)
38
+ super(OpenvoxStrings::Yard::CodeObjects::Functions.instance(function_type), name)
39
+ @parameters = []
40
+ @function_type = function_type
41
+ end
42
+
43
+ # Gets the type of the code object.
44
+ # @return Returns the type of the code object.
45
+ def type
46
+ :puppet_function
47
+ end
48
+
49
+ # Gets the function type display string.
50
+ # @return Returns the function type display string.
51
+ def function_type
52
+ case @function_type
53
+ when RUBY_3X
54
+ 'Ruby 3.x API'
55
+ when RUBY_4X
56
+ 'Ruby 4.x API'
57
+ else
58
+ 'Puppet Language'
59
+ end
60
+ end
61
+
62
+ # Gets the Puppet signature of the function (single overload only).
63
+ # @return [String] Returns the Puppet signature of the function.
64
+ def signature
65
+ return '' if has_tag? :overload
66
+
67
+ tags = self.tags(:param)
68
+ args = @parameters.map do |parameter|
69
+ name, default = parameter
70
+ tag = tags.find { |t| t.name == name } if tags
71
+ type = tag&.types ? "#{tag.type} " : 'Any '
72
+ prefix = name[0].to_s if name.start_with?('*', '&')
73
+ name = name[1..] if prefix
74
+ default = " = #{default}" if default
75
+ "#{type}#{prefix}$#{name}#{default}"
76
+ end.join(', ')
77
+ "#{@name}(#{args})"
78
+ end
79
+
80
+ # Converts the code object to a hash representation.
81
+ # @return [Hash] Returns a hash representation of the code object.
82
+ def to_hash
83
+ hash = {}
84
+
85
+ hash[:name] = name
86
+ hash[:file] = file
87
+ hash[:line] = line
88
+ hash[:type] = @function_type.to_s
89
+ hash[:signatures] = []
90
+
91
+ if has_tag? :overload
92
+ # loop over overloads and append onto the signatures array
93
+ tags(:overload).each do |o|
94
+ hash[:signatures] << { signature: o.signature, docstring: OpenvoxStrings::Yard::Util.docstring_to_hash(o.docstring, %i[param option enum return example]) }
95
+ end
96
+ else
97
+ hash[:signatures] << { signature: signature, docstring: OpenvoxStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example]) }
98
+ end
99
+
100
+ hash[:docstring] = OpenvoxStrings::Yard::Util.docstring_to_hash(docstring)
101
+ defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten]
102
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
103
+ hash[:source] = source unless source.nil? || source.empty?
104
+ hash
105
+ end
106
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openvox-strings/yard/code_objects/base'
4
+
5
+ # Implements the base class for "groups".
6
+ #
7
+ # A group behaves like a YARD namespace object, but displays differently in the HTML output.
8
+ class OpenvoxStrings::Yard::CodeObjects::Group < OpenvoxStrings::Yard::CodeObjects::Base
9
+ # Gets the singleton instance of the group.
10
+ # @param [Symbol] key The key to lookup the group for.
11
+ # @return Returns the singleton instance of the group.
12
+ def self.instance(key)
13
+ instance = P(:root, key)
14
+ return instance unless instance.is_a?(YARD::CodeObjects::Proxy)
15
+
16
+ instance = new(:root, key)
17
+ instance.visibility = :hidden
18
+ P(:root).children << instance
19
+ instance
20
+ end
21
+
22
+ # Gets the path to the group.
23
+ # @return [String] Returns the path to the group.
24
+ def path
25
+ @name.to_s
26
+ end
27
+
28
+ # Gets the type of the group.
29
+ # @return [Symbol] Returns the type of the group.
30
+ def type
31
+ @name
32
+ end
33
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openvox-strings/yard/code_objects/group'
4
+
5
+ # Implements the group for Puppet plans.
6
+ class OpenvoxStrings::Yard::CodeObjects::Plans < OpenvoxStrings::Yard::CodeObjects::Group
7
+ # Gets the singleton instance of the group.
8
+ # @return Returns the singleton instance of the group.
9
+ def self.instance
10
+ super(:puppet_plans)
11
+ end
12
+
13
+ # Gets the display name of the group.
14
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
15
+ # @return [String] Returns the display name of the group.
16
+ def name(_prefix = false)
17
+ 'Puppet Plans'
18
+ end
19
+ end
20
+
21
+ # Implements the Puppet plan code object.
22
+ class OpenvoxStrings::Yard::CodeObjects::Plan < OpenvoxStrings::Yard::CodeObjects::Base
23
+ attr_reader :statement, :parameters
24
+
25
+ # Initializes a Puppet plan code object.
26
+ # @param [OpenvoxStrings::Parsers::PlanStatement] statement The plan statement that was parsed.
27
+ # @return [void]
28
+ def initialize(statement)
29
+ @statement = statement
30
+ @parameters = statement.parameters.map { |p| [p.name, p.value] }
31
+ super(OpenvoxStrings::Yard::CodeObjects::Plans.instance, statement.name)
32
+ end
33
+
34
+ # Gets the type of the code object.
35
+ # @return Returns the type of the code object.
36
+ def type
37
+ :puppet_plan
38
+ end
39
+
40
+ # Gets the source of the code object.
41
+ # @return Returns the source of the code object.
42
+ def source
43
+ @statement.source
44
+ end
45
+
46
+ # Converts the code object to a hash representation.
47
+ # @return [Hash] Returns a hash representation of the code object.
48
+ def to_hash
49
+ hash = {}
50
+ hash[:name] = name
51
+ hash[:file] = file
52
+ hash[:line] = line
53
+ hash[:docstring] = OpenvoxStrings::Yard::Util.docstring_to_hash(docstring)
54
+ defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten]
55
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
56
+ hash[:source] = source unless source.nil? || source.empty?
57
+ hash
58
+ end
59
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openvox-strings/yard/code_objects/group'
4
+
5
+ # Implements the group for Puppet providers.
6
+ class OpenvoxStrings::Yard::CodeObjects::Providers < OpenvoxStrings::Yard::CodeObjects::Group
7
+ # Gets the singleton instance of the group.
8
+ # @param [String] type The resource type name for the provider.
9
+ # @return Returns the singleton instance of the group.
10
+ def self.instance(type)
11
+ super(:"puppet_providers_#{type}")
12
+ end
13
+
14
+ # Gets the display name of the group.
15
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
16
+ # @return [String] Returns the display name of the group.
17
+ def name(_prefix = false)
18
+ 'Providers'
19
+ end
20
+ end
21
+
22
+ # Implements the Puppet provider code object.
23
+ class OpenvoxStrings::Yard::CodeObjects::Provider < OpenvoxStrings::Yard::CodeObjects::Base
24
+ attr_reader :type_name, :confines, :features, :defaults, :commands
25
+
26
+ # Initializes a Puppet provider code object.
27
+ # @param [String] type_name The resource type name for the provider.
28
+ # @param [String] name The name of the provider.s
29
+ # @return [void]
30
+ def initialize(type_name, name)
31
+ @type_name = type_name
32
+ super(OpenvoxStrings::Yard::CodeObjects::Providers.instance(type_name), name)
33
+ end
34
+
35
+ # Gets the type of the code object.
36
+ # @return Returns the type of the code object.
37
+ def type
38
+ :puppet_provider
39
+ end
40
+
41
+ # Adds a confine to the provider.
42
+ # @param [String] key The confine's key.
43
+ # @param [String] value The confine's value.
44
+ # @return [void]
45
+ def add_confine(key, value)
46
+ return unless key && value
47
+
48
+ @confines ||= {}
49
+ @confines[key] = value
50
+ end
51
+
52
+ # Adds a feature to the provider.
53
+ # @param [String] feature The feature to add to the provider.
54
+ # @return [void]
55
+ def add_feature(feature)
56
+ return unless feature
57
+
58
+ @features ||= []
59
+ @features << feature
60
+ end
61
+
62
+ # Adds a default to the provider.
63
+ # @param [Array] constraints List of related key-pair values for the default.
64
+ # @return [void]
65
+ def add_default(constraints)
66
+ return unless constraints
67
+
68
+ @defaults ||= []
69
+ @defaults << constraints
70
+ end
71
+
72
+ # Adds a command to the provider.
73
+ # @param [String] key The command's key.
74
+ # @param [String] value The command's value.
75
+ # @return [void]
76
+ def add_command(key, value)
77
+ return unless key && value
78
+
79
+ @commands ||= {}
80
+ @commands[key] = value
81
+ end
82
+
83
+ # Converts the code object to a hash representation.
84
+ # @return [Hash] Returns a hash representation of the code object.
85
+ def to_hash
86
+ hash = {}
87
+ hash[:name] = name
88
+ hash[:type_name] = type_name
89
+ hash[:file] = file
90
+ hash[:line] = line
91
+ hash[:docstring] = OpenvoxStrings::Yard::Util.docstring_to_hash(docstring)
92
+ hash[:confines] = confines if confines && !confines.empty?
93
+ hash[:features] = features if features && !features.empty?
94
+ hash[:defaults] = defaults if defaults && !defaults.empty?
95
+ hash[:commands] = commands if commands && !commands.empty?
96
+ hash
97
+ end
98
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openvox-strings/yard/code_objects/group'
4
+
5
+ # Implements the group for Puppet tasks.
6
+ class OpenvoxStrings::Yard::CodeObjects::Tasks < OpenvoxStrings::Yard::CodeObjects::Group
7
+ # Gets the singleton instance of the group.
8
+ # @return Returns the singleton instance of the group.
9
+ def self.instance
10
+ super(:puppet_tasks)
11
+ end
12
+
13
+ # Gets the display name of the group.
14
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
15
+ # @return [String] Returns the display name of the group.
16
+ def name(_prefix = false)
17
+ 'Puppet Tasks'
18
+ end
19
+ end
20
+
21
+ # Implements the Puppet task code object.
22
+ class OpenvoxStrings::Yard::CodeObjects::Task < OpenvoxStrings::Yard::CodeObjects::Base
23
+ attr_reader :statement
24
+
25
+ # Initializes a JSON task code object.
26
+ # @param statement TaskStatement object
27
+ # @return [void]
28
+ def initialize(statement)
29
+ @name = statement.name
30
+ @statement = statement
31
+ super(OpenvoxStrings::Yard::CodeObjects::Tasks.instance, name)
32
+ end
33
+
34
+ # Gets the type of the code object.
35
+ # @return Returns the type of the code object.
36
+ def type
37
+ :puppet_task
38
+ end
39
+
40
+ # Gets the source of the code object.
41
+ # @return Returns the source of the code object.
42
+ def source
43
+ @statement.source
44
+ end
45
+
46
+ def parameters
47
+ statement.parameters.map do |name, props|
48
+ { name: name.to_s,
49
+ tag_name: 'param',
50
+ text: props['description'] || '',
51
+ types: [props['type']] || '' }
52
+ end
53
+ end
54
+
55
+ # Converts the code object to a hash representation.
56
+ # @return [Hash] Returns a hash representation of the code object.
57
+ def to_hash
58
+ { name: name.to_s,
59
+ file: statement.file,
60
+ line: statement.line,
61
+ docstring: {
62
+ text: statement.docstring,
63
+ tags: parameters
64
+ },
65
+ source: statement.source,
66
+ supports_noop: statement.json['supports_noop'] || false,
67
+ input_method: statement.json['input_method'] }
68
+ end
69
+ end
@@ -0,0 +1,196 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openvox-strings/yard/code_objects/group'
4
+ require 'openvox-strings/yard/util'
5
+
6
+ # Implements the group for Puppet resource types.
7
+ class OpenvoxStrings::Yard::CodeObjects::Types < OpenvoxStrings::Yard::CodeObjects::Group
8
+ # Gets the singleton instance of the group.
9
+ # @return Returns the singleton instance of the group.
10
+ def self.instance
11
+ super(:puppet_types)
12
+ end
13
+
14
+ # Gets the display name of the group.
15
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
16
+ # @return [String] Returns the display name of the group.
17
+ def name(_prefix = false)
18
+ 'Resource Types'
19
+ end
20
+ end
21
+
22
+ # Implements the Puppet resource type code object.
23
+ class OpenvoxStrings::Yard::CodeObjects::Type < OpenvoxStrings::Yard::CodeObjects::Base
24
+ # Represents a resource type parameter.
25
+ class Parameter
26
+ attr_reader :name, :values, :aliases
27
+ attr_accessor :docstring, :isnamevar, :default, :data_type, :required_features
28
+
29
+ # Initializes a resource type parameter or property.
30
+ # @param [String] name The name of the parameter or property.
31
+ # @param [String] docstring The docstring for the parameter or property.s
32
+ def initialize(name, docstring = nil)
33
+ @name = name
34
+ @docstring = docstring || ''
35
+ @values = []
36
+ @data_type = []
37
+ @aliases = {}
38
+ @isnamevar = false
39
+ @default = nil
40
+ end
41
+
42
+ # Adds a value to the parameter or property.
43
+ # @param [String] value The value to add.
44
+ # @return [void]
45
+ def add(value)
46
+ @values << value
47
+ end
48
+
49
+ # Aliases a value to another value.
50
+ # @param [String] new The new (alias) value.
51
+ # @param [String] old The old (existing) value.
52
+ # @return [void]
53
+ def alias(new, old)
54
+ @values << new unless @values.include? new
55
+ @aliases[new] = old
56
+ end
57
+
58
+ # Converts the parameter to a hash representation.
59
+ # @return [Hash] Returns a hash representation of the parameter.
60
+ def to_hash
61
+ hash = {}
62
+ hash[:name] = name
63
+ hash[:description] = docstring unless docstring.empty?
64
+ hash[:values] = values unless values.empty?
65
+ hash[:data_type] = data_type unless data_type.empty?
66
+ hash[:aliases] = aliases unless aliases.empty?
67
+ hash[:isnamevar] = true if isnamevar
68
+ hash[:required_features] = required_features if required_features
69
+ hash[:default] = default if default
70
+ hash
71
+ end
72
+ end
73
+
74
+ # Represents a resource type property (same attributes as a parameter).
75
+ class Property < Parameter
76
+ end
77
+
78
+ class Check < Parameter
79
+ end
80
+
81
+ # Represents a resource type feature.
82
+ class Feature
83
+ attr_reader :name, :docstring
84
+
85
+ # Initializes a new feature.
86
+ # @param [String] name The name of the feature.
87
+ # @param [String] docstring The docstring of the feature.
88
+ def initialize(name, docstring)
89
+ @name = name
90
+ @docstring = OpenvoxStrings::Yard::Util.scrub_string(docstring).tr("\n", ' ')
91
+ end
92
+
93
+ # Converts the feature to a hash representation.
94
+ # @return [Hash] Returns a hash representation of the feature.
95
+ def to_hash
96
+ hash = {}
97
+ hash[:name] = name
98
+ hash[:description] = docstring unless docstring.empty?
99
+ hash
100
+ end
101
+ end
102
+
103
+ attr_reader :properties, :features, :checks
104
+
105
+ # Initializes a new resource type.
106
+ # @param [String] name The resource type name.
107
+ # @return [void]
108
+ def initialize(name)
109
+ super(OpenvoxStrings::Yard::CodeObjects::Types.instance, name)
110
+ end
111
+
112
+ # Gets the type of the code object.
113
+ # @return Returns the type of the code object.
114
+ def type
115
+ :puppet_type
116
+ end
117
+
118
+ # Adds a parameter to the resource type
119
+ # @param [OpenvoxStrings::Yard::CodeObjects::Type::Parameter] parameter The parameter to add.
120
+ # @return [void]
121
+ def add_parameter(parameter)
122
+ @parameters ||= []
123
+ @parameters << parameter
124
+ end
125
+
126
+ # Adds a property to the resource type
127
+ # @param [OpenvoxStrings::Yard::CodeObjects::Type::Property] property The property to add.
128
+ # @return [void]
129
+ def add_property(property)
130
+ @properties ||= []
131
+ @properties << property
132
+ end
133
+
134
+ # Adds a feature to the resource type.
135
+ # @param [OpenvoxStrings::Yard::CodeObjects::Type::Feature] feature The feature to add.
136
+ # @return [void]
137
+ def add_feature(feature)
138
+ @features ||= []
139
+ @features << feature
140
+ end
141
+
142
+ # Adds a check to the resource type.
143
+ # @param [OpenvoxStrings::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
+ @parameters ||= [] # guard against not filled parameters
152
+ # just return params if there are no providers
153
+ return @parameters if providers.empty?
154
+
155
+ # return existing params if we have already added provider
156
+ return @parameters if @parameters&.any? { |p| p.name == 'provider' }
157
+
158
+ provider_param = Parameter.new(
159
+ 'provider',
160
+ "The specific backend to use for this `#{name}` resource. You will seldom need " \
161
+ 'to specify this --- Puppet will usually discover the appropriate provider for your platform.'
162
+ )
163
+
164
+ @parameters ||= []
165
+ @parameters << provider_param
166
+ end
167
+
168
+ # Not sure if this is where this belongs or if providers should only be resolved at
169
+ # render-time. For now, this should re-resolve on every call.
170
+ # may be able to memoize this
171
+ def providers
172
+ providers = YARD::Registry.all(:"puppet_providers_#{name}")
173
+ return providers if providers.empty?
174
+
175
+ providers.first.children
176
+ end
177
+
178
+ # Converts the code object to a hash representation.
179
+ # @return [Hash] Returns a hash representation of the code object.
180
+ def to_hash
181
+ hash = {}
182
+
183
+ hash[:name] = name
184
+ hash[:file] = file
185
+ hash[:line] = line
186
+
187
+ hash[:docstring] = OpenvoxStrings::Yard::Util.docstring_to_hash(docstring)
188
+ hash[:properties] = properties.sort_by(&:name).map(&:to_hash) if properties && !properties.empty?
189
+ hash[:parameters] = parameters.sort_by(&:name).map(&:to_hash) if parameters && !parameters.empty?
190
+ hash[:checks] = checks.sort_by(&:name).map(&:to_hash) if checks && !checks.empty?
191
+ hash[:features] = features.sort_by(&:name).map(&:to_hash) if features && !features.empty?
192
+ hash[:providers] = providers.sort_by(&:name).map(&:to_hash) if providers && !providers.empty?
193
+
194
+ hash
195
+ end
196
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The module for custom YARD code objects.
4
+ module OpenvoxStrings::Yard::CodeObjects
5
+ require 'openvox-strings/yard/code_objects/class'
6
+ require 'openvox-strings/yard/code_objects/data_type'
7
+ require 'openvox-strings/yard/code_objects/data_type_alias'
8
+ require 'openvox-strings/yard/code_objects/defined_type'
9
+ require 'openvox-strings/yard/code_objects/type'
10
+ require 'openvox-strings/yard/code_objects/provider'
11
+ require 'openvox-strings/yard/code_objects/function'
12
+ require 'openvox-strings/yard/code_objects/task'
13
+ require 'openvox-strings/yard/code_objects/plan'
14
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Implements a helper that logs a warning if a summary tag has more than 140 characters
4
+ module OpenvoxStrings::Yard::Handlers::Helpers
5
+ def self.validate_summary_tag(object)
6
+ return unless object.has_tag?(:summary) && object.tag(:summary).text.length > 140
7
+
8
+ log.warn "The length of the summary for #{object.type} '#{object.name}' exceeds the recommended limit of 140 characters."
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Implements the base class for all JSON handlers.
4
+ class OpenvoxStrings::Yard::Handlers::JSON::Base < YARD::Handlers::Base
5
+ def self.handles?(statement)
6
+ handlers.any? { |handler| statement.is_a?(handler) }
7
+ end
8
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openvox-strings/yard/handlers/json/base'
4
+ require 'openvox-strings/yard/parsers'
5
+ require 'openvox-strings/yard/parsers/json/parser'
6
+
7
+ # Implements the handler for JSON task metadata.
8
+ class OpenvoxStrings::Yard::Handlers::JSON::TaskHandler < OpenvoxStrings::Yard::Handlers::JSON::Base
9
+ handles OpenvoxStrings::Yard::Parsers::JSON::TaskStatement
10
+ namespace_only
11
+
12
+ process do
13
+ object = OpenvoxStrings::Yard::CodeObjects::Task.new(statement)
14
+ register object
15
+
16
+ @kind = "Puppet Task #{object.name}."
17
+ @statement = statement
18
+
19
+ validate_description
20
+ validate_params
21
+ end
22
+
23
+ def validate_description
24
+ log.warn "Missing a description for #{@kind}." if @statement.docstring.empty?
25
+ end
26
+
27
+ def validate_params
28
+ return if @statement.parameters.empty?
29
+
30
+ @statement.parameters.each do |param, val|
31
+ log.warn "Missing description for param '#{param}' in #{@kind}" if val['description'].nil?
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Implements the base handler for Puppet language handlers.
4
+ class OpenvoxStrings::Yard::Handlers::Puppet::Base < YARD::Handlers::Base
5
+ # Determine sif the handler handles the given statement.
6
+ # @param statement The statement that was parsed.
7
+ # @return [Boolean] Returns true if the statement is handled by this handler or false if not.
8
+ def self.handles?(statement)
9
+ handlers.any? { |handler| statement.is_a?(handler) }
10
+ end
11
+
12
+ protected
13
+
14
+ # Sets the parameter tag types for the given code object.
15
+ # This also performs some validation on the parameter tags.
16
+ # @param object The code object to set the parameter tag types for.
17
+ # @return [void]
18
+ def set_parameter_types(object)
19
+ # Ensure there is an actual parameter for each parameter tag
20
+ tags = object.tags(:param)
21
+ tags.each do |tag|
22
+ next if statement.parameters.find { |p| tag.name == p.name }
23
+
24
+ log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{statement.file}:#{statement.line}." unless %w[name title].include?(tag.name)
25
+ end
26
+
27
+ # Assign the types for the parameter
28
+ statement.parameters.each do |parameter|
29
+ tag = tags.find { |t| t.name == parameter.name }
30
+ unless tag
31
+ log.warn "Missing @param tag for parameter '#{parameter.name}' near #{statement.file}:#{statement.line}." unless object.docstring.empty?
32
+
33
+ # Add a tag with an empty docstring
34
+ object.add_tag YARD::Tags::Tag.new(:param, '', [parameter.type || 'Any'], parameter.name)
35
+ next
36
+ end
37
+
38
+ # Warn if the parameter type and tag types don't match
39
+ if parameter.type && tag.types && !tag.types.empty? && parameter.type != tag.types[0]
40
+ log.warn "The type of the @param tag for parameter '#{parameter.name}' " \
41
+ "does not match the parameter type specification near #{statement.file}:#{statement.line}: " \
42
+ 'ignoring in favor of parameter type information.'
43
+ end
44
+
45
+ if parameter.type
46
+ tag.types = [parameter.type]
47
+ elsif !tag.types
48
+ tag.types = ['Any']
49
+ end
50
+ end
51
+ end
52
+ end