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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +78 -4
- data/CONTRIBUTING.md +32 -2
- data/README.md +81 -17
- data/lib/puppet-strings.rb +13 -4
- data/lib/puppet-strings/describe.rb +68 -0
- data/lib/puppet-strings/json.rb +2 -38
- data/lib/puppet-strings/markdown.rb +3 -1
- data/lib/puppet-strings/markdown/base.rb +37 -16
- data/lib/puppet-strings/markdown/data_type.rb +34 -0
- data/lib/puppet-strings/markdown/data_types.rb +41 -0
- data/lib/puppet-strings/markdown/function.rb +2 -2
- data/lib/puppet-strings/markdown/resource_type.rb +19 -2
- data/lib/puppet-strings/markdown/table_of_contents.rb +1 -0
- data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +12 -4
- data/lib/puppet-strings/markdown/templates/data_type.erb +93 -0
- data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
- data/lib/puppet-strings/markdown/templates/function.erb +36 -1
- data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
- data/lib/puppet-strings/markdown/templates/resource_type.erb +32 -12
- data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
- data/lib/puppet-strings/tasks/generate.rb +10 -3
- data/lib/puppet-strings/version.rb +1 -1
- data/lib/puppet-strings/yard.rb +16 -0
- data/lib/puppet-strings/yard/code_objects.rb +2 -0
- data/lib/puppet-strings/yard/code_objects/class.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/data_type.rb +100 -0
- data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +58 -0
- data/lib/puppet-strings/yard/code_objects/defined_type.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/function.rb +4 -4
- data/lib/puppet-strings/yard/code_objects/plan.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/provider.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/task.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/type.rb +48 -6
- data/lib/puppet-strings/yard/handlers.rb +3 -0
- data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +24 -0
- data/lib/puppet-strings/yard/handlers/ruby/base.rb +12 -1
- data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +393 -0
- data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +2 -12
- data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +1 -9
- data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +3 -3
- data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +135 -0
- data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +56 -0
- data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +9 -115
- data/lib/puppet-strings/yard/parsers/json/parser.rb +4 -2
- data/lib/puppet-strings/yard/parsers/puppet/parser.rb +14 -7
- data/lib/puppet-strings/yard/parsers/puppet/statement.rb +25 -0
- data/lib/puppet-strings/yard/tags.rb +2 -0
- data/lib/puppet-strings/yard/tags/enum_tag.rb +12 -0
- data/lib/puppet-strings/yard/tags/factory.rb +16 -0
- data/lib/puppet-strings/yard/tags/overload_tag.rb +2 -2
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
- data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
- data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
- data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
- data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
- data/lib/puppet-strings/yard/util.rb +48 -0
- data/lib/puppet/face/strings.rb +68 -3
- metadata +36 -45
- data/Gemfile +0 -37
- data/HISTORY.md +0 -218
- data/JSON.md +0 -802
- data/Rakefile +0 -93
- data/codecov.yml +0 -3
- data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
- data/spec/acceptance/emit_json_options.rb +0 -71
- data/spec/acceptance/generate_markdown_spec.rb +0 -49
- data/spec/acceptance/lib/util.rb +0 -163
- data/spec/acceptance/running_strings_generate.rb +0 -54
- data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
- data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
- data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
- data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
- data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
- data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
- data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
- data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
- data/spec/fixtures/unit/json/output.json +0 -660
- data/spec/fixtures/unit/json/output_with_plan.json +0 -697
- data/spec/fixtures/unit/json/output_without_puppet_function.json +0 -480
- data/spec/fixtures/unit/markdown/output.md +0 -444
- data/spec/fixtures/unit/markdown/output_with_plan.md +0 -478
- data/spec/spec_helper.rb +0 -45
- data/spec/spec_helper_acceptance.rb +0 -28
- data/spec/unit/puppet-strings/json_spec.rb +0 -229
- data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
- data/spec/unit/puppet-strings/markdown_spec.rb +0 -283
- data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
- data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -124
- data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
- data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
- data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
- data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
- data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
- data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -214
- data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -269
- data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -70
- data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
- data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
- data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
@@ -35,7 +35,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
35
35
|
# Create and register the function object
|
36
36
|
is_3x = module_name == 'Puppet::Parser::Functions' || module_name == 'newfunction'
|
37
37
|
object = PuppetStrings::Yard::CodeObjects::Function.new(
|
38
|
-
get_name,
|
38
|
+
get_name(statement, 'Puppet::Functions.create_function'),
|
39
39
|
is_3x ? PuppetStrings::Yard::CodeObjects::Function::RUBY_3X : PuppetStrings::Yard::CodeObjects::Function::RUBY_4X
|
40
40
|
)
|
41
41
|
object.source = statement
|
@@ -68,14 +68,6 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
71
|
-
def get_name
|
72
|
-
parameters = statement.parameters(false)
|
73
|
-
raise YARD::Parser::UndocumentableError, "Expected at least one parameter to Puppet::Functions.create_function at #{statement.file}:#{statement.line}." if parameters.empty?
|
74
|
-
name = node_as_string(parameters.first)
|
75
|
-
raise YARD::Parser::UndocumentableError, "Expected a symbol or string literal for first parameter but found '#{parameters.first.type}' at #{statement.file}:#{statement.line}." unless name
|
76
|
-
name
|
77
|
-
end
|
78
|
-
|
79
71
|
def add_tags(object)
|
80
72
|
log.warn "Missing documentation for Puppet function '#{object.name}' at #{statement.file}:#{statement.line}." if object.docstring.empty? && object.tags.empty?
|
81
73
|
log.warn "The docstring for Puppet 4.x function '#{object.name}' contains @param tags near #{object.file}:#{object.line}: parameter documentation should be made on the dispatch call." unless object.tags(:param).empty?
|
@@ -309,9 +301,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
|
|
309
301
|
name = '&' + name
|
310
302
|
end
|
311
303
|
|
312
|
-
|
313
|
-
type = tag && tag.types ? tag.type : 'Any'
|
314
|
-
end
|
304
|
+
type ||= tag && tag.types ? tag.type : 'Any'
|
315
305
|
type = optional ? "Optional[#{type}]" : type
|
316
306
|
|
317
307
|
object.parameters << [name, to_puppet_literal(default)]
|
@@ -24,7 +24,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
24
24
|
raise YARD::Parser::UndocumentableError, "Could not determine the resource type name for the provider defined at #{statement.file}:#{statement.line}." unless type_name
|
25
25
|
|
26
26
|
# Register the object
|
27
|
-
object = PuppetStrings::Yard::CodeObjects::Provider.new(type_name, get_name)
|
27
|
+
object = PuppetStrings::Yard::CodeObjects::Provider.new(type_name, get_name(statement, "'provide'"))
|
28
28
|
register object
|
29
29
|
|
30
30
|
# Extract the docstring
|
@@ -41,14 +41,6 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
|
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
|
-
def get_name
|
45
|
-
parameters = statement.parameters(false)
|
46
|
-
raise YARD::Parser::UndocumentableError, "Expected at least one parameter to 'provide' at #{statement.file}:#{statement.line}." if parameters.empty?
|
47
|
-
name = node_as_string(parameters.first)
|
48
|
-
raise YARD::Parser::UndocumentableError, "Expected a symbol or string literal for first parameter but found '#{parameters.first.type}' at #{statement.file}:#{statement.line}." unless name
|
49
|
-
name
|
50
|
-
end
|
51
|
-
|
52
44
|
def register_provider_docstring(object)
|
53
45
|
# Walk the tree searching for assignments or calls to desc/doc=
|
54
46
|
statement.traverse do |child|
|
@@ -15,7 +15,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
|
|
15
15
|
# Only accept calls to Puppet::ResourceApi
|
16
16
|
return unless statement.count > 1
|
17
17
|
module_name = statement[0].source
|
18
|
-
return unless [
|
18
|
+
return unless ['Puppet::ResourceApi'].include? module_name
|
19
19
|
|
20
20
|
schema = extract_schema
|
21
21
|
|
@@ -71,7 +71,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
|
|
71
71
|
array_from_node(node)
|
72
72
|
when :var_ref
|
73
73
|
var_ref_from_node(node)
|
74
|
-
when :symbol, :symbol_literal, :label, :dyna_symbol, :string_literal
|
74
|
+
when :symbol, :symbol_literal, :label, :dyna_symbol, :string_literal, :regexp_literal
|
75
75
|
node_as_string(node)
|
76
76
|
else
|
77
77
|
raise_parse_error("unexpected construct #{node.type}")
|
@@ -92,7 +92,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
|
|
92
92
|
# puts "hash from #{node.inspect}"
|
93
93
|
|
94
94
|
kv_pairs = node.children.collect do |assoc|
|
95
|
-
[
|
95
|
+
[value_from_node(assoc.children[0]), value_from_node(assoc.children[1])]
|
96
96
|
end
|
97
97
|
Hash[kv_pairs]
|
98
98
|
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'puppet-strings/yard/handlers/ruby/base'
|
2
|
+
|
3
|
+
class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handlers::Ruby::Base
|
4
|
+
protected
|
5
|
+
def get_type_yard_object(name)
|
6
|
+
#Have to guess the path - if we create the object to get the true path from the code,
|
7
|
+
#it also shows up in the .at call - self registering?
|
8
|
+
guess_path = "puppet_types::#{name}"
|
9
|
+
object = YARD::Registry.at(guess_path)
|
10
|
+
|
11
|
+
return object unless object.nil?
|
12
|
+
|
13
|
+
#Didn't find, create instead
|
14
|
+
object = PuppetStrings::Yard::CodeObjects::Type.new(name)
|
15
|
+
register object
|
16
|
+
object
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_docstring(node, kind)
|
20
|
+
# Walk the tree searching for assignments or calls to desc/doc=
|
21
|
+
node.traverse do |child|
|
22
|
+
if child.type == :assign
|
23
|
+
ivar = child.jump(:ivar)
|
24
|
+
next unless ivar != child && ivar.source == '@doc'
|
25
|
+
docstring = node_as_string(child[1])
|
26
|
+
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
|
27
|
+
return PuppetStrings::Yard::Util.scrub_string(docstring)
|
28
|
+
elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
|
29
|
+
# Look for a call to a dispatch method with a block
|
30
|
+
next unless child.method_name &&
|
31
|
+
(child.method_name.source == 'desc' || child.method_name.source == 'doc=') &&
|
32
|
+
child.parameters(false).count == 1
|
33
|
+
|
34
|
+
docstring = node_as_string(child.parameters[0])
|
35
|
+
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
|
36
|
+
return PuppetStrings::Yard::Util.scrub_string(docstring)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
log.warn "Missing a description for #{kind} at #{node.file}:#{node.line}."
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_parameter(name, node)
|
44
|
+
parameter = PuppetStrings::Yard::CodeObjects::Type::Parameter.new(name, find_docstring(node, "Puppet resource parameter '#{name}'"))
|
45
|
+
set_values(node, parameter)
|
46
|
+
parameter
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_property(name, node)
|
50
|
+
property = PuppetStrings::Yard::CodeObjects::Type::Property.new(name, find_docstring(node, "Puppet resource property '#{name}'"))
|
51
|
+
set_values(node, property)
|
52
|
+
property
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_check(name, node)
|
56
|
+
check = PuppetStrings::Yard::CodeObjects::Type::Check.new(name, find_docstring(node, "Puppet resource check '#{name}'"))
|
57
|
+
set_values(node, check)
|
58
|
+
check
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_values(node, object)
|
62
|
+
return unless node.block && node.block.count >= 2
|
63
|
+
|
64
|
+
node.block[1].children.each do |child|
|
65
|
+
next unless child.is_a?(YARD::Parser::Ruby::MethodCallNode) && child.method_name
|
66
|
+
|
67
|
+
method_name = child.method_name.source
|
68
|
+
parameters = child.parameters(false)
|
69
|
+
|
70
|
+
if method_name == 'newvalue'
|
71
|
+
next unless parameters.count >= 1
|
72
|
+
object.add(node_as_string(parameters[0]) || parameters[0].source)
|
73
|
+
elsif method_name == 'newvalues'
|
74
|
+
parameters.each do |p|
|
75
|
+
object.add(node_as_string(p) || p.source)
|
76
|
+
end
|
77
|
+
elsif method_name == 'aliasvalue'
|
78
|
+
next unless parameters.count >= 2
|
79
|
+
object.alias(node_as_string(parameters[0]) || parameters[0].source, node_as_string(parameters[1]) || parameters[1].source)
|
80
|
+
elsif method_name == 'defaultto'
|
81
|
+
next unless parameters.count >= 1
|
82
|
+
object.default = node_as_string(parameters[0]) || parameters[0].source
|
83
|
+
elsif method_name == 'isnamevar'
|
84
|
+
object.isnamevar = true
|
85
|
+
elsif method_name == 'defaultvalues' && object.name == 'ensure'
|
86
|
+
object.add('present')
|
87
|
+
object.add('absent')
|
88
|
+
object.default = 'present'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
parameters = node.parameters(false)
|
93
|
+
|
94
|
+
if parameters.count >= 2
|
95
|
+
kvps = parameters[1].find_all { |kvp| kvp.count == 2 }
|
96
|
+
required_features_kvp = kvps.find { |kvp| node_as_string(kvp[0]) == 'required_features' }
|
97
|
+
object.required_features = node_as_string(required_features_kvp[1]) unless required_features_kvp.nil?
|
98
|
+
end
|
99
|
+
|
100
|
+
if object.is_a? PuppetStrings::Yard::CodeObjects::Type::Parameter
|
101
|
+
# Process the options for parameter base types
|
102
|
+
if parameters.count >= 2
|
103
|
+
parameters[1].each do |kvp|
|
104
|
+
next unless kvp.count == 2
|
105
|
+
next unless node_as_string(kvp[0]) == 'parent'
|
106
|
+
if kvp[1].source == 'Puppet::Parameter::Boolean'
|
107
|
+
object.add('true') unless object.values.include? 'true' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
|
108
|
+
object.add('false') unless object.values.include? 'false' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
|
109
|
+
object.add('yes') unless object.values.include? 'yes' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
|
110
|
+
object.add('no') unless object.values.include? 'no' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
|
111
|
+
end
|
112
|
+
break
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def set_default_namevar(object)
|
119
|
+
return unless object.properties || object.parameters
|
120
|
+
default = nil
|
121
|
+
if object.properties
|
122
|
+
object.properties.each do |property|
|
123
|
+
return nil if property.isnamevar
|
124
|
+
default = property if property.name == 'name'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
if object.parameters
|
128
|
+
object.parameters.each do |parameter|
|
129
|
+
return nil if parameter.isnamevar
|
130
|
+
default ||= parameter if parameter.name == 'name'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
default.isnamevar = true if default
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'puppet-strings/yard/handlers/helpers'
|
2
|
+
require 'puppet-strings/yard/handlers/ruby/type_base'
|
3
|
+
require 'puppet-strings/yard/code_objects'
|
4
|
+
require 'puppet-strings/yard/util'
|
5
|
+
|
6
|
+
# Implements the handler for Puppet resource type newparam/newproperty calls written in Ruby.
|
7
|
+
class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Yard::Handlers::Ruby::TypeBase
|
8
|
+
# The default docstring when ensurable is used without given a docstring.
|
9
|
+
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'.freeze
|
10
|
+
|
11
|
+
namespace_only
|
12
|
+
handles method_call(:newparam)
|
13
|
+
handles method_call(:newproperty)
|
14
|
+
|
15
|
+
process do
|
16
|
+
|
17
|
+
# Our entry point is a type newproperty/newparam compound statement like this:
|
18
|
+
# "Puppet::Type.type(:file).newparam(:content) do"
|
19
|
+
# We want to
|
20
|
+
# Verify the structure
|
21
|
+
# Capture the three parameters (e.g. type: 'file', newproperty or newparam?, name: 'source')
|
22
|
+
# Proceed with collecting data
|
23
|
+
# Either decorate an existing type object or store for future type object parsing
|
24
|
+
|
25
|
+
# Only accept calls to Puppet::Type.type(<type>).newparam/.newproperty
|
26
|
+
# e.g. "Puppet::Type.type(:file).newparam(:content) do" would yield:
|
27
|
+
# module_name: "Puppet::Type"
|
28
|
+
# method1_name: "type"
|
29
|
+
# typename: "file"
|
30
|
+
# method2_name: "newparam"
|
31
|
+
# propertyname: "content"
|
32
|
+
|
33
|
+
return unless (statement.count > 1) && (statement[0].children.count > 2)
|
34
|
+
module_name = statement[0].children[0].source
|
35
|
+
method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source
|
36
|
+
return unless (module_name == 'Puppet::Type' || module_name == 'Type') && method1_name == 'type'
|
37
|
+
|
38
|
+
typename = get_name(statement[0], 'Puppet::Type.type')
|
39
|
+
method2_name = caller_method
|
40
|
+
propertyname = get_name(statement, "Puppet::Type.type().#{method2_name}")
|
41
|
+
|
42
|
+
typeobject = get_type_yard_object(typename)
|
43
|
+
|
44
|
+
# node - what should it be here?
|
45
|
+
node = statement #?? not sure... test...
|
46
|
+
|
47
|
+
if method2_name == 'newproperty'
|
48
|
+
typeobject.add_property(create_property(propertyname, node))
|
49
|
+
elsif method2_name == 'newparam'
|
50
|
+
typeobject.add_parameter(create_parameter(propertyname, node))
|
51
|
+
end
|
52
|
+
|
53
|
+
# Set the default namevar
|
54
|
+
set_default_namevar(typeobject)
|
55
|
+
end
|
56
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'puppet-strings/yard/handlers/helpers'
|
2
|
-
require 'puppet-strings/yard/handlers/ruby/
|
2
|
+
require 'puppet-strings/yard/handlers/ruby/type_base'
|
3
3
|
require 'puppet-strings/yard/code_objects'
|
4
4
|
require 'puppet-strings/yard/util'
|
5
5
|
|
6
6
|
# Implements the handler for Puppet resource types written in Ruby.
|
7
|
-
class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Handlers::Ruby::
|
7
|
+
class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Handlers::Ruby::TypeBase
|
8
8
|
# The default docstring when ensurable is used without given a docstring.
|
9
9
|
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'.freeze
|
10
10
|
|
@@ -17,8 +17,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
17
17
|
module_name = statement[0].source
|
18
18
|
return unless module_name == 'Puppet::Type' || module_name == 'Type'
|
19
19
|
|
20
|
-
object =
|
21
|
-
register object
|
20
|
+
object = get_type_yard_object(get_name(statement, 'Puppet::Type.newtype'))
|
22
21
|
|
23
22
|
docstring = find_docstring(statement, "Puppet resource type '#{object.name}'")
|
24
23
|
register_docstring(object, docstring, nil) if docstring
|
@@ -37,38 +36,6 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
37
36
|
end
|
38
37
|
|
39
38
|
private
|
40
|
-
def get_name
|
41
|
-
parameters = statement.parameters(false)
|
42
|
-
raise YARD::Parser::UndocumentableError, "Expected at least one parameter to Puppet::Type.newtype at #{statement.file}:#{statement.line}." if parameters.empty?
|
43
|
-
name = node_as_string(parameters.first)
|
44
|
-
raise YARD::Parser::UndocumentableError, "Expected a symbol or string literal for first parameter but found '#{parameters.first.type}' at #{statement.file}:#{statement.line}." unless name
|
45
|
-
name
|
46
|
-
end
|
47
|
-
|
48
|
-
def find_docstring(node, kind)
|
49
|
-
# Walk the tree searching for assignments or calls to desc/doc=
|
50
|
-
node.traverse do |child|
|
51
|
-
if child.type == :assign
|
52
|
-
ivar = child.jump(:ivar)
|
53
|
-
next unless ivar != child && ivar.source == '@doc'
|
54
|
-
docstring = node_as_string(child[1])
|
55
|
-
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
|
56
|
-
return PuppetStrings::Yard::Util.scrub_string(docstring)
|
57
|
-
elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
|
58
|
-
# Look for a call to a dispatch method with a block
|
59
|
-
next unless child.method_name &&
|
60
|
-
(child.method_name.source == 'desc' || child.method_name.source == 'doc=') &&
|
61
|
-
child.parameters(false).count == 1
|
62
|
-
|
63
|
-
docstring = node_as_string(child.parameters[0])
|
64
|
-
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
|
65
|
-
return PuppetStrings::Yard::Util.scrub_string(docstring)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
log.warn "Missing a description for #{kind} at #{node.file}:#{node.line}."
|
69
|
-
nil
|
70
|
-
end
|
71
|
-
|
72
39
|
def populate_type_data(object)
|
73
40
|
# Traverse the block looking for properties/parameters/features
|
74
41
|
block = statement.block
|
@@ -92,6 +59,12 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
92
59
|
name = node_as_string(parameters[0])
|
93
60
|
next unless name
|
94
61
|
object.add_parameter(create_parameter(name, node))
|
62
|
+
elsif method_name == 'newcheck'
|
63
|
+
# Add a check to the object
|
64
|
+
next unless parameters.count >= 1
|
65
|
+
name = node_as_string(parameters[0])
|
66
|
+
next unless name
|
67
|
+
object.add_check(create_check(name, node))
|
95
68
|
elsif method_name == 'feature'
|
96
69
|
# Add a feature to the object
|
97
70
|
next unless parameters.count >= 2
|
@@ -116,83 +89,4 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
116
89
|
end
|
117
90
|
end
|
118
91
|
end
|
119
|
-
|
120
|
-
def create_parameter(name, node)
|
121
|
-
parameter = PuppetStrings::Yard::CodeObjects::Type::Parameter.new(name, find_docstring(node, "Puppet resource parameter '#{name}'"))
|
122
|
-
set_values(node, parameter)
|
123
|
-
parameter
|
124
|
-
end
|
125
|
-
|
126
|
-
def create_property(name, node)
|
127
|
-
property = PuppetStrings::Yard::CodeObjects::Type::Property.new(name, find_docstring(node, "Puppet resource property '#{name}'"))
|
128
|
-
set_values(node, property)
|
129
|
-
property
|
130
|
-
end
|
131
|
-
|
132
|
-
def set_values(node, object)
|
133
|
-
return unless node.block && node.block.count >= 2
|
134
|
-
|
135
|
-
node.block[1].children.each do |child|
|
136
|
-
next unless child.is_a?(YARD::Parser::Ruby::MethodCallNode) && child.method_name
|
137
|
-
|
138
|
-
method_name = child.method_name.source
|
139
|
-
parameters = child.parameters(false)
|
140
|
-
|
141
|
-
if method_name == 'newvalue'
|
142
|
-
next unless parameters.count >= 1
|
143
|
-
object.add(node_as_string(parameters[0]) || parameters[0].source)
|
144
|
-
elsif method_name == 'newvalues'
|
145
|
-
parameters.each do |p|
|
146
|
-
object.add(node_as_string(p) || p.source)
|
147
|
-
end
|
148
|
-
elsif method_name == 'aliasvalue'
|
149
|
-
next unless parameters.count >= 2
|
150
|
-
object.alias(node_as_string(parameters[0]) || parameters[0].source, node_as_string(parameters[1]) || parameters[1].source)
|
151
|
-
elsif method_name == 'defaultto'
|
152
|
-
next unless parameters.count >= 1
|
153
|
-
object.default = node_as_string(parameters[0]) || parameters[0].source
|
154
|
-
elsif method_name == 'isnamevar'
|
155
|
-
object.isnamevar = true
|
156
|
-
elsif method_name == 'defaultvalues' && object.name == 'ensure'
|
157
|
-
object.add('present')
|
158
|
-
object.add('absent')
|
159
|
-
object.default = 'present'
|
160
|
-
end
|
161
|
-
end
|
162
|
-
if object.is_a? PuppetStrings::Yard::CodeObjects::Type::Parameter
|
163
|
-
# Process the options for parameter base types
|
164
|
-
parameters = node.parameters(false)
|
165
|
-
if parameters.count >= 2
|
166
|
-
parameters[1].each do |kvp|
|
167
|
-
next unless kvp.count == 2
|
168
|
-
next unless node_as_string(kvp[0]) == 'parent'
|
169
|
-
if kvp[1].source == 'Puppet::Parameter::Boolean'
|
170
|
-
object.add('true') unless object.values.include? 'true'
|
171
|
-
object.add('false') unless object.values.include? 'false'
|
172
|
-
object.add('yes') unless object.values.include? 'yes'
|
173
|
-
object.add('no') unless object.values.include? 'no'
|
174
|
-
end
|
175
|
-
break
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def set_default_namevar(object)
|
182
|
-
return unless object.properties || object.parameters
|
183
|
-
default = nil
|
184
|
-
if object.properties
|
185
|
-
object.properties.each do |property|
|
186
|
-
return nil if property.isnamevar
|
187
|
-
default = property if property.name == 'name'
|
188
|
-
end
|
189
|
-
end
|
190
|
-
if object.parameters
|
191
|
-
object.parameters.each do |parameter|
|
192
|
-
return nil if parameter.isnamevar
|
193
|
-
default ||= parameter if parameter.name == 'name'
|
194
|
-
end
|
195
|
-
end
|
196
|
-
default.isnamevar = true if default
|
197
|
-
end
|
198
92
|
end
|
@@ -22,8 +22,10 @@ class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
|
|
22
22
|
def parse
|
23
23
|
begin
|
24
24
|
json = JSON.parse(source)
|
25
|
-
|
26
|
-
|
25
|
+
# TODO: this should compare json to a Task metadata json-schema or perform some other hueristics
|
26
|
+
# to determine what type of statement it represents
|
27
|
+
@statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) unless json.empty?
|
28
|
+
rescue # rubocop:disable Style/RescueStandardError Just catch everything
|
27
29
|
log.error "Failed to parse #{@file}: "
|
28
30
|
@statements = []
|
29
31
|
end
|