puppet-strings 2.1.0 → 2.2.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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +18 -3
- data/Gemfile +3 -2
- data/Rakefile +5 -0
- data/lib/puppet-strings.rb +10 -1
- data/lib/puppet-strings/describe.rb +68 -0
- data/lib/puppet-strings/json.rb +0 -38
- data/lib/puppet-strings/markdown/base.rb +18 -16
- data/lib/puppet-strings/markdown/templates/function.erb +26 -0
- data/lib/puppet-strings/markdown/templates/resource_type.erb +4 -0
- data/lib/puppet-strings/tasks/generate.rb +7 -1
- data/lib/puppet-strings/version.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/class.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/defined_type.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/function.rb +3 -3
- data/lib/puppet-strings/yard/code_objects/plan.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/provider.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/type.rb +3 -2
- data/lib/puppet-strings/yard/handlers.rb +1 -0
- data/lib/puppet-strings/yard/handlers/ruby/base.rb +11 -0
- data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +1 -9
- data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +1 -9
- data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +1 -1
- data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +130 -0
- data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +56 -0
- data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +3 -115
- data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -1
- data/lib/puppet-strings/yard/tags/overload_tag.rb +1 -1
- data/lib/puppet-strings/yard/util.rb +48 -0
- data/lib/puppet/face/strings.rb +66 -1
- data/spec/fixtures/unit/markdown/output.md +64 -0
- data/spec/fixtures/unit/markdown/output_with_plan.md +64 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/puppet-strings/describe_spec.rb +141 -0
- data/spec/unit/puppet-strings/json_spec.rb +65 -11
- data/spec/unit/puppet-strings/markdown_spec.rb +13 -0
- data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +4 -12
- data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +1 -1
- data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +21 -0
- data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +26 -0
- data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +5 -3
- metadata +7 -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
@@ -22,7 +22,7 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
|
|
22
22
|
# Represents a resource type parameter.
|
23
23
|
class Parameter
|
24
24
|
attr_reader :name, :values, :aliases
|
25
|
-
attr_accessor :docstring, :isnamevar, :default, :data_type
|
25
|
+
attr_accessor :docstring, :isnamevar, :default, :data_type, :required_features
|
26
26
|
|
27
27
|
# Initializes a resource type parameter or property.
|
28
28
|
# @param [String] name The name of the parameter or property.
|
@@ -63,6 +63,7 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
|
|
63
63
|
hash[:data_type] = data_type unless data_type.empty?
|
64
64
|
hash[:aliases] = aliases unless aliases.empty?
|
65
65
|
hash[:isnamevar] = true if isnamevar
|
66
|
+
hash[:required_features] = required_features if required_features
|
66
67
|
hash[:default] = default if default
|
67
68
|
hash
|
68
69
|
end
|
@@ -140,7 +141,7 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
|
|
140
141
|
hash[:name] = name
|
141
142
|
hash[:file] = file
|
142
143
|
hash[:line] = line
|
143
|
-
hash[:docstring] = PuppetStrings::
|
144
|
+
hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
|
144
145
|
hash[:properties] = properties.map(&:to_hash) if properties && !properties.empty?
|
145
146
|
hash[:parameters] = parameters.map(&:to_hash) if parameters && !parameters.empty?
|
146
147
|
hash[:features] = features.map(&:to_hash) if features && !features.empty?
|
@@ -3,6 +3,7 @@ module PuppetStrings::Yard::Handlers
|
|
3
3
|
# The module for custom Ruby YARD handlers.
|
4
4
|
module Ruby
|
5
5
|
require 'puppet-strings/yard/handlers/ruby/type_handler'
|
6
|
+
require 'puppet-strings/yard/handlers/ruby/type_extras_handler'
|
6
7
|
require 'puppet-strings/yard/handlers/ruby/rsapi_handler'
|
7
8
|
require 'puppet-strings/yard/handlers/ruby/provider_handler'
|
8
9
|
require 'puppet-strings/yard/handlers/ruby/function_handler'
|
@@ -33,6 +33,17 @@ class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base
|
|
33
33
|
end
|
34
34
|
|
35
35
|
source
|
36
|
+
when :regexp_literal
|
37
|
+
node.source
|
36
38
|
end
|
37
39
|
end
|
40
|
+
|
41
|
+
def get_name(statementobject, statementtype)
|
42
|
+
parameters = statementobject.parameters(false)
|
43
|
+
raise YARD::Parser::UndocumentableError, "Expected at least one parameter to #{statementtype} at #{statementobject.file}:#{statementobject.line}." if parameters.empty?
|
44
|
+
name = node_as_string(parameters.first)
|
45
|
+
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
|
46
|
+
name
|
47
|
+
end
|
48
|
+
|
38
49
|
end
|
@@ -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?
|
@@ -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|
|
@@ -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}")
|
@@ -0,0 +1,130 @@
|
|
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 set_values(node, object)
|
56
|
+
return unless node.block && node.block.count >= 2
|
57
|
+
|
58
|
+
node.block[1].children.each do |child|
|
59
|
+
next unless child.is_a?(YARD::Parser::Ruby::MethodCallNode) && child.method_name
|
60
|
+
|
61
|
+
method_name = child.method_name.source
|
62
|
+
parameters = child.parameters(false)
|
63
|
+
|
64
|
+
if method_name == 'newvalue'
|
65
|
+
next unless parameters.count >= 1
|
66
|
+
object.add(node_as_string(parameters[0]) || parameters[0].source)
|
67
|
+
elsif method_name == 'newvalues'
|
68
|
+
parameters.each do |p|
|
69
|
+
object.add(node_as_string(p) || p.source)
|
70
|
+
end
|
71
|
+
elsif method_name == 'aliasvalue'
|
72
|
+
next unless parameters.count >= 2
|
73
|
+
object.alias(node_as_string(parameters[0]) || parameters[0].source, node_as_string(parameters[1]) || parameters[1].source)
|
74
|
+
elsif method_name == 'defaultto'
|
75
|
+
next unless parameters.count >= 1
|
76
|
+
object.default = node_as_string(parameters[0]) || parameters[0].source
|
77
|
+
elsif method_name == 'isnamevar'
|
78
|
+
object.isnamevar = true
|
79
|
+
elsif method_name == 'defaultvalues' && object.name == 'ensure'
|
80
|
+
object.add('present')
|
81
|
+
object.add('absent')
|
82
|
+
object.default = 'present'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
parameters = node.parameters(false)
|
87
|
+
|
88
|
+
if parameters.count >= 2
|
89
|
+
kvps = parameters[1].find_all { |kvp| kvp.count == 2 }
|
90
|
+
required_features_kvp = kvps.find { |kvp| node_as_string(kvp[0]) == 'required_features' }
|
91
|
+
object.required_features = node_as_string(required_features_kvp[1]) unless required_features_kvp.nil?
|
92
|
+
end
|
93
|
+
|
94
|
+
if object.is_a? PuppetStrings::Yard::CodeObjects::Type::Parameter
|
95
|
+
# Process the options for parameter base types
|
96
|
+
if parameters.count >= 2
|
97
|
+
parameters[1].each do |kvp|
|
98
|
+
next unless kvp.count == 2
|
99
|
+
next unless node_as_string(kvp[0]) == 'parent'
|
100
|
+
if kvp[1].source == 'Puppet::Parameter::Boolean'
|
101
|
+
object.add('true') unless object.values.include? 'true'
|
102
|
+
object.add('false') unless object.values.include? 'false'
|
103
|
+
object.add('yes') unless object.values.include? 'yes'
|
104
|
+
object.add('no') unless object.values.include? 'no'
|
105
|
+
end
|
106
|
+
break
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def set_default_namevar(object)
|
113
|
+
return unless object.properties || object.parameters
|
114
|
+
default = nil
|
115
|
+
if object.properties
|
116
|
+
object.properties.each do |property|
|
117
|
+
return nil if property.isnamevar
|
118
|
+
default = property if property.name == 'name'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
if object.parameters
|
122
|
+
object.parameters.each do |parameter|
|
123
|
+
return nil if parameter.isnamevar
|
124
|
+
default ||= parameter if parameter.name == 'name'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
default.isnamevar = true if default
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
@@ -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[1].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
|
@@ -116,83 +83,4 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
|
|
116
83
|
end
|
117
84
|
end
|
118
85
|
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
86
|
end
|
@@ -22,7 +22,9 @@ class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
|
|
22
22
|
def parse
|
23
23
|
begin
|
24
24
|
json = JSON.parse(source)
|
25
|
-
|
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?
|
26
28
|
rescue
|
27
29
|
log.error "Failed to parse #{@file}: "
|
28
30
|
@statements = []
|