openvox-strings 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +407 -0
- data/LICENSE +177 -0
- data/README.md +116 -0
- data/lib/openvox-strings/describe.rb +75 -0
- data/lib/openvox-strings/json.rb +33 -0
- data/lib/openvox-strings/markdown/base.rb +236 -0
- data/lib/openvox-strings/markdown/data_type.rb +39 -0
- data/lib/openvox-strings/markdown/defined_type.rb +20 -0
- data/lib/openvox-strings/markdown/function.rb +59 -0
- data/lib/openvox-strings/markdown/helpers.rb +21 -0
- data/lib/openvox-strings/markdown/puppet_class.rb +20 -0
- data/lib/openvox-strings/markdown/puppet_plan.rb +20 -0
- data/lib/openvox-strings/markdown/puppet_task.rb +29 -0
- data/lib/openvox-strings/markdown/resource_type.rb +56 -0
- data/lib/openvox-strings/markdown/templates/classes_and_defines.erb +94 -0
- data/lib/openvox-strings/markdown/templates/data_type.erb +101 -0
- data/lib/openvox-strings/markdown/templates/data_type_function.erb +67 -0
- data/lib/openvox-strings/markdown/templates/function.erb +106 -0
- data/lib/openvox-strings/markdown/templates/puppet_task.erb +28 -0
- data/lib/openvox-strings/markdown/templates/resource_type.erb +156 -0
- data/lib/openvox-strings/markdown/templates/table_of_contents.erb +26 -0
- data/lib/openvox-strings/markdown.rb +81 -0
- data/lib/openvox-strings/monkey_patches/display_object_command.rb +16 -0
- data/lib/openvox-strings/tasks/generate.rb +54 -0
- data/lib/openvox-strings/tasks/gh_pages.rb +72 -0
- data/lib/openvox-strings/tasks/validate.rb +42 -0
- data/lib/openvox-strings/tasks.rb +14 -0
- data/lib/openvox-strings/version.rb +5 -0
- data/lib/openvox-strings/yard/code_objects/base.rb +16 -0
- data/lib/openvox-strings/yard/code_objects/class.rb +60 -0
- data/lib/openvox-strings/yard/code_objects/data_type.rb +102 -0
- data/lib/openvox-strings/yard/code_objects/data_type_alias.rb +60 -0
- data/lib/openvox-strings/yard/code_objects/defined_type.rb +59 -0
- data/lib/openvox-strings/yard/code_objects/function.rb +106 -0
- data/lib/openvox-strings/yard/code_objects/group.rb +33 -0
- data/lib/openvox-strings/yard/code_objects/plan.rb +59 -0
- data/lib/openvox-strings/yard/code_objects/provider.rb +98 -0
- data/lib/openvox-strings/yard/code_objects/task.rb +69 -0
- data/lib/openvox-strings/yard/code_objects/type.rb +196 -0
- data/lib/openvox-strings/yard/code_objects.rb +14 -0
- data/lib/openvox-strings/yard/handlers/helpers.rb +10 -0
- data/lib/openvox-strings/yard/handlers/json/base.rb +8 -0
- data/lib/openvox-strings/yard/handlers/json/task_handler.rb +34 -0
- data/lib/openvox-strings/yard/handlers/puppet/base.rb +52 -0
- data/lib/openvox-strings/yard/handlers/puppet/class_handler.rb +29 -0
- data/lib/openvox-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
- data/lib/openvox-strings/yard/handlers/puppet/defined_type_handler.rb +29 -0
- data/lib/openvox-strings/yard/handlers/puppet/function_handler.rb +54 -0
- data/lib/openvox-strings/yard/handlers/puppet/plan_handler.rb +29 -0
- data/lib/openvox-strings/yard/handlers/ruby/base.rb +55 -0
- data/lib/openvox-strings/yard/handlers/ruby/data_type_handler.rb +411 -0
- data/lib/openvox-strings/yard/handlers/ruby/function_handler.rb +386 -0
- data/lib/openvox-strings/yard/handlers/ruby/provider_handler.rb +127 -0
- data/lib/openvox-strings/yard/handlers/ruby/rsapi_handler.rb +157 -0
- data/lib/openvox-strings/yard/handlers/ruby/type_base.rb +146 -0
- data/lib/openvox-strings/yard/handlers/ruby/type_extras_handler.rb +65 -0
- data/lib/openvox-strings/yard/handlers/ruby/type_handler.rb +105 -0
- data/lib/openvox-strings/yard/handlers.rb +28 -0
- data/lib/openvox-strings/yard/parsers/json/parser.rb +38 -0
- data/lib/openvox-strings/yard/parsers/json/task_statement.rb +37 -0
- data/lib/openvox-strings/yard/parsers/puppet/parser.rb +89 -0
- data/lib/openvox-strings/yard/parsers/puppet/statement.rb +182 -0
- data/lib/openvox-strings/yard/parsers.rb +14 -0
- data/lib/openvox-strings/yard/tags/enum_tag.rb +13 -0
- data/lib/openvox-strings/yard/tags/factory.rb +18 -0
- data/lib/openvox-strings/yard/tags/overload_tag.rb +112 -0
- data/lib/openvox-strings/yard/tags/parameter_directive.rb +25 -0
- data/lib/openvox-strings/yard/tags/property_directive.rb +25 -0
- data/lib/openvox-strings/yard/tags/summary_tag.rb +10 -0
- data/lib/openvox-strings/yard/tags.rb +11 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/css/common.css +8 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_plan.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_task.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/setup.rb +93 -0
- data/lib/openvox-strings/yard/templates/default/layout/html/footer.erb +3 -0
- data/lib/openvox-strings/yard/templates/default/layout/html/objects.erb +37 -0
- data/lib/openvox-strings/yard/templates/default/layout/html/setup.rb +231 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/box_info.erb +26 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/setup.rb +16 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/setup.rb +15 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +19 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/setup.rb +7 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/box_info.erb +14 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/overview.erb +18 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/setup.rb +7 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/setup.rb +13 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/box_info.erb +14 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/collection.erb +17 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/features.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/setup.rb +31 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/box_info.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/input.erb +5 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/parameters.erb +16 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/setup.rb +24 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/supports_noop.erb +3 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/box_info.erb +20 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/features.erb +13 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/parameters.erb +35 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/setup.rb +36 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/tags/html/enum.erb +17 -0
- data/lib/openvox-strings/yard/templates/default/tags/html/puppet_overload.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/tags/setup.rb +20 -0
- data/lib/openvox-strings/yard/util.rb +87 -0
- data/lib/openvox-strings/yard.rb +132 -0
- data/lib/openvox-strings.rb +88 -0
- data/lib/puppet/application/strings.rb +7 -0
- data/lib/puppet/face/strings.rb +185 -0
- data/lib/puppet/feature/rgen.rb +5 -0
- data/lib/puppet/feature/yard.rb +5 -0
- metadata +263 -0
@@ -0,0 +1,146 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/yard/handlers/ruby/base'
|
4
|
+
|
5
|
+
# Base class for all Puppet resource type handlers.
|
6
|
+
class OpenvoxStrings::Yard::Handlers::Ruby::TypeBase < OpenvoxStrings::Yard::Handlers::Ruby::Base
|
7
|
+
protected
|
8
|
+
|
9
|
+
def get_type_yard_object(name)
|
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?
|
12
|
+
guess_path = "puppet_types::#{name}"
|
13
|
+
object = YARD::Registry.at(guess_path)
|
14
|
+
|
15
|
+
return object unless object.nil?
|
16
|
+
|
17
|
+
# Didn't find, create instead
|
18
|
+
object = OpenvoxStrings::Yard::CodeObjects::Type.new(name)
|
19
|
+
register object
|
20
|
+
object
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_docstring(node, kind)
|
24
|
+
# Walk the tree searching for assignments or calls to desc/doc=
|
25
|
+
node.traverse do |child|
|
26
|
+
if child.type == :assign
|
27
|
+
ivar = child.jump(:ivar)
|
28
|
+
next unless ivar != child && ivar.source == '@doc'
|
29
|
+
|
30
|
+
docstring = node_as_string(child[1])
|
31
|
+
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
|
32
|
+
|
33
|
+
return OpenvoxStrings::Yard::Util.scrub_string(docstring)
|
34
|
+
elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
|
35
|
+
# Look for a call to a dispatch method with a block
|
36
|
+
next unless child.method_name &&
|
37
|
+
['desc', 'doc='].include?(child.method_name.source) &&
|
38
|
+
child.parameters(false).count == 1
|
39
|
+
|
40
|
+
docstring = node_as_string(child.parameters[0])
|
41
|
+
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
|
42
|
+
|
43
|
+
return OpenvoxStrings::Yard::Util.scrub_string(docstring)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
log.warn "Missing a description for #{kind} at #{node.file}:#{node.line}."
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_parameter(name, node)
|
51
|
+
parameter = OpenvoxStrings::Yard::CodeObjects::Type::Parameter.new(name, find_docstring(node, "Puppet resource parameter '#{name}'"))
|
52
|
+
set_values(node, parameter)
|
53
|
+
parameter
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_property(name, node)
|
57
|
+
property = OpenvoxStrings::Yard::CodeObjects::Type::Property.new(name, find_docstring(node, "Puppet resource property '#{name}'"))
|
58
|
+
set_values(node, property)
|
59
|
+
property
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_check(name, node)
|
63
|
+
check = OpenvoxStrings::Yard::CodeObjects::Type::Check.new(name, find_docstring(node, "Puppet resource check '#{name}'"))
|
64
|
+
set_values(node, check)
|
65
|
+
check
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_values(node, object)
|
69
|
+
return unless node.block && node.block.count >= 2
|
70
|
+
|
71
|
+
node.block[1].children.each do |child|
|
72
|
+
next unless child.is_a?(YARD::Parser::Ruby::MethodCallNode) && child.method_name
|
73
|
+
|
74
|
+
method_name = child.method_name.source
|
75
|
+
parameters = child.parameters(false)
|
76
|
+
|
77
|
+
if method_name == 'newvalue'
|
78
|
+
next unless parameters.count >= 1
|
79
|
+
|
80
|
+
object.add(node_as_string(parameters[0]) || parameters[0].source)
|
81
|
+
elsif method_name == 'newvalues'
|
82
|
+
parameters.each do |p|
|
83
|
+
object.add(node_as_string(p) || p.source)
|
84
|
+
end
|
85
|
+
elsif method_name == 'aliasvalue'
|
86
|
+
next unless parameters.count >= 2
|
87
|
+
|
88
|
+
object.alias(node_as_string(parameters[0]) || parameters[0].source, node_as_string(parameters[1]) || parameters[1].source)
|
89
|
+
elsif method_name == 'defaultto'
|
90
|
+
next unless parameters.count >= 1
|
91
|
+
|
92
|
+
object.default = node_as_string(parameters[0]) || parameters[0].source
|
93
|
+
elsif method_name == 'isnamevar'
|
94
|
+
object.isnamevar = true
|
95
|
+
elsif method_name == 'defaultvalues' && object.name == 'ensure'
|
96
|
+
object.add('present')
|
97
|
+
object.add('absent')
|
98
|
+
object.default = 'present'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
parameters = node.parameters(false)
|
103
|
+
|
104
|
+
if parameters.count >= 2
|
105
|
+
kvps = parameters[1].select { |kvp| kvp.count == 2 }
|
106
|
+
required_features_kvp = kvps.find { |kvp| node_as_string(kvp[0]) == 'required_features' }
|
107
|
+
object.required_features = node_as_string(required_features_kvp[1]) unless required_features_kvp.nil?
|
108
|
+
end
|
109
|
+
|
110
|
+
return unless object.is_a? OpenvoxStrings::Yard::CodeObjects::Type::Parameter
|
111
|
+
# Process the options for parameter base types
|
112
|
+
return unless parameters.count >= 2
|
113
|
+
|
114
|
+
parameters[1].each do |kvp|
|
115
|
+
next unless kvp.count == 2
|
116
|
+
next unless node_as_string(kvp[0]) == 'parent'
|
117
|
+
|
118
|
+
if kvp[1].source == 'Puppet::Parameter::Boolean'
|
119
|
+
# rubocop:disable Performance/InefficientHashSearch
|
120
|
+
object.add('true') unless object.values.include? 'true'
|
121
|
+
object.add('false') unless object.values.include? 'false'
|
122
|
+
object.add('yes') unless object.values.include? 'yes'
|
123
|
+
object.add('no') unless object.values.include? 'no'
|
124
|
+
# rubocop:enable Performance/InefficientHashSearch
|
125
|
+
end
|
126
|
+
break
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def set_default_namevar(object)
|
131
|
+
return unless object.properties || object.parameters
|
132
|
+
|
133
|
+
default = nil
|
134
|
+
object.properties&.each do |property|
|
135
|
+
return nil if property.isnamevar
|
136
|
+
|
137
|
+
default = property if property.name == 'name'
|
138
|
+
end
|
139
|
+
object.parameters&.each do |parameter|
|
140
|
+
return nil if parameter.isnamevar
|
141
|
+
|
142
|
+
default ||= parameter if parameter.name == 'name'
|
143
|
+
end
|
144
|
+
default.isnamevar = true if default
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/yard/handlers/helpers'
|
4
|
+
require 'openvox-strings/yard/handlers/ruby/type_base'
|
5
|
+
require 'openvox-strings/yard/code_objects'
|
6
|
+
require 'openvox-strings/yard/util'
|
7
|
+
|
8
|
+
# Implements the handler for Puppet resource type newparam/newproperty/ensurable calls written in Ruby.
|
9
|
+
class OpenvoxStrings::Yard::Handlers::Ruby::TypeExtrasHandler < OpenvoxStrings::Yard::Handlers::Ruby::TypeBase
|
10
|
+
# The default docstring when ensurable is used without given a docstring.
|
11
|
+
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
|
12
|
+
|
13
|
+
namespace_only
|
14
|
+
handles method_call(:newparam)
|
15
|
+
handles method_call(:newproperty)
|
16
|
+
handles method_call(:ensurable)
|
17
|
+
|
18
|
+
process do
|
19
|
+
# Our entry point is a type newproperty/newparam compound statement like this:
|
20
|
+
# "Puppet::Type.type(:file).newparam(:content) do"
|
21
|
+
# We want to
|
22
|
+
# Verify the structure
|
23
|
+
# Capture the three parameters (e.g. type: 'file', newproperty or newparam?, name: 'source')
|
24
|
+
# Proceed with collecting data
|
25
|
+
# Either decorate an existing type object or store for future type object parsing
|
26
|
+
|
27
|
+
# Only accept calls to Puppet::Type.type(<type>).newparam/.newproperty
|
28
|
+
# e.g. "Puppet::Type.type(:file).newparam(:content) do" would yield:
|
29
|
+
# module_name: "Puppet::Type"
|
30
|
+
# method1_name: "type"
|
31
|
+
# typename: "file"
|
32
|
+
# method2_name: "newparam"
|
33
|
+
# propertyname: "content"
|
34
|
+
|
35
|
+
return unless (statement.count > 1) && (statement[0].children.count > 2)
|
36
|
+
|
37
|
+
module_name = statement[0].children[0].source
|
38
|
+
method1_name = statement[0].children.drop(1).find { |c| c.type == :ident }.source
|
39
|
+
return unless ['Type', 'Puppet::Type'].include?(module_name) && method1_name == 'type'
|
40
|
+
|
41
|
+
# ensurable is syntatic sugar for newproperty
|
42
|
+
typename = get_name(statement[0], 'Puppet::Type.type')
|
43
|
+
if caller_method == 'ensurable'
|
44
|
+
method2_name = 'newproperty'
|
45
|
+
propertyname = 'ensure'
|
46
|
+
else
|
47
|
+
method2_name = caller_method
|
48
|
+
propertyname = get_name(statement, "Puppet::Type.type().#{method2_name}")
|
49
|
+
end
|
50
|
+
|
51
|
+
typeobject = get_type_yard_object(typename)
|
52
|
+
|
53
|
+
# node - what should it be here?
|
54
|
+
node = statement # ?? not sure... test...
|
55
|
+
|
56
|
+
if method2_name == 'newproperty'
|
57
|
+
typeobject.add_property(create_property(propertyname, node))
|
58
|
+
elsif method2_name == 'newparam'
|
59
|
+
typeobject.add_parameter(create_parameter(propertyname, node))
|
60
|
+
end
|
61
|
+
|
62
|
+
# Set the default namevar
|
63
|
+
set_default_namevar(typeobject)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/yard/handlers/helpers'
|
4
|
+
require 'openvox-strings/yard/handlers/ruby/type_base'
|
5
|
+
require 'openvox-strings/yard/code_objects'
|
6
|
+
require 'openvox-strings/yard/util'
|
7
|
+
|
8
|
+
# Implements the handler for Puppet resource types written in Ruby.
|
9
|
+
class OpenvoxStrings::Yard::Handlers::Ruby::TypeHandler < OpenvoxStrings::Yard::Handlers::Ruby::TypeBase
|
10
|
+
# The default docstring when ensurable is used without given a docstring.
|
11
|
+
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
|
12
|
+
|
13
|
+
namespace_only
|
14
|
+
handles method_call(:newtype)
|
15
|
+
|
16
|
+
process do
|
17
|
+
# Only accept calls to Puppet::Type
|
18
|
+
return unless statement.count > 1
|
19
|
+
|
20
|
+
module_name = statement[0].source
|
21
|
+
return unless ['Puppet::Type', 'Type'].include?(module_name)
|
22
|
+
|
23
|
+
object = get_type_yard_object(get_name(statement, 'Puppet::Type.newtype'))
|
24
|
+
|
25
|
+
docstring = find_docstring(statement, "Puppet resource type '#{object.name}'")
|
26
|
+
register_docstring(object, docstring, nil) if docstring
|
27
|
+
|
28
|
+
# Populate the parameters/properties/features to the type
|
29
|
+
populate_type_data(object)
|
30
|
+
|
31
|
+
# Set the default namevar
|
32
|
+
set_default_namevar(object)
|
33
|
+
|
34
|
+
# Mark the type as public if it doesn't already have an api tag
|
35
|
+
object.add_tag YARD::Tags::Tag.new(:api, 'public') unless object.has_tag? :api
|
36
|
+
|
37
|
+
# Warn if a summary longer than 140 characters was provided
|
38
|
+
OpenvoxStrings::Yard::Handlers::Helpers.validate_summary_tag(object) if object.has_tag? :summary
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def populate_type_data(object)
|
44
|
+
# Traverse the block looking for properties/parameters/features
|
45
|
+
block = statement.block
|
46
|
+
return unless block && block.count >= 2
|
47
|
+
|
48
|
+
block[1].children.each do |node|
|
49
|
+
next unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) &&
|
50
|
+
node.method_name
|
51
|
+
|
52
|
+
method_name = node.method_name.source
|
53
|
+
parameters = node.parameters(false)
|
54
|
+
|
55
|
+
case method_name
|
56
|
+
when 'newproperty'
|
57
|
+
# Add a property to the object
|
58
|
+
next unless parameters.count >= 1
|
59
|
+
|
60
|
+
name = node_as_string(parameters[0])
|
61
|
+
next unless name
|
62
|
+
|
63
|
+
object.add_property(create_property(name, node))
|
64
|
+
when 'newparam'
|
65
|
+
# Add a parameter to the object
|
66
|
+
next unless parameters.count >= 1
|
67
|
+
|
68
|
+
name = node_as_string(parameters[0])
|
69
|
+
next unless name
|
70
|
+
|
71
|
+
object.add_parameter(create_parameter(name, node))
|
72
|
+
when 'newcheck'
|
73
|
+
# Add a check to the object
|
74
|
+
next unless parameters.count >= 1
|
75
|
+
|
76
|
+
name = node_as_string(parameters[0])
|
77
|
+
next unless name
|
78
|
+
|
79
|
+
object.add_check(create_check(name, node))
|
80
|
+
when 'feature'
|
81
|
+
# Add a feature to the object
|
82
|
+
next unless parameters.count >= 2
|
83
|
+
|
84
|
+
name = node_as_string(parameters[0])
|
85
|
+
next unless name
|
86
|
+
|
87
|
+
docstring = node_as_string(parameters[1])
|
88
|
+
next unless docstring
|
89
|
+
|
90
|
+
object.add_feature(OpenvoxStrings::Yard::CodeObjects::Type::Feature.new(name, docstring))
|
91
|
+
when 'ensurable'
|
92
|
+
if node.block
|
93
|
+
property = create_property('ensure', node)
|
94
|
+
property.docstring = DEFAULT_ENSURABLE_DOCSTRING if property.docstring.empty?
|
95
|
+
else
|
96
|
+
property = OpenvoxStrings::Yard::CodeObjects::Type::Property.new('ensure', DEFAULT_ENSURABLE_DOCSTRING)
|
97
|
+
property.add('present')
|
98
|
+
property.add('absent')
|
99
|
+
property.default = 'present'
|
100
|
+
end
|
101
|
+
object.add_property property
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The module for custom YARD handlers.
|
4
|
+
module OpenvoxStrings::Yard::Handlers
|
5
|
+
# The module for custom Ruby YARD handlers.
|
6
|
+
module Ruby
|
7
|
+
require 'openvox-strings/yard/handlers/ruby/data_type_handler'
|
8
|
+
require 'openvox-strings/yard/handlers/ruby/type_handler'
|
9
|
+
require 'openvox-strings/yard/handlers/ruby/type_extras_handler'
|
10
|
+
require 'openvox-strings/yard/handlers/ruby/rsapi_handler'
|
11
|
+
require 'openvox-strings/yard/handlers/ruby/provider_handler'
|
12
|
+
require 'openvox-strings/yard/handlers/ruby/function_handler'
|
13
|
+
end
|
14
|
+
|
15
|
+
# The module for custom JSON YARD handlers.
|
16
|
+
module JSON
|
17
|
+
require 'openvox-strings/yard/handlers/json/task_handler'
|
18
|
+
end
|
19
|
+
|
20
|
+
# The module for custom Puppet YARD handlers.
|
21
|
+
module Puppet
|
22
|
+
require 'openvox-strings/yard/handlers/puppet/class_handler'
|
23
|
+
require 'openvox-strings/yard/handlers/puppet/data_type_alias_handler'
|
24
|
+
require 'openvox-strings/yard/handlers/puppet/defined_type_handler'
|
25
|
+
require 'openvox-strings/yard/handlers/puppet/function_handler'
|
26
|
+
require 'openvox-strings/yard/handlers/puppet/plan_handler'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/yard/parsers/json/task_statement'
|
4
|
+
|
5
|
+
# Implementas a JSON parser.
|
6
|
+
class OpenvoxStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
|
7
|
+
attr_reader :file, :source
|
8
|
+
|
9
|
+
# Initializes the parser.
|
10
|
+
# @param [String] source The source being parsed.
|
11
|
+
# @param [String] filename The file name of the file being parsed.
|
12
|
+
# @return [void]
|
13
|
+
def initialize(source, filename) # rubocop:disable Lint/MissingSuper
|
14
|
+
@file = filename
|
15
|
+
@source = source
|
16
|
+
@statements = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def enumerator
|
20
|
+
@statements
|
21
|
+
end
|
22
|
+
|
23
|
+
# Parses the source
|
24
|
+
# @return [void]
|
25
|
+
def parse
|
26
|
+
begin
|
27
|
+
json = JSON.parse(source)
|
28
|
+
# TODO: this should compare json to a Task metadata json-schema or perform some other hueristics
|
29
|
+
# to determine what type of statement it represents
|
30
|
+
@statements.push(OpenvoxStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) unless json.empty?
|
31
|
+
rescue StandardError
|
32
|
+
log.error "Failed to parse #{@file}: "
|
33
|
+
@statements = []
|
34
|
+
end
|
35
|
+
@statements.freeze
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenvoxStrings::Yard::Parsers::JSON
|
4
|
+
# Represents the Puppet Task statement.
|
5
|
+
class TaskStatement
|
6
|
+
attr_reader :line, :comments_range, :json, :file, :source, :docstring
|
7
|
+
|
8
|
+
def initialize(json, source, file)
|
9
|
+
@file = file
|
10
|
+
@source = source
|
11
|
+
@json = json
|
12
|
+
@line = 0
|
13
|
+
@comments_range = nil
|
14
|
+
@docstring = YARD::Docstring.new(@json['description'])
|
15
|
+
end
|
16
|
+
|
17
|
+
def parameters
|
18
|
+
json['parameters'] || {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def comments_hash_flag
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
def show
|
26
|
+
''
|
27
|
+
end
|
28
|
+
|
29
|
+
def comments
|
30
|
+
docstring.all
|
31
|
+
end
|
32
|
+
|
33
|
+
def name
|
34
|
+
File.basename(@file).gsub('.json', '') || ''
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'puppet'
|
4
|
+
require 'puppet/pops'
|
5
|
+
require 'openvox-strings/yard/parsers/puppet/statement'
|
6
|
+
|
7
|
+
# Implements the Puppet language parser.
|
8
|
+
class OpenvoxStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
|
9
|
+
attr_reader :file, :source
|
10
|
+
|
11
|
+
# Initializes the parser.
|
12
|
+
# @param [String] source The source being parsed.
|
13
|
+
# @param [String] filename The file name of the file being parsed.
|
14
|
+
# @return [void]
|
15
|
+
def initialize(source, filename) # rubocop:disable Lint/MissingSuper
|
16
|
+
@source = source
|
17
|
+
@file = filename
|
18
|
+
@visitor = ::Puppet::Pops::Visitor.new(self, 'transform')
|
19
|
+
end
|
20
|
+
|
21
|
+
# Parses the source.
|
22
|
+
# @return [void]
|
23
|
+
def parse
|
24
|
+
begin
|
25
|
+
Puppet[:tasks] = true if Puppet.settings.include?(:tasks)
|
26
|
+
@statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact
|
27
|
+
rescue ::Puppet::ParseError => e
|
28
|
+
log.error "Failed to parse #{@file}: #{e.message}"
|
29
|
+
@statements = []
|
30
|
+
end
|
31
|
+
@statements.freeze
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# Gets an enumerator for the statements that were parsed.
|
36
|
+
# @return Returns an enumerator for the statements that were parsed.
|
37
|
+
def enumerator
|
38
|
+
@statements
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# TODO: Fix the rubocop violations in this file between the following rubocop:disable/enable lines
|
44
|
+
# rubocop:disable Naming/MethodName
|
45
|
+
def transform_Program(o)
|
46
|
+
# Cache the lines of the source text; we'll use this to locate comments
|
47
|
+
@lines = o.source_text.lines.to_a
|
48
|
+
o.definitions.map { |d| @visitor.visit(d) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def transform_Factory(o)
|
52
|
+
@visitor.visit(o.current)
|
53
|
+
end
|
54
|
+
|
55
|
+
def transform_HostClassDefinition(o)
|
56
|
+
statement = OpenvoxStrings::Yard::Parsers::Puppet::ClassStatement.new(o, @file)
|
57
|
+
statement.extract_docstring(@lines)
|
58
|
+
statement
|
59
|
+
end
|
60
|
+
|
61
|
+
def transform_ResourceTypeDefinition(o)
|
62
|
+
statement = OpenvoxStrings::Yard::Parsers::Puppet::DefinedTypeStatement.new(o, @file)
|
63
|
+
statement.extract_docstring(@lines)
|
64
|
+
statement
|
65
|
+
end
|
66
|
+
|
67
|
+
def transform_FunctionDefinition(o)
|
68
|
+
statement = OpenvoxStrings::Yard::Parsers::Puppet::FunctionStatement.new(o, @file)
|
69
|
+
statement.extract_docstring(@lines)
|
70
|
+
statement
|
71
|
+
end
|
72
|
+
|
73
|
+
def transform_PlanDefinition(o)
|
74
|
+
statement = OpenvoxStrings::Yard::Parsers::Puppet::PlanStatement.new(o, @file)
|
75
|
+
statement.extract_docstring(@lines)
|
76
|
+
statement
|
77
|
+
end
|
78
|
+
|
79
|
+
def transform_TypeAlias(o)
|
80
|
+
statement = OpenvoxStrings::Yard::Parsers::Puppet::DataTypeAliasStatement.new(o, @file)
|
81
|
+
statement.extract_docstring(@lines)
|
82
|
+
statement
|
83
|
+
end
|
84
|
+
|
85
|
+
def transform_Object(o)
|
86
|
+
# Ignore anything else (will be compacted out of the resulting array)
|
87
|
+
end
|
88
|
+
# rubocop:enable Naming/MethodName
|
89
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'puppet'
|
4
|
+
require 'puppet/pops'
|
5
|
+
|
6
|
+
module OpenvoxStrings::Yard::Parsers::Puppet
|
7
|
+
# Represents the base Puppet language statement.
|
8
|
+
class Statement
|
9
|
+
# The pattern for parsing docstring comments.
|
10
|
+
COMMENT_REGEX = /^\s*#+\s?/
|
11
|
+
|
12
|
+
attr_reader :source, :file, :line, :docstring, :comments_range
|
13
|
+
|
14
|
+
# Initializes the Puppet language statement.
|
15
|
+
# @param object The Puppet parser model object for the statement.
|
16
|
+
# @param [String] file The file name of the file containing the statement.
|
17
|
+
def initialize(object, file)
|
18
|
+
@file = file
|
19
|
+
|
20
|
+
@source = OpenvoxStrings::Yard::Util.ast_to_text(object)
|
21
|
+
@line = object.line
|
22
|
+
@comments_range = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
# Extracts the docstring for the statement given the source lines.
|
26
|
+
# @param [Array<String>] lines The source lines for the file containing the statement.
|
27
|
+
# @return [void]
|
28
|
+
def extract_docstring(lines)
|
29
|
+
comment = []
|
30
|
+
(0..@line - 2).reverse_each do |index|
|
31
|
+
break unless index <= lines.count
|
32
|
+
|
33
|
+
line = lines[index].strip
|
34
|
+
count = line.size
|
35
|
+
line.gsub!(COMMENT_REGEX, '')
|
36
|
+
# Break out if nothing was removed (wasn't a comment line)
|
37
|
+
break unless line.size < count
|
38
|
+
|
39
|
+
comment << line
|
40
|
+
end
|
41
|
+
@comments_range = (@line - comment.size - 1..@line - 1)
|
42
|
+
@docstring = YARD::Docstring.new(comment.reverse.join("\n"))
|
43
|
+
end
|
44
|
+
|
45
|
+
# Shows the first line context for the statement.
|
46
|
+
# @return [String] Returns the first line context for the statement.
|
47
|
+
def show
|
48
|
+
"\t#{@line}: #{first_line}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Gets the full comments of the statement.
|
52
|
+
# @return [String] Returns the full comments of the statement.
|
53
|
+
def comments
|
54
|
+
@docstring.all
|
55
|
+
end
|
56
|
+
|
57
|
+
# Determines if the comments have hash flag.
|
58
|
+
# @return [Boolean] Returns true if the comments have a hash flag or false if not.
|
59
|
+
def comments_hash_flag
|
60
|
+
false
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def first_line
|
66
|
+
@source.split(/\r?\n/).first.strip
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Implements a parameterized statement (a statement that takes parameters).
|
71
|
+
class ParameterizedStatement < Statement
|
72
|
+
# Implements a parameter for a parameterized statement.
|
73
|
+
class Parameter
|
74
|
+
attr_reader :name, :type, :value
|
75
|
+
|
76
|
+
# Initializes the parameter.
|
77
|
+
# @param [Puppet::Pops::Model::Parameter] parameter The parameter model object.
|
78
|
+
def initialize(parameter)
|
79
|
+
@name = parameter.name
|
80
|
+
# Take the exact text for the type expression
|
81
|
+
@type = OpenvoxStrings::Yard::Util.ast_to_text(parameter.type_expr) if parameter.type_expr
|
82
|
+
# Take the exact text for the default value expression
|
83
|
+
return unless parameter.value
|
84
|
+
|
85
|
+
@value = OpenvoxStrings::Yard::Util.ast_to_text(parameter.value)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
attr_reader :parameters
|
90
|
+
|
91
|
+
# Initializes the parameterized statement.
|
92
|
+
# @param object The Puppet parser model object that has parameters.
|
93
|
+
# @param [String] file The file containing the statement.
|
94
|
+
def initialize(object, file)
|
95
|
+
super
|
96
|
+
@parameters = object.parameters.map { |parameter| Parameter.new(parameter) }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Implements the Puppet class statement.
|
101
|
+
class ClassStatement < ParameterizedStatement
|
102
|
+
attr_reader :name, :parent_class
|
103
|
+
|
104
|
+
# Initializes the Puppet class statement.
|
105
|
+
# @param [Puppet::Pops::Model::HostClassDefinition] object The model object for the class statement.
|
106
|
+
# @param [String] file The file containing the statement.
|
107
|
+
def initialize(object, file)
|
108
|
+
super
|
109
|
+
@name = object.name
|
110
|
+
@parent_class = object.parent_class
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Implements the Puppet defined type statement.
|
115
|
+
class DefinedTypeStatement < ParameterizedStatement
|
116
|
+
attr_reader :name
|
117
|
+
|
118
|
+
# Initializes the Puppet defined type statement.
|
119
|
+
# @param [Puppet::Pops::Model::ResourceTypeDefinition] object The model object for the defined type statement.
|
120
|
+
# @param [String] file The file containing the statement.
|
121
|
+
def initialize(object, file)
|
122
|
+
super
|
123
|
+
@name = object.name
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Implements the Puppet function statement.
|
128
|
+
class FunctionStatement < ParameterizedStatement
|
129
|
+
attr_reader :name, :type
|
130
|
+
|
131
|
+
# Initializes the Puppet function statement.
|
132
|
+
# @param [Puppet::Pops::Model::FunctionDefinition] object The model object for the function statement.
|
133
|
+
# @param [String] file The file containing the statement.
|
134
|
+
def initialize(object, file)
|
135
|
+
super
|
136
|
+
@name = object.name
|
137
|
+
return unless object.respond_to? :return_type
|
138
|
+
|
139
|
+
type = object.return_type
|
140
|
+
return unless type
|
141
|
+
|
142
|
+
@type = OpenvoxStrings::Yard::Util.ast_to_text(type).gsub('>> ', '')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Implements the Puppet plan statement.
|
147
|
+
class PlanStatement < ParameterizedStatement
|
148
|
+
attr_reader :name
|
149
|
+
|
150
|
+
# Initializes the Puppet plan statement.
|
151
|
+
# @param [Puppet::Pops::Model::PlanDefinition] object The model object for the plan statement.
|
152
|
+
# @param [String] file The file containing the statement.
|
153
|
+
def initialize(object, file)
|
154
|
+
super
|
155
|
+
@name = object.name
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Implements the Puppet data type alias statement.
|
160
|
+
class DataTypeAliasStatement < Statement
|
161
|
+
attr_reader :name, :alias_of
|
162
|
+
|
163
|
+
# Initializes the Puppet data type alias statement.
|
164
|
+
# @param [Puppet::Pops::Model::TypeAlias] object The model object for the type statement.
|
165
|
+
# @param [String] file The file containing the statement.
|
166
|
+
def initialize(object, file)
|
167
|
+
super
|
168
|
+
|
169
|
+
type_expr = object.type_expr
|
170
|
+
case type_expr
|
171
|
+
when Puppet::Pops::Model::AccessExpression
|
172
|
+
# TODO: I don't like rebuilding the source from the AST, but AccessExpressions don't expose the original source
|
173
|
+
@alias_of = +"#{OpenvoxStrings::Yard::Util.ast_to_text(type_expr.left_expr)}[" # alias_of should be mutable so we add a + to the string.
|
174
|
+
@alias_of << type_expr.keys.map { |key| OpenvoxStrings::Yard::Util.ast_to_text(key) }.join(', ')
|
175
|
+
@alias_of << ']'
|
176
|
+
else
|
177
|
+
@alias_of = OpenvoxStrings::Yard::Util.ast_to_text(type_expr)
|
178
|
+
end
|
179
|
+
@name = object.name
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|