puppet-strings 2.1.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -4
  3. data/CONTRIBUTING.md +32 -2
  4. data/README.md +81 -17
  5. data/lib/puppet-strings.rb +13 -4
  6. data/lib/puppet-strings/describe.rb +68 -0
  7. data/lib/puppet-strings/json.rb +2 -38
  8. data/lib/puppet-strings/markdown.rb +3 -1
  9. data/lib/puppet-strings/markdown/base.rb +37 -16
  10. data/lib/puppet-strings/markdown/data_type.rb +34 -0
  11. data/lib/puppet-strings/markdown/data_types.rb +41 -0
  12. data/lib/puppet-strings/markdown/function.rb +2 -2
  13. data/lib/puppet-strings/markdown/resource_type.rb +19 -2
  14. data/lib/puppet-strings/markdown/table_of_contents.rb +1 -0
  15. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +12 -4
  16. data/lib/puppet-strings/markdown/templates/data_type.erb +93 -0
  17. data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
  18. data/lib/puppet-strings/markdown/templates/function.erb +36 -1
  19. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  20. data/lib/puppet-strings/markdown/templates/resource_type.erb +32 -12
  21. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
  22. data/lib/puppet-strings/tasks/generate.rb +10 -3
  23. data/lib/puppet-strings/version.rb +1 -1
  24. data/lib/puppet-strings/yard.rb +16 -0
  25. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  26. data/lib/puppet-strings/yard/code_objects/class.rb +2 -2
  27. data/lib/puppet-strings/yard/code_objects/data_type.rb +100 -0
  28. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +58 -0
  29. data/lib/puppet-strings/yard/code_objects/defined_type.rb +2 -2
  30. data/lib/puppet-strings/yard/code_objects/function.rb +4 -4
  31. data/lib/puppet-strings/yard/code_objects/plan.rb +2 -2
  32. data/lib/puppet-strings/yard/code_objects/provider.rb +1 -1
  33. data/lib/puppet-strings/yard/code_objects/task.rb +1 -1
  34. data/lib/puppet-strings/yard/code_objects/type.rb +48 -6
  35. data/lib/puppet-strings/yard/handlers.rb +3 -0
  36. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +24 -0
  37. data/lib/puppet-strings/yard/handlers/ruby/base.rb +12 -1
  38. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +393 -0
  39. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +2 -12
  40. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +1 -9
  41. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +3 -3
  42. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +135 -0
  43. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +56 -0
  44. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +9 -115
  45. data/lib/puppet-strings/yard/parsers/json/parser.rb +4 -2
  46. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +14 -7
  47. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +25 -0
  48. data/lib/puppet-strings/yard/tags.rb +2 -0
  49. data/lib/puppet-strings/yard/tags/enum_tag.rb +12 -0
  50. data/lib/puppet-strings/yard/tags/factory.rb +16 -0
  51. data/lib/puppet-strings/yard/tags/overload_tag.rb +2 -2
  52. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
  53. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
  54. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
  55. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
  56. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
  57. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
  58. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  59. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
  60. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
  61. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
  62. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
  63. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
  64. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
  65. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
  66. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
  67. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
  68. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
  69. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
  70. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
  71. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
  72. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
  73. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
  74. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
  75. data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
  76. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
  77. data/lib/puppet-strings/yard/util.rb +48 -0
  78. data/lib/puppet/face/strings.rb +68 -3
  79. metadata +36 -45
  80. data/Gemfile +0 -37
  81. data/HISTORY.md +0 -218
  82. data/JSON.md +0 -802
  83. data/Rakefile +0 -93
  84. data/codecov.yml +0 -3
  85. data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
  86. data/spec/acceptance/emit_json_options.rb +0 -71
  87. data/spec/acceptance/generate_markdown_spec.rb +0 -49
  88. data/spec/acceptance/lib/util.rb +0 -163
  89. data/spec/acceptance/running_strings_generate.rb +0 -54
  90. data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
  91. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
  92. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
  93. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
  94. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
  95. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
  96. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
  97. data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
  98. data/spec/fixtures/unit/json/output.json +0 -660
  99. data/spec/fixtures/unit/json/output_with_plan.json +0 -697
  100. data/spec/fixtures/unit/json/output_without_puppet_function.json +0 -480
  101. data/spec/fixtures/unit/markdown/output.md +0 -444
  102. data/spec/fixtures/unit/markdown/output_with_plan.md +0 -478
  103. data/spec/spec_helper.rb +0 -45
  104. data/spec/spec_helper_acceptance.rb +0 -28
  105. data/spec/unit/puppet-strings/json_spec.rb +0 -229
  106. data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
  107. data/spec/unit/puppet-strings/markdown_spec.rb +0 -283
  108. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
  109. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -124
  110. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
  111. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
  112. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
  113. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
  114. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
  115. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -214
  116. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -269
  117. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -70
  118. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
  119. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
  120. data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
@@ -1,13 +1,16 @@
1
- ### <%= name %>
1
+ ### `<%= name %>`
2
2
 
3
3
  Type: <%= type %>
4
4
 
5
5
  <% if text -%>
6
6
  <%= text %>
7
+
7
8
  <% elsif summary -%>
8
9
  <%= summary %>
10
+
9
11
  <% else -%>
10
12
  <%= "The #{name} function." %>
13
+
11
14
  <% end -%>
12
15
  <% if todo -%>
13
16
  * **TODO** <%= todo %>
@@ -17,7 +20,18 @@ Type: <%= type %>
17
20
  * **Note** <%= note %>
18
21
 
19
22
  <% end -%>
23
+ <% if examples -%>
24
+ #### Examples
25
+
26
+ <% examples.each do |eg| -%>
27
+ ##### <%= eg[:name] %>
28
+
29
+ ```puppet
30
+ <%= eg[:text] %>
31
+ ```
20
32
 
33
+ <% end -%>
34
+ <% end -%>
21
35
  <% signatures.each do |sig| -%>
22
36
  #### `<%= sig.signature %>`
23
37
 
@@ -41,10 +55,23 @@ Returns: `<%= sig.return_type %>`<% if sig.return_val %> <%= sig.return_val %><%
41
55
  <% end -%>
42
56
  <% if raises -%>
43
57
  Raises:
58
+
44
59
  <% raises.each do |r| -%>
45
60
  * <%= error_type(r[:text]) %> <%= error_text(r[:text]) %>
46
61
  <% end -%>
47
62
 
63
+ <% end -%>
64
+ <% if sig.examples -%>
65
+ ##### Examples
66
+
67
+ <% sig.examples.each do |eg| -%>
68
+ ###### <%= eg[:name] %>
69
+
70
+ ```puppet
71
+ <%= eg[:text] %>
72
+ ```
73
+
74
+ <% end -%>
48
75
  <% end -%>
49
76
  <% if sig.params -%>
50
77
  <% sig.params.each do |param| -%>
@@ -61,6 +88,14 @@ Options:
61
88
  * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
62
89
  <% end -%>
63
90
 
91
+ <% end -%>
92
+ <% if sig.enums_for_param(param[:name]) -%>
93
+ Options:
94
+
95
+ <% sig.enums_for_param(param[:name]).each do |e| -%>
96
+ * **<%= e[:opt_name] %>**: <%= e[:opt_text] %>
97
+ <% end -%>
98
+
64
99
  <% end -%>
65
100
  <% end -%>
66
101
  <% end -%>
@@ -1,4 +1,4 @@
1
- ### <%= name %>
1
+ ### `<%= name %>`
2
2
 
3
3
  <% if text -%>
4
4
  <%= text %>
@@ -1,4 +1,4 @@
1
- ### <%= name %>
1
+ ### `<%= 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] -%>
@@ -77,9 +77,17 @@ Options:
77
77
  * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
78
78
  <% end -%>
79
79
 
80
+ <% end -%>
81
+ <% if enums_for_param(prop[:name]) -%>
82
+ Options:
83
+
84
+ <% enums_for_param(prop[:name]).each do |e| -%>
85
+ * **<%= e[:opt_name] %>**: <%= e[:opt_text] %>
86
+ <% end -%>
87
+
80
88
  <% end -%>
81
89
  <% if prop[:default] -%>
82
- Default value: <%= prop[:default] %>
90
+ Default value: `<%= prop[:default] %>`
83
91
 
84
92
  <% end -%>
85
93
  <% end -%>
@@ -93,7 +101,7 @@ The following parameters are available in the `<%= name %>` <%= @type %>.
93
101
  ##### `<%= param[:name] %>`
94
102
 
95
103
  <% if param[:values] -%>
96
- Valid values: <%= param[:values].map { |value| value_string(value) }.join(', ') %>
104
+ Valid values: `<%= param[:values].map { |value| value_string(value) }.join('`, `') %>`
97
105
 
98
106
  <% end -%>
99
107
  <% if param[:isnamevar] -%>
@@ -101,14 +109,14 @@ namevar
101
109
 
102
110
  <% end -%>
103
111
  <% if param[:aliases] -%>
104
- Aliases: <%= param[:aliases].to_s.delete('{').delete('}') %>
112
+ Aliases: `<%= param[:aliases].to_s.delete('{').delete('}') %>`
105
113
 
106
114
  <% end -%>
107
115
  <% if param[:data_type] -%>
108
116
  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]) %>
109
117
 
110
118
  <% end -%>
111
- <%= param[:description] %>
119
+ <%= word_wrap(param[:description]) %>
112
120
 
113
121
  <% if options_for_param(param[:name]) -%>
114
122
  Options:
@@ -117,9 +125,21 @@ Options:
117
125
  * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
118
126
  <% end -%>
119
127
 
128
+ <% end -%>
129
+ <% if enums_for_param(param[:name]) -%>
130
+ Options:
131
+
132
+ <% enums_for_param(param[:name]).each do |e| -%>
133
+ * **<%= e[:opt_name] %>**: <%= e[:opt_text] %>
134
+ <% end -%>
135
+
120
136
  <% end -%>
121
137
  <% if param[:default] -%>
122
- Default value: <%= value_string(param[:default]) %>
138
+ Default value: `<%= value_string(param[:default]) %>`
139
+
140
+ <% end -%>
141
+ <% if param[:required_features] -%>
142
+ Required features: <%= param[:required_features] %>.
123
143
 
124
144
  <% end -%>
125
145
  <% end -%>
@@ -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
 
@@ -33,13 +33,20 @@ namespace :strings do
33
33
  end
34
34
  end
35
35
  end
36
+ # rubocop:enable Style/PreferredHashMethods
36
37
 
37
- [:json,:markdown].each { |format| parse_format_option(args, options, format) }
38
+ %i[json markdown].each { |format| parse_format_option(args, options, format) }
38
39
 
39
40
  warn('yard_args behavior is a little dodgy, use at your own risk') if args[:yard_args]
40
- options[:yard_args] = args[:yard_args].split if args.has_key? :yard_args
41
+ options[:yard_args] = args[:yard_args].split if args.key? :yard_args
41
42
 
42
43
  PuppetStrings.generate(patterns, options)
43
44
  end
44
- end
45
45
 
46
+ namespace :generate do
47
+ desc 'Generate Puppet Reference documentation.'
48
+ task :reference, [:patterns, :debug, :backtrace] do |t, args|
49
+ Rake::Task['strings:generate'].invoke(args[:patterns], args[:debug], args[:backtrace], nil, 'false', 'true')
50
+ end
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module PuppetStrings
2
- VERSION = '2.1.0'.freeze
2
+ VERSION = '2.5.0'.freeze
3
3
  end
@@ -11,6 +11,9 @@ module PuppetStrings::Yard
11
11
  # Sets up YARD for use with puppet-strings.
12
12
  # @return [void]
13
13
  def self.setup!
14
+ # Register our factory
15
+ YARD::Tags::Library.default_factory = PuppetStrings::Yard::Tags::Factory
16
+
14
17
  # Register the template path
15
18
  YARD::Templates::Engine.register_template_path(File.join(File.dirname(__FILE__), 'yard', 'templates'))
16
19
 
@@ -30,6 +33,9 @@ module PuppetStrings::Yard
30
33
  # Register the summary tag
31
34
  PuppetStrings::Yard::Tags::SummaryTag.register!
32
35
 
36
+ # Register the enum tag
37
+ PuppetStrings::Yard::Tags::EnumTag.register!
38
+
33
39
  # Ignore documentation on Puppet DSL calls
34
40
  # This prevents the YARD DSL parser from emitting warnings for Puppet's Ruby DSL
35
41
  YARD::Handlers::Ruby::DSLHandlerMethods::IGNORE_METHODS['create_function'] = true
@@ -46,6 +52,8 @@ class YARD::CLI::Yardoc
46
52
  :module,
47
53
  :class,
48
54
  :puppet_class,
55
+ :puppet_data_type,
56
+ :puppet_data_type_alias,
49
57
  :puppet_defined_type,
50
58
  :puppet_type,
51
59
  :puppet_provider,
@@ -64,6 +72,14 @@ class YARD::CLI::Stats
64
72
  output 'Puppet Classes', *type_statistics_all(:puppet_class)
65
73
  end
66
74
 
75
+ def stats_for_puppet_data_types
76
+ output 'Puppet Data Types', *type_statistics_all(:puppet_data_type)
77
+ end
78
+
79
+ def stats_for_puppet_data_type_aliases
80
+ output 'Puppet Data Type Aliases', *type_statistics_all(:puppet_data_type_alias)
81
+ end
82
+
67
83
  def stats_for_puppet_defined_types
68
84
  output 'Puppet Defined Types', *type_statistics_all(:puppet_defined_type)
69
85
  end
@@ -1,6 +1,8 @@
1
1
  # The module for custom YARD code objects.
2
2
  module PuppetStrings::Yard::CodeObjects
3
3
  require 'puppet-strings/yard/code_objects/class'
4
+ require 'puppet-strings/yard/code_objects/data_type'
5
+ require 'puppet-strings/yard/code_objects/data_type_alias'
4
6
  require 'puppet-strings/yard/code_objects/defined_type'
5
7
  require 'puppet-strings/yard/code_objects/type'
6
8
  require 'puppet-strings/yard/code_objects/provider'
@@ -50,8 +50,8 @@ class PuppetStrings::Yard::CodeObjects::Class < PuppetStrings::Yard::CodeObjects
50
50
  hash[:file] = file
51
51
  hash[:line] = line
52
52
  hash[:inherits] = statement.parent_class if statement.parent_class
53
- hash[:docstring] = PuppetStrings::Json.docstring_to_hash(docstring)
54
- defaults = Hash[*parameters.select{ |p| !p[1].nil? }.flatten]
53
+ hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
54
+ defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
55
55
  hash[:defaults] = defaults unless defaults.empty?
56
56
  hash[:source] = source unless source && source.empty?
57
57
  hash
@@ -0,0 +1,100 @@
1
+ require 'puppet-strings/yard/code_objects/group'
2
+ require 'puppet-strings/yard/util'
3
+
4
+ # Implements the group for Puppet DataTypes.
5
+ class PuppetStrings::Yard::CodeObjects::DataTypes < PuppetStrings::Yard::CodeObjects::Group
6
+ # Gets the singleton instance of the group.
7
+ # @return Returns the singleton instance of the group.
8
+ def self.instance
9
+ super(:puppet_data_types)
10
+ end
11
+
12
+ # Gets the display name of the group.
13
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
14
+ # @return [String] Returns the display name of the group.
15
+ def name(prefix = false)
16
+ 'Puppet Data Types'
17
+ end
18
+ end
19
+
20
+ # Implements the Puppet DataType code object.
21
+ class PuppetStrings::Yard::CodeObjects::DataType < PuppetStrings::Yard::CodeObjects::Base
22
+ # Initializes a Puppet class code object.
23
+ # @param [String] The name of the Data Type
24
+ # @return [void]
25
+ def initialize(name)
26
+ super(PuppetStrings::Yard::CodeObjects::DataTypes.instance, name)
27
+ @defaults = {}
28
+ end
29
+
30
+ # Gets the type of the code object.
31
+ # @return Returns the type of the code object.
32
+ def type
33
+ :puppet_data_type
34
+ end
35
+
36
+ # Gets the source of the code object.
37
+ # @return Returns the source of the code object.
38
+ def source
39
+ # Not implemented, but would be nice!
40
+ nil
41
+ end
42
+
43
+ def add_parameter(name, type, default)
44
+ tag = docstring.tags(:param).find { |item| item.name == name }
45
+ if tag.nil?
46
+ tag = YARD::Tags::Tag.new(:param, '', nil, name)
47
+ docstring.add_tag(tag)
48
+ end
49
+ type = [type] unless type.is_a?(Array)
50
+ tag.types = type if tag.types.nil?
51
+ set_parameter_default(name, default)
52
+ end
53
+
54
+ def set_parameter_default(param_name, default)
55
+ defaults.delete(param_name)
56
+ defaults[param_name] = default unless default.nil?
57
+ end
58
+
59
+ def parameters
60
+ docstring.tags(:param).map { |tag| [tag.name, defaults[tag.name]] }
61
+ end
62
+
63
+ def add_function(name, return_type, parameter_types)
64
+ meth_obj = YARD::CodeObjects::MethodObject.new(self, name, :class)
65
+
66
+ # Add return tag
67
+ meth_obj.add_tag(YARD::Tags::Tag.new(:return, '', return_type))
68
+
69
+ # Add parameters
70
+ parameter_types.each_with_index do |param_type, index|
71
+ meth_obj.add_tag(YARD::Tags::Tag.new(:param, '', [param_type], "param#{index + 1}"))
72
+ end
73
+
74
+ self.meths << meth_obj
75
+ end
76
+
77
+ def functions
78
+ meths
79
+ end
80
+
81
+ # Converts the code object to a hash representation.
82
+ # @return [Hash] Returns a hash representation of the code object.
83
+ def to_hash
84
+ hash = {}
85
+ hash[:name] = name
86
+ hash[:file] = file
87
+ hash[:line] = line
88
+ hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example])
89
+ hash[:defaults] = defaults unless defaults.empty?
90
+ hash[:source] = source unless source && source.empty?
91
+ hash[:functions] = functions.map do |func|
92
+ {
93
+ name: func.name,
94
+ signature: func.signature,
95
+ docstring: PuppetStrings::Yard::Util.docstring_to_hash(func.docstring, %i[param option enum return example])
96
+ }
97
+ end
98
+ hash
99
+ end
100
+ end
@@ -0,0 +1,58 @@
1
+ require 'puppet-strings/yard/code_objects/group'
2
+ require 'puppet-strings/yard/util'
3
+
4
+ # Implements the group for Puppet DataTypeAliases.
5
+ class PuppetStrings::Yard::CodeObjects::DataTypeAliases < PuppetStrings::Yard::CodeObjects::Group
6
+ # Gets the singleton instance of the group.
7
+ # @return Returns the singleton instance of the group.
8
+ def self.instance
9
+ super(:puppet_data_type_aliases)
10
+ end
11
+
12
+ # Gets the display name of the group.
13
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
14
+ # @return [String] Returns the display name of the group.
15
+ def name(prefix = false)
16
+ 'Puppet Data Type Aliases'
17
+ end
18
+ end
19
+
20
+ # Implements the Puppet DataTypeAlias code object.
21
+ class PuppetStrings::Yard::CodeObjects::DataTypeAlias < PuppetStrings::Yard::CodeObjects::Base
22
+ attr_reader :statement
23
+ attr_accessor :alias_of
24
+
25
+ # Initializes a Puppet data type alias code object.
26
+ # @param [PuppetStrings::Parsers::DataTypeAliasStatement] statement The data type alias statement that was parsed.
27
+ # @return [void]
28
+ def initialize(statement)
29
+ @statement = statement
30
+ @alias_of = statement.alias_of
31
+ super(PuppetStrings::Yard::CodeObjects::DataTypeAliases.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_data_type_alias
38
+ end
39
+
40
+ # Gets the source of the code object.
41
+ # @return Returns the source of the code object.
42
+ def source
43
+ # Not implemented, but would be nice!
44
+ nil
45
+ end
46
+
47
+ # Converts the code object to a hash representation.
48
+ # @return [Hash] Returns a hash representation of the code object.
49
+ def to_hash
50
+ hash = {}
51
+ hash[:name] = name
52
+ hash[:file] = file
53
+ hash[:line] = line
54
+ hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
55
+ hash[:alias_of] = alias_of
56
+ hash
57
+ end
58
+ end