puppet-strings 2.8.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +267 -225
- data/README.md +52 -65
- data/lib/puppet/face/strings.rb +30 -50
- data/lib/puppet/feature/rgen.rb +1 -1
- data/lib/puppet/feature/yard.rb +1 -1
- data/lib/puppet-strings/describe.rb +18 -18
- data/lib/puppet-strings/markdown/base.rb +63 -28
- data/lib/puppet-strings/markdown/data_type.rb +4 -0
- data/lib/puppet-strings/markdown/defined_type.rb +4 -0
- data/lib/puppet-strings/markdown/function.rb +13 -8
- data/lib/puppet-strings/markdown/helpers.rb +21 -0
- data/lib/puppet-strings/markdown/puppet_class.rb +4 -0
- data/lib/puppet-strings/markdown/puppet_plan.rb +4 -0
- data/lib/puppet-strings/markdown/puppet_task.rb +4 -1
- data/lib/puppet-strings/markdown/resource_type.rb +13 -3
- data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +4 -4
- data/lib/puppet-strings/markdown/templates/data_type.erb +5 -9
- data/lib/puppet-strings/markdown/templates/data_type_function.erb +1 -1
- data/lib/puppet-strings/markdown/templates/function.erb +1 -1
- data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
- data/lib/puppet-strings/markdown/templates/resource_type.erb +6 -6
- data/lib/puppet-strings/markdown/templates/table_of_contents.erb +8 -8
- data/lib/puppet-strings/markdown.rb +62 -20
- data/lib/puppet-strings/monkey_patches/display_object_command.rb +4 -1
- data/lib/puppet-strings/tasks/generate.rb +8 -10
- data/lib/puppet-strings/tasks/gh_pages.rb +6 -5
- data/lib/puppet-strings/tasks/validate.rb +42 -0
- data/lib/puppet-strings/tasks.rb +5 -6
- data/lib/puppet-strings/version.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/class.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/data_type.rb +4 -4
- data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/defined_type.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/function.rb +11 -11
- data/lib/puppet-strings/yard/code_objects/group.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/plan.rb +4 -2
- data/lib/puppet-strings/yard/code_objects/provider.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/task.rb +6 -7
- data/lib/puppet-strings/yard/code_objects/type.rb +6 -5
- data/lib/puppet-strings/yard/handlers/helpers.rb +3 -4
- data/lib/puppet-strings/yard/handlers/json/base.rb +2 -1
- data/lib/puppet-strings/yard/handlers/json/task_handler.rb +4 -4
- data/lib/puppet-strings/yard/handlers/puppet/base.rb +7 -2
- data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -2
- data/lib/puppet-strings/yard/handlers/ruby/base.rb +3 -2
- data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +19 -16
- data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +70 -50
- data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +2 -1
- data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +12 -9
- data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +27 -27
- data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +2 -3
- data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +2 -1
- data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -2
- data/lib/puppet-strings/yard/parsers/json/task_statement.rb +3 -3
- data/lib/puppet-strings/yard/parsers/puppet/parser.rb +7 -7
- data/lib/puppet-strings/yard/parsers/puppet/statement.rb +16 -23
- data/lib/puppet-strings/yard/parsers.rb +1 -0
- data/lib/puppet-strings/yard/tags/enum_tag.rb +1 -2
- data/lib/puppet-strings/yard/tags/factory.rb +1 -1
- data/lib/puppet-strings/yard/tags/overload_tag.rb +7 -7
- data/lib/puppet-strings/yard/tags/parameter_directive.rb +2 -2
- data/lib/puppet-strings/yard/tags/property_directive.rb +2 -2
- data/lib/puppet-strings/yard/tags/summary_tag.rb +1 -2
- data/lib/puppet-strings/yard/util.rb +11 -4
- data/lib/puppet-strings/yard.rb +6 -6
- data/lib/puppet-strings.rb +7 -13
- metadata +15 -22
- data/lib/puppet-strings/markdown/data_types.rb +0 -43
- data/lib/puppet-strings/markdown/defined_types.rb +0 -39
- data/lib/puppet-strings/markdown/functions.rb +0 -40
- data/lib/puppet-strings/markdown/puppet_classes.rb +0 -39
- data/lib/puppet-strings/markdown/puppet_plans.rb +0 -39
- data/lib/puppet-strings/markdown/puppet_tasks.rb +0 -36
- data/lib/puppet-strings/markdown/resource_types.rb +0 -39
- data/lib/puppet-strings/markdown/table_of_contents.rb +0 -26
@@ -8,18 +8,18 @@ require 'puppet-strings/yard/util'
|
|
8
8
|
# Implements the handler for Puppet functions written in Ruby.
|
9
9
|
class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard::Handlers::Ruby::Base
|
10
10
|
# Represents the list of Puppet 4.x function API methods to support.
|
11
|
-
DISPATCH_METHOD_NAMES =
|
12
|
-
param
|
13
|
-
required_param
|
14
|
-
optional_param
|
15
|
-
repeated_param
|
16
|
-
optional_repeated_param
|
17
|
-
required_repeated_param
|
18
|
-
block_param
|
19
|
-
required_block_param
|
20
|
-
optional_block_param
|
21
|
-
return_type
|
22
|
-
|
11
|
+
DISPATCH_METHOD_NAMES = [
|
12
|
+
'param',
|
13
|
+
'required_param',
|
14
|
+
'optional_param',
|
15
|
+
'repeated_param',
|
16
|
+
'optional_repeated_param',
|
17
|
+
'required_repeated_param',
|
18
|
+
'block_param',
|
19
|
+
'required_block_param',
|
20
|
+
'optional_block_param',
|
21
|
+
'return_type',
|
22
|
+
].freeze
|
23
23
|
|
24
24
|
namespace_only
|
25
25
|
handles method_call(:create_function)
|
@@ -33,13 +33,13 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
33
33
|
return unless statement.count > 1
|
34
34
|
|
35
35
|
module_name = statement[0].source
|
36
|
-
return unless
|
36
|
+
return unless ['Puppet::Functions', 'Puppet::Parser::Functions', 'newfunction'].include?(module_name)
|
37
37
|
|
38
38
|
# Create and register the function object
|
39
|
-
is_3x =
|
39
|
+
is_3x = ['Puppet::Parser::Functions', 'newfunction'].include?(module_name)
|
40
40
|
object = PuppetStrings::Yard::CodeObjects::Function.new(
|
41
41
|
get_name(statement, 'Puppet::Functions.create_function'),
|
42
|
-
is_3x ? PuppetStrings::Yard::CodeObjects::Function::RUBY_3X : PuppetStrings::Yard::CodeObjects::Function::RUBY_4X
|
42
|
+
is_3x ? PuppetStrings::Yard::CodeObjects::Function::RUBY_3X : PuppetStrings::Yard::CodeObjects::Function::RUBY_4X,
|
43
43
|
)
|
44
44
|
object.source = statement
|
45
45
|
register object
|
@@ -56,7 +56,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
56
56
|
end
|
57
57
|
|
58
58
|
# Populate the parameters and the return tag
|
59
|
-
object.parameters = object.tags(:param).map{ |p| [p.name, nil] }
|
59
|
+
object.parameters = object.tags(:param).map { |p| [p.name, nil] }
|
60
60
|
add_return_tag(object, statement.file, statement.line)
|
61
61
|
else
|
62
62
|
# For 4x, auto generate tags based on dispatch docstrings
|
@@ -71,11 +71,27 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
71
71
|
end
|
72
72
|
|
73
73
|
private
|
74
|
+
|
74
75
|
def add_tags(object)
|
75
76
|
log.warn "Missing documentation for Puppet function '#{object.name}' at #{statement.file}:#{statement.line}." if object.docstring.empty? && object.tags.empty?
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
|
78
|
+
unless object.tags(:param).empty?
|
79
|
+
log.warn "The docstring for Puppet 4.x function '#{object.name}' "\
|
80
|
+
"contains @param tags near #{object.file}:#{object.line}: parameter "\
|
81
|
+
'documentation should be made on the dispatch call.'
|
82
|
+
end
|
83
|
+
|
84
|
+
unless object.tags(:return).empty?
|
85
|
+
log.warn "The docstring for Puppet 4.x function '#{object.name}' "\
|
86
|
+
"contains @return tags near #{object.file}:#{object.line}: return "\
|
87
|
+
'value documentation should be made on the dispatch call.'
|
88
|
+
end
|
89
|
+
|
90
|
+
unless object.tags(:overload).empty?
|
91
|
+
log.warn "The docstring for Puppet 4.x function '#{object.name}' "\
|
92
|
+
"contains @overload tags near #{object.file}:#{object.line}: overload "\
|
93
|
+
'tags are automatically generated from the dispatch calls.'
|
94
|
+
end
|
79
95
|
|
80
96
|
# Delete any existing param/return/overload tags
|
81
97
|
object.docstring.delete_tags(:param)
|
@@ -106,12 +122,11 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
106
122
|
end
|
107
123
|
|
108
124
|
# If there's only one overload, move the tags to the object itself
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
125
|
+
return unless overloads.length == 1
|
126
|
+
overload = overloads.first
|
127
|
+
object.parameters = overload.parameters
|
128
|
+
object.add_tag(*overload.tags)
|
129
|
+
object.docstring.delete_tags(:overload)
|
115
130
|
end
|
116
131
|
|
117
132
|
def add_overload_tag(object, node)
|
@@ -169,7 +184,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
169
184
|
node_as_string(parameters[0]),
|
170
185
|
nil, # TODO: determine default from corresponding Ruby method signature?
|
171
186
|
method_name.include?('optional'),
|
172
|
-
method_name.include?('repeated')
|
187
|
+
method_name.include?('repeated'),
|
173
188
|
)
|
174
189
|
end
|
175
190
|
|
@@ -200,7 +215,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
200
215
|
nil, # TODO: determine default from corresponding Ruby method signature?
|
201
216
|
block.method_name.source.include?('optional'),
|
202
217
|
false, # Not repeated
|
203
|
-
true
|
218
|
+
true, # Is block
|
204
219
|
)
|
205
220
|
end
|
206
221
|
end
|
@@ -223,29 +238,29 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
223
238
|
# Populate the required parameters
|
224
239
|
params = parameters.unnamed_required_params
|
225
240
|
params&.each do |parameter|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
241
|
+
add_param_tag(
|
242
|
+
overload_tag,
|
243
|
+
param_tags,
|
244
|
+
parameter.source,
|
245
|
+
parameter.file,
|
246
|
+
parameter.line,
|
247
|
+
)
|
248
|
+
end
|
234
249
|
|
235
250
|
# Populate the optional parameters
|
236
251
|
params = parameters.unnamed_optional_params
|
237
252
|
params&.each do |parameter|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
253
|
+
add_param_tag(
|
254
|
+
overload_tag,
|
255
|
+
param_tags,
|
256
|
+
parameter[0].source,
|
257
|
+
parameter.file,
|
258
|
+
parameter.line,
|
259
|
+
nil,
|
260
|
+
parameter[1].source,
|
261
|
+
true,
|
262
|
+
)
|
263
|
+
end
|
249
264
|
|
250
265
|
# Populate the splat parameter
|
251
266
|
param = parameters.splat_param
|
@@ -259,7 +274,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
259
274
|
nil,
|
260
275
|
nil,
|
261
276
|
false,
|
262
|
-
true
|
277
|
+
true,
|
263
278
|
)
|
264
279
|
end
|
265
280
|
|
@@ -276,7 +291,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
276
291
|
nil,
|
277
292
|
false,
|
278
293
|
false,
|
279
|
-
true
|
294
|
+
true,
|
280
295
|
)
|
281
296
|
end
|
282
297
|
|
@@ -290,9 +305,14 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
290
305
|
end
|
291
306
|
|
292
307
|
def add_param_tag(object, tags, name, file, line, type = nil, default = nil, optional = false, repeated = false, block = false)
|
293
|
-
tag = tags.find { |
|
308
|
+
tag = tags.find { |t| t.name == name } if tags
|
294
309
|
log.warn "Missing @param tag for parameter '#{name}' near #{file}:#{line}." unless tag || object.docstring.all.empty?
|
295
|
-
|
310
|
+
|
311
|
+
if type && tag && tag.types && !tag.types.empty?
|
312
|
+
log.warn "The @param tag for parameter '#{name}' should not contain a "\
|
313
|
+
"type specification near #{file}:#{line}: ignoring in favor of "\
|
314
|
+
'dispatch type information.'
|
315
|
+
end
|
296
316
|
|
297
317
|
if repeated
|
298
318
|
name = '*' + name
|
@@ -44,6 +44,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
47
|
+
|
47
48
|
def register_provider_docstring(object)
|
48
49
|
# Walk the tree searching for assignments or calls to desc/doc=
|
49
50
|
statement.traverse do |child|
|
@@ -93,7 +94,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
93
94
|
|
94
95
|
object.add_confine(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source)
|
95
96
|
end
|
96
|
-
elsif
|
97
|
+
elsif ['has_feature', 'has_features'].include?(method_name)
|
97
98
|
# Add the features to the object
|
98
99
|
parameters.each do |parameter|
|
99
100
|
object.add_feature(node_as_string(parameter) || parameter.source)
|
@@ -52,11 +52,15 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
|
|
52
52
|
|
53
53
|
# check that the params of the register_type call are key/value pairs.
|
54
54
|
def kv_arg_list?(params)
|
55
|
-
params.type == :list &&
|
55
|
+
params.type == :list &&
|
56
|
+
params.children.count > 0 &&
|
57
|
+
params.children.first.type == :list &&
|
58
|
+
params.children.first.children.count > 0 &&
|
59
|
+
statement.parameters.children.first.children.first.type == :assoc
|
56
60
|
end
|
57
61
|
|
58
62
|
def extract_schema
|
59
|
-
raise_parse_error(
|
63
|
+
raise_parse_error('Expected list of key/value pairs as argument') unless kv_arg_list?(statement.parameters)
|
60
64
|
hash_from_node(statement.parameters.children.first)
|
61
65
|
end
|
62
66
|
|
@@ -84,7 +88,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
|
|
84
88
|
def array_from_node(node)
|
85
89
|
return nil unless node
|
86
90
|
|
87
|
-
|
91
|
+
node.children.map do |assoc|
|
88
92
|
value_from_node(assoc.children[0])
|
89
93
|
end
|
90
94
|
end
|
@@ -94,7 +98,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
|
|
94
98
|
|
95
99
|
# puts "hash from #{node.inspect}"
|
96
100
|
|
97
|
-
kv_pairs = node.children.
|
101
|
+
kv_pairs = node.children.map do |assoc|
|
98
102
|
[value_from_node(assoc.children[0]), value_from_node(assoc.children[1])]
|
99
103
|
end
|
100
104
|
Hash[kv_pairs]
|
@@ -107,20 +111,19 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
|
|
107
111
|
|
108
112
|
if node.children.first.type == :kw
|
109
113
|
case node.children.first.source
|
110
|
-
when
|
114
|
+
when 'false'
|
111
115
|
return false
|
112
|
-
when
|
116
|
+
when 'true'
|
113
117
|
return true
|
114
|
-
when
|
118
|
+
when 'nil'
|
115
119
|
return nil
|
116
120
|
else
|
117
121
|
raise_parse_error("unexpected keyword '#{node.children.first.source}'")
|
118
122
|
end
|
119
123
|
end
|
120
|
-
raise_parse_error(
|
124
|
+
raise_parse_error('unexpected variable')
|
121
125
|
end
|
122
126
|
|
123
|
-
|
124
127
|
def populate_type_data(object, schema)
|
125
128
|
return if schema['attributes'].nil?
|
126
129
|
|
@@ -2,17 +2,19 @@
|
|
2
2
|
|
3
3
|
require 'puppet-strings/yard/handlers/ruby/base'
|
4
4
|
|
5
|
+
# Base class for all Puppet resource type handlers.
|
5
6
|
class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handlers::Ruby::Base
|
6
7
|
protected
|
8
|
+
|
7
9
|
def get_type_yard_object(name)
|
8
|
-
#Have to guess the path - if we create the object to get the true path from the code,
|
9
|
-
#it also shows up in the .at call - self registering?
|
10
|
+
# Have to guess the path - if we create the object to get the true path from the code,
|
11
|
+
# it also shows up in the .at call - self registering?
|
10
12
|
guess_path = "puppet_types::#{name}"
|
11
13
|
object = YARD::Registry.at(guess_path)
|
12
14
|
|
13
15
|
return object unless object.nil?
|
14
16
|
|
15
|
-
#Didn't find, create instead
|
17
|
+
# Didn't find, create instead
|
16
18
|
object = PuppetStrings::Yard::CodeObjects::Type.new(name)
|
17
19
|
register object
|
18
20
|
object
|
@@ -32,8 +34,8 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
32
34
|
elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
|
33
35
|
# Look for a call to a dispatch method with a block
|
34
36
|
next unless child.method_name &&
|
35
|
-
|
36
|
-
|
37
|
+
(child.method_name.source == 'desc' || child.method_name.source == 'doc=') &&
|
38
|
+
child.parameters(false).count == 1
|
37
39
|
|
38
40
|
docstring = node_as_string(child.parameters[0])
|
39
41
|
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
|
@@ -100,27 +102,25 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
100
102
|
parameters = node.parameters(false)
|
101
103
|
|
102
104
|
if parameters.count >= 2
|
103
|
-
kvps = parameters[1].
|
105
|
+
kvps = parameters[1].select { |kvp| kvp.count == 2 }
|
104
106
|
required_features_kvp = kvps.find { |kvp| node_as_string(kvp[0]) == 'required_features' }
|
105
107
|
object.required_features = node_as_string(required_features_kvp[1]) unless required_features_kvp.nil?
|
106
108
|
end
|
107
109
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
121
|
-
break
|
122
|
-
end
|
110
|
+
return unless object.is_a? PuppetStrings::Yard::CodeObjects::Type::Parameter
|
111
|
+
# Process the options for parameter base types
|
112
|
+
return unless parameters.count >= 2
|
113
|
+
parameters[1].each do |kvp|
|
114
|
+
next unless kvp.count == 2
|
115
|
+
next unless node_as_string(kvp[0]) == 'parent'
|
116
|
+
|
117
|
+
if kvp[1].source == 'Puppet::Parameter::Boolean'
|
118
|
+
object.add('true') unless object.values.include? 'true'
|
119
|
+
object.add('false') unless object.values.include? 'false'
|
120
|
+
object.add('yes') unless object.values.include? 'yes'
|
121
|
+
object.add('no') unless object.values.include? 'no'
|
123
122
|
end
|
123
|
+
break
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
@@ -129,15 +129,15 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
|
|
129
129
|
|
130
130
|
default = nil
|
131
131
|
object.properties&.each do |property|
|
132
|
-
|
132
|
+
return nil if property.isnamevar
|
133
133
|
|
134
|
-
|
135
|
-
|
134
|
+
default = property if property.name == 'name'
|
135
|
+
end
|
136
136
|
object.parameters&.each do |parameter|
|
137
|
-
|
137
|
+
return nil if parameter.isnamevar
|
138
138
|
|
139
|
-
|
140
|
-
|
139
|
+
default ||= parameter if parameter.name == 'name'
|
140
|
+
end
|
141
141
|
default.isnamevar = true if default
|
142
142
|
end
|
143
143
|
end
|
@@ -16,7 +16,6 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
|
|
16
16
|
handles method_call(:ensurable)
|
17
17
|
|
18
18
|
process do
|
19
|
-
|
20
19
|
# Our entry point is a type newproperty/newparam compound statement like this:
|
21
20
|
# "Puppet::Type.type(:file).newparam(:content) do"
|
22
21
|
# We want to
|
@@ -36,7 +35,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
|
|
36
35
|
return unless (statement.count > 1) && (statement[0].children.count > 2)
|
37
36
|
|
38
37
|
module_name = statement[0].children[0].source
|
39
|
-
method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source
|
38
|
+
method1_name = statement[0].children.drop(1).find { |c| c.type == :ident }.source
|
40
39
|
return unless ['Type', 'Puppet::Type'].include?(module_name) && method1_name == 'type'
|
41
40
|
|
42
41
|
# ensurable is syntatic sugar for newproperty
|
@@ -52,7 +51,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
|
|
52
51
|
typeobject = get_type_yard_object(typename)
|
53
52
|
|
54
53
|
# node - what should it be here?
|
55
|
-
node = statement
|
54
|
+
node = statement # ?? not sure... test...
|
56
55
|
|
57
56
|
if method2_name == 'newproperty'
|
58
57
|
typeobject.add_property(create_property(propertyname, node))
|
@@ -18,7 +18,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
18
18
|
return unless statement.count > 1
|
19
19
|
|
20
20
|
module_name = statement[0].source
|
21
|
-
return unless
|
21
|
+
return unless ['Puppet::Type', 'Type'].include?(module_name)
|
22
22
|
|
23
23
|
object = get_type_yard_object(get_name(statement, 'Puppet::Type.newtype'))
|
24
24
|
|
@@ -39,6 +39,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
42
|
+
|
42
43
|
def populate_type_data(object)
|
43
44
|
# Traverse the block looking for properties/parameters/features
|
44
45
|
block = statement.block
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'puppet-strings/yard/parsers/json/task_statement'
|
4
4
|
|
5
|
+
# Implementas a JSON parser.
|
5
6
|
class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
|
6
7
|
attr_reader :file, :source
|
7
8
|
|
@@ -9,7 +10,7 @@ class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
|
|
9
10
|
# @param [String] source The source being parsed.
|
10
11
|
# @param [String] filename The file name of the file being parsed.
|
11
12
|
# @return [void]
|
12
|
-
def initialize(source, filename)
|
13
|
+
def initialize(source, filename) # rubocop:disable Lint/MissingSuper
|
13
14
|
@file = filename
|
14
15
|
@source = source
|
15
16
|
@statements = []
|
@@ -27,7 +28,7 @@ class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
|
|
27
28
|
# TODO: this should compare json to a Task metadata json-schema or perform some other hueristics
|
28
29
|
# to determine what type of statement it represents
|
29
30
|
@statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) unless json.empty?
|
30
|
-
rescue
|
31
|
+
rescue
|
31
32
|
log.error "Failed to parse #{@file}: "
|
32
33
|
@statements = []
|
33
34
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module PuppetStrings::Yard::Parsers::JSON
|
4
4
|
# Represents the Puppet Task statement.
|
5
5
|
class TaskStatement
|
6
|
-
attr_reader :line, :
|
6
|
+
attr_reader :line, :comments_range, :json, :file, :source, :docstring
|
7
7
|
|
8
8
|
def initialize(json, source, file)
|
9
9
|
@file = file
|
@@ -23,7 +23,7 @@ module PuppetStrings::Yard::Parsers::JSON
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def show
|
26
|
-
|
26
|
+
''
|
27
27
|
end
|
28
28
|
|
29
29
|
def comments
|
@@ -31,7 +31,7 @@ module PuppetStrings::Yard::Parsers::JSON
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def name
|
34
|
-
File.basename(@file).gsub('.json','') ||
|
34
|
+
File.basename(@file).gsub('.json', '') || ''
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Naming/MethodName
|
4
|
+
|
3
5
|
require 'puppet'
|
4
6
|
require 'puppet/pops'
|
5
7
|
require 'puppet-strings/yard/parsers/puppet/statement'
|
@@ -12,7 +14,7 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
|
|
12
14
|
# @param [String] source The source being parsed.
|
13
15
|
# @param [String] filename The file name of the file being parsed.
|
14
16
|
# @return [void]
|
15
|
-
def initialize(source, filename)
|
17
|
+
def initialize(source, filename) # rubocop:disable Lint/MissingSuper
|
16
18
|
@source = source
|
17
19
|
@file = filename
|
18
20
|
@visitor = ::Puppet::Pops::Visitor.new(self, 'transform')
|
@@ -22,13 +24,11 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
|
|
22
24
|
# @return [void]
|
23
25
|
def parse
|
24
26
|
begin
|
25
|
-
if @file.to_s.match(
|
26
|
-
|
27
|
-
|
28
|
-
return
|
29
|
-
end
|
30
|
-
Puppet[:tasks] = true if Puppet.settings.include?(:tasks)
|
27
|
+
if @file.to_s.match?(%r{^plans|/plans/}) && Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') < 0
|
28
|
+
log.warn "Skipping #{@file}: Puppet Plans require Puppet 5 or greater."
|
29
|
+
return
|
31
30
|
end
|
31
|
+
Puppet[:tasks] = true if Puppet.settings.include?(:tasks)
|
32
32
|
@statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact
|
33
33
|
rescue ::Puppet::ParseError => e
|
34
34
|
log.error "Failed to parse #{@file}: #{e.message}"
|
@@ -7,7 +7,7 @@ module PuppetStrings::Yard::Parsers::Puppet
|
|
7
7
|
# Represents the base Puppet language statement.
|
8
8
|
class Statement
|
9
9
|
# The pattern for parsing docstring comments.
|
10
|
-
COMMENT_REGEX =
|
10
|
+
COMMENT_REGEX = %r{^\s*#+\s?}.freeze
|
11
11
|
|
12
12
|
attr_reader :source
|
13
13
|
attr_reader :file
|
@@ -21,9 +21,8 @@ module PuppetStrings::Yard::Parsers::Puppet
|
|
21
21
|
def initialize(object, file)
|
22
22
|
@file = file
|
23
23
|
|
24
|
-
|
25
|
-
@
|
26
|
-
@line = adapter.line
|
24
|
+
@source = PuppetStrings::Yard::Util.ast_to_text(object)
|
25
|
+
@line = object.line
|
27
26
|
@comments_range = nil
|
28
27
|
end
|
29
28
|
|
@@ -32,7 +31,7 @@ module PuppetStrings::Yard::Parsers::Puppet
|
|
32
31
|
# @return [void]
|
33
32
|
def extract_docstring(lines)
|
34
33
|
comment = []
|
35
|
-
(0..@line-2).reverse_each do |index|
|
34
|
+
(0..@line - 2).reverse_each do |index|
|
36
35
|
break unless index <= lines.count
|
37
36
|
|
38
37
|
line = lines[index].strip
|
@@ -66,8 +65,9 @@ module PuppetStrings::Yard::Parsers::Puppet
|
|
66
65
|
end
|
67
66
|
|
68
67
|
private
|
68
|
+
|
69
69
|
def first_line
|
70
|
-
@source.split(
|
70
|
+
@source.split(%r{\r?\n}).first.strip
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -85,14 +85,11 @@ module PuppetStrings::Yard::Parsers::Puppet
|
|
85
85
|
@name = parameter.name
|
86
86
|
# Take the exact text for the type expression
|
87
87
|
if parameter.type_expr
|
88
|
-
|
89
|
-
@type = adapter.extract_text
|
88
|
+
@type = PuppetStrings::Yard::Util.ast_to_text(parameter.type_expr)
|
90
89
|
end
|
91
90
|
# Take the exact text for the default value expression
|
92
|
-
|
93
|
-
|
94
|
-
@value = adapter.extract_text
|
95
|
-
end
|
91
|
+
return unless parameter.value
|
92
|
+
@value = PuppetStrings::Yard::Util.ast_to_text(parameter.value)
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
@@ -146,13 +143,10 @@ module PuppetStrings::Yard::Parsers::Puppet
|
|
146
143
|
def initialize(object, file)
|
147
144
|
super(object, file)
|
148
145
|
@name = object.name
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
@type = adapter.extract_text.gsub('>> ', '')
|
154
|
-
end
|
155
|
-
end
|
146
|
+
return unless object.respond_to? :return_type
|
147
|
+
type = object.return_type
|
148
|
+
return unless type
|
149
|
+
@type = PuppetStrings::Yard::Util.ast_to_text(type).gsub('>> ', '')
|
156
150
|
end
|
157
151
|
end
|
158
152
|
|
@@ -184,12 +178,11 @@ module PuppetStrings::Yard::Parsers::Puppet
|
|
184
178
|
case type_expr
|
185
179
|
when Puppet::Pops::Model::AccessExpression
|
186
180
|
# TODO: I don't like rebuilding the source from the AST, but AccessExpressions don't expose the original source
|
187
|
-
@alias_of = ::
|
188
|
-
@alias_of << type_expr.keys.map { |key| ::
|
181
|
+
@alias_of = PuppetStrings::Yard::Util.ast_to_text(type_expr.left_expr) + '['
|
182
|
+
@alias_of << type_expr.keys.map { |key| PuppetStrings::Yard::Util.ast_to_text(key) }.join(', ')
|
189
183
|
@alias_of << ']'
|
190
184
|
else
|
191
|
-
|
192
|
-
@alias_of = adapter.extract_text
|
185
|
+
@alias_of = PuppetStrings::Yard::Util.ast_to_text(type_expr)
|
193
186
|
end
|
194
187
|
@name = object.name
|
195
188
|
end
|
@@ -3,12 +3,11 @@
|
|
3
3
|
require 'yard/tags/option_tag'
|
4
4
|
|
5
5
|
# Implements an enum tag for describing enumerated value data types
|
6
|
-
|
7
6
|
class PuppetStrings::Yard::Tags::EnumTag < YARD::Tags::OptionTag
|
8
7
|
# Registers the tag with YARD.
|
9
8
|
# @return [void]
|
10
9
|
def self.register!
|
11
|
-
YARD::Tags::Library.define_tag(
|
10
|
+
YARD::Tags::Library.define_tag('puppet.enum', :enum, :with_enums)
|
12
11
|
YARD::Tags::Library.visible_tags.place(:enum).after(:option)
|
13
12
|
end
|
14
13
|
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'yard/tags/default_factory'
|
4
4
|
require 'puppet-strings/yard/tags/enum_tag'
|
5
5
|
|
6
|
+
# Factory for creating tags.
|
6
7
|
class PuppetStrings::Yard::Tags::Factory < YARD::Tags::DefaultFactory
|
7
|
-
|
8
8
|
# Parses tag text and creates a new enum tag type. Modeled after
|
9
9
|
# the parse_tag_with_options method in YARD::Tags::DefaultFactory.
|
10
10
|
#
|