puppet-strings 0.4.0 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +122 -0
  3. data/COMMITTERS.md +185 -0
  4. data/CONTRIBUTING.md +89 -0
  5. data/Gemfile +38 -0
  6. data/JSON.md +511 -0
  7. data/LICENSE +13 -0
  8. data/README.md +416 -0
  9. data/Rakefile +49 -0
  10. data/lib/puppet-strings.rb +63 -0
  11. data/lib/puppet-strings/json.rb +49 -0
  12. data/lib/puppet-strings/tasks.rb +10 -0
  13. data/lib/puppet-strings/tasks/generate.rb +23 -0
  14. data/lib/puppet-strings/tasks/gh_pages.rb +43 -0
  15. data/lib/puppet-strings/yard.rb +96 -0
  16. data/lib/puppet-strings/yard/code_objects.rb +8 -0
  17. data/lib/puppet-strings/yard/code_objects/base.rb +14 -0
  18. data/lib/puppet-strings/yard/code_objects/class.rb +59 -0
  19. data/lib/puppet-strings/yard/code_objects/defined_type.rb +58 -0
  20. data/lib/puppet-strings/yard/code_objects/function.rb +93 -0
  21. data/lib/puppet-strings/yard/code_objects/group.rb +30 -0
  22. data/lib/puppet-strings/yard/code_objects/provider.rb +93 -0
  23. data/lib/puppet-strings/yard/code_objects/type.rb +146 -0
  24. data/lib/puppet-strings/yard/handlers.rb +16 -0
  25. data/lib/puppet-strings/yard/handlers/puppet/base.rb +44 -0
  26. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +23 -0
  27. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +23 -0
  28. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +42 -0
  29. data/lib/puppet-strings/yard/handlers/ruby/base.rb +38 -0
  30. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +357 -0
  31. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +113 -0
  32. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +194 -0
  33. data/lib/puppet-strings/yard/parsers.rb +7 -0
  34. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +70 -0
  35. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +146 -0
  36. data/lib/puppet-strings/yard/tags.rb +6 -0
  37. data/lib/puppet-strings/yard/tags/overload_tag.rb +109 -0
  38. data/lib/puppet-strings/yard/tags/parameter_directive.rb +24 -0
  39. data/lib/puppet-strings/yard/tags/property_directive.rb +24 -0
  40. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb +9 -0
  41. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb +9 -0
  42. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb +10 -0
  43. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +10 -0
  44. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +9 -0
  45. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +64 -0
  46. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +35 -0
  47. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +172 -0
  48. data/lib/puppet-strings/yard/templates/default/puppet_class/html/box_info.erb +26 -0
  49. data/lib/puppet-strings/yard/templates/default/puppet_class/html/header.erb +1 -0
  50. data/lib/puppet-strings/yard/templates/default/puppet_class/html/overview.erb +6 -0
  51. data/lib/puppet-strings/yard/templates/default/puppet_class/html/setup.rb +14 -0
  52. data/lib/puppet-strings/yard/templates/default/puppet_class/html/source.erb +12 -0
  53. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/box_info.erb +10 -0
  54. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/header.erb +1 -0
  55. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/overview.erb +6 -0
  56. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/setup.rb +5 -0
  57. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/source.erb +12 -0
  58. data/lib/puppet-strings/yard/templates/default/puppet_function/html/box_info.erb +14 -0
  59. data/lib/puppet-strings/yard/templates/default/puppet_function/html/header.erb +1 -0
  60. data/lib/puppet-strings/yard/templates/default/puppet_function/html/overview.erb +18 -0
  61. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +5 -0
  62. data/lib/puppet-strings/yard/templates/default/puppet_function/html/source.erb +12 -0
  63. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/box_info.erb +14 -0
  64. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/collection.erb +10 -0
  65. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/features.erb +12 -0
  66. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/header.erb +1 -0
  67. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/overview.erb +6 -0
  68. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/setup.rb +29 -0
  69. data/lib/puppet-strings/yard/templates/default/puppet_type/html/box_info.erb +20 -0
  70. data/lib/puppet-strings/yard/templates/default/puppet_type/html/features.erb +13 -0
  71. data/lib/puppet-strings/yard/templates/default/puppet_type/html/header.erb +1 -0
  72. data/lib/puppet-strings/yard/templates/default/puppet_type/html/overview.erb +6 -0
  73. data/lib/puppet-strings/yard/templates/default/puppet_type/html/parameters.erb +35 -0
  74. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +32 -0
  75. data/lib/puppet-strings/yard/templates/default/tags/html/puppet_overload.erb +12 -0
  76. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +15 -0
  77. data/lib/puppet/application/strings.rb +1 -0
  78. data/lib/puppet/face/strings.rb +80 -39
  79. data/spec/acceptance/emit_json_options.rb +41 -0
  80. data/spec/acceptance/lib/util.rb +15 -0
  81. data/spec/acceptance/running_strings_generate.rb +54 -0
  82. data/spec/fixtures/acceptance/modules/test/functions/add.pp +9 -0
  83. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +5 -0
  84. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +2 -0
  85. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +9 -0
  86. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +15 -0
  87. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +27 -0
  88. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +27 -0
  89. data/spec/fixtures/acceptance/modules/test/metadata.json +6 -0
  90. data/spec/fixtures/unit/json/output.json +348 -0
  91. data/spec/fixtures/unit/json/output_without_puppet_function.json +301 -0
  92. data/spec/spec_helper.rb +21 -0
  93. data/spec/spec_helper_acceptance.rb +27 -0
  94. data/spec/unit/puppet-strings/json_spec.rb +136 -0
  95. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +155 -0
  96. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +155 -0
  97. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +169 -0
  98. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +613 -0
  99. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +90 -0
  100. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +214 -0
  101. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +171 -0
  102. metadata +115 -92
  103. data/lib/puppet-strings/rake_tasks.rb +0 -18
  104. data/lib/puppet_x/puppetlabs/strings.rb +0 -64
  105. data/lib/puppet_x/puppetlabs/strings/actions.rb +0 -92
  106. data/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb +0 -79
  107. data/lib/puppet_x/puppetlabs/strings/pops/yard_transformer.rb +0 -47
  108. data/lib/puppet_x/puppetlabs/strings/util.rb +0 -65
  109. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/defined_type_object.rb +0 -33
  110. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/host_class_object.rb +0 -22
  111. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/method_object.rb +0 -62
  112. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/provider_object.rb +0 -24
  113. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/puppet_namespace_object.rb +0 -48
  114. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/type_object.rb +0 -42
  115. data/lib/puppet_x/puppetlabs/strings/yard/core_ext/yard.rb +0 -40
  116. data/lib/puppet_x/puppetlabs/strings/yard/handlers/base.rb +0 -13
  117. data/lib/puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler.rb +0 -31
  118. data/lib/puppet_x/puppetlabs/strings/yard/handlers/heredoc_helper.rb +0 -80
  119. data/lib/puppet_x/puppetlabs/strings/yard/handlers/host_class_handler.rb +0 -42
  120. data/lib/puppet_x/puppetlabs/strings/yard/handlers/provider_handler.rb +0 -95
  121. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +0 -54
  122. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb +0 -234
  123. data/lib/puppet_x/puppetlabs/strings/yard/handlers/type_handler.rb +0 -295
  124. data/lib/puppet_x/puppetlabs/strings/yard/json_registry_store.rb +0 -85
  125. data/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb +0 -68
  126. data/lib/puppet_x/puppetlabs/strings/yard/parser.rb +0 -30
  127. data/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb +0 -9
  128. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb +0 -34
  129. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/header.erb +0 -5
  130. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb +0 -6
  131. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/setup.rb +0 -1
  132. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/setup.rb +0 -49
  133. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_class.erb +0 -2
  134. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_manifest.erb +0 -1
  135. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb +0 -21
  136. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +0 -1
  137. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +0 -1
  138. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/setup.rb +0 -82
  139. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/box_info.erb +0 -22
  140. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/setup.rb +0 -1
  141. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/subclasses.erb +0 -4
  142. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb +0 -21
  143. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/html_helper.rb +0 -139
  144. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/layout/html/setup.rb +0 -18
  145. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/html/header.erb +0 -17
  146. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/setup.rb +0 -21
  147. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/text/header.erb +0 -2
  148. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/command_details.erb +0 -8
  149. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/confine_details.erb +0 -10
  150. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/default_details.erb +0 -10
  151. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/docstring.erb +0 -34
  152. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/feature_details.erb +0 -10
  153. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/header.erb +0 -5
  154. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/setup.rb +0 -1
  155. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb +0 -50
  156. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/box_info.erb +0 -11
  157. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/header.erb +0 -5
  158. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_details_list.erb +0 -53
  159. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb +0 -20
  160. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/setup.rb +0 -1
  161. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb +0 -91
  162. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb +0 -192
  163. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/docstring.erb +0 -34
  164. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/header.erb +0 -5
  165. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/parameter_details.erb +0 -12
  166. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/provider_details.erb +0 -10
  167. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/setup.rb +0 -1
  168. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/setup.rb +0 -55
@@ -0,0 +1,30 @@
1
+ require 'puppet-strings/yard/code_objects/base'
2
+
3
+ # Implements the base class for "groups".
4
+ #
5
+ # A group behaves like a YARD namespace object, but displays differently in the HTML output.
6
+ class PuppetStrings::Yard::CodeObjects::Group < PuppetStrings::Yard::CodeObjects::Base
7
+ # Gets the singleton instance of the group.
8
+ # @param [Symbol] key The key to lookup the group for.
9
+ # @return Returns the singleton instance of the group.
10
+ def self.instance(key)
11
+ instance = P(:root, key)
12
+ return instance unless instance.is_a?(YARD::CodeObjects::Proxy)
13
+ instance = self.new(:root, key)
14
+ instance.visibility = :hidden
15
+ P(:root).children << instance
16
+ instance
17
+ end
18
+
19
+ # Gets the path to the group.
20
+ # @return [String] Returns the path to the group.
21
+ def path
22
+ @name.to_s
23
+ end
24
+
25
+ # Gets the type of the group.
26
+ # @return [Symbol] Returns the type of the group.
27
+ def type
28
+ @name
29
+ end
30
+ end
@@ -0,0 +1,93 @@
1
+ require 'puppet-strings/yard/code_objects/group'
2
+
3
+ # Implements the group for Puppet providers.
4
+ class PuppetStrings::Yard::CodeObjects::Providers < PuppetStrings::Yard::CodeObjects::Group
5
+ # Gets the singleton instance of the group.
6
+ # @param [String] type The resource type name for the provider.
7
+ # @return Returns the singleton instance of the group.
8
+ def self.instance(type)
9
+ super("puppet_providers_#{type}".intern)
10
+ end
11
+
12
+ # Gets the display name of the group.
13
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
14
+ # @return [String] Returns the display name of the group.
15
+ def name(prefix = false)
16
+ 'Providers'
17
+ end
18
+ end
19
+
20
+ # Implements the Puppet provider code object.
21
+ class PuppetStrings::Yard::CodeObjects::Provider < PuppetStrings::Yard::CodeObjects::Base
22
+ attr_reader :type_name, :confines, :features, :defaults, :commands
23
+
24
+ # Initializes a Puppet provider code object.
25
+ # @param [String] type_name The resource type name for the provider.
26
+ # @param [String] name The name of the provider.s
27
+ # @return [void]
28
+ def initialize(type_name, name)
29
+ @type_name = type_name
30
+ super(PuppetStrings::Yard::CodeObjects::Providers.instance(type_name), name)
31
+ end
32
+
33
+ # Gets the type of the code object.
34
+ # @return Returns the type of the code object.
35
+ def type
36
+ :puppet_provider
37
+ end
38
+
39
+ # Adds a confine to the provider.
40
+ # @param [String] key The confine's key.
41
+ # @param [String] value The confine's value.
42
+ # @return [void]
43
+ def add_confine(key, value)
44
+ return unless key && value
45
+ @confines ||= {}
46
+ @confines[key] = value
47
+ end
48
+
49
+ # Adds a feature to the provider.
50
+ # @param [String] feature The feature to add to the provider.
51
+ # @return [void]
52
+ def add_feature(feature)
53
+ return unless feature
54
+ @features ||= []
55
+ @features << feature
56
+ end
57
+
58
+ # Adds a default to the provider.
59
+ # @param [String] key The default's key.
60
+ # @param [String] value The default's value.
61
+ # @return [void]
62
+ def add_default(key, value)
63
+ return unless key && value
64
+ @defaults ||= {}
65
+ @defaults[key] = value
66
+ end
67
+
68
+ # Adds a command to the provider.
69
+ # @param [String] key The command's key.
70
+ # @param [String] value The command's value.
71
+ # @return [void]
72
+ def add_command(key, value)
73
+ return unless key && value
74
+ @commands ||= {}
75
+ @commands[key] = value
76
+ end
77
+
78
+ # Converts the code object to a hash representation.
79
+ # @return [Hash] Returns a hash representation of the code object.
80
+ def to_hash
81
+ hash = {}
82
+ hash[:name] = name
83
+ hash[:type_name] = type_name
84
+ hash[:file] = file
85
+ hash[:line] = line
86
+ hash[:docstring] = PuppetStrings::Json.docstring_to_hash(docstring)
87
+ hash[:confines] = confines if confines && !confines.empty?
88
+ hash[:features] = features if features && !features.empty?
89
+ hash[:defaults] = defaults if defaults && !defaults.empty?
90
+ hash[:commands] = commands if commands && !commands.empty?
91
+ hash
92
+ end
93
+ end
@@ -0,0 +1,146 @@
1
+ require 'puppet-strings/yard/code_objects/group'
2
+
3
+ # Implements the group for Puppet resource types.
4
+ class PuppetStrings::Yard::CodeObjects::Types < PuppetStrings::Yard::CodeObjects::Group
5
+ # Gets the singleton instance of the group.
6
+ # @return Returns the singleton instance of the group.
7
+ def self.instance
8
+ super(:puppet_types)
9
+ end
10
+
11
+ # Gets the display name of the group.
12
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
13
+ # @return [String] Returns the display name of the group.
14
+ def name(prefix = false)
15
+ 'Resource Types'
16
+ end
17
+ end
18
+
19
+ # Implements the Puppet resource type code object.
20
+ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects::Base
21
+ # Represents a resource type parameter.
22
+ class Parameter
23
+ attr_reader :name, :values, :aliases
24
+ attr_accessor :docstring, :isnamevar, :default
25
+
26
+ # Initializes a resource type parameter or property.
27
+ # @param [String] name The name of the parameter or property.
28
+ # @param [String] docstring The docstring for the parameter or property.s
29
+ def initialize(name, docstring = nil)
30
+ @name = name
31
+ @docstring = docstring || ''
32
+ @values = []
33
+ @aliases = {}
34
+ @isnamevar = false
35
+ @default = nil
36
+ end
37
+
38
+ # Adds a value to the parameter or property.
39
+ # @param [String] value The value to add.
40
+ # @return [void]
41
+ def add(value)
42
+ @values << value
43
+ end
44
+
45
+ # Aliases a value to another value.
46
+ # @param [String] new The new (alias) value.
47
+ # @param [String] old The old (existing) value.
48
+ # @return [void]
49
+ def alias(new, old)
50
+ @values << new unless @values.include? new
51
+ @aliases[new] = old
52
+ end
53
+
54
+ # Converts the parameter to a hash representation.
55
+ # @return [Hash] Returns a hash representation of the parameter.
56
+ def to_hash
57
+ hash = {}
58
+ hash[:name] = name
59
+ hash[:description] = docstring unless docstring.empty?
60
+ hash[:values] = values unless values.empty?
61
+ hash[:aliases] = aliases unless aliases.empty?
62
+ hash[:isnamevar] = true if isnamevar
63
+ hash[:default] = default if default
64
+ hash
65
+ end
66
+ end
67
+
68
+ # Represents a resource type property (same attributes as a parameter).
69
+ class Property < Parameter
70
+ end
71
+
72
+ # Represents a resource type feature.
73
+ class Feature
74
+ attr_reader :name, :docstring
75
+
76
+ # Initializes a new feature.
77
+ # @param [String] name The name of the feature.
78
+ # @param [String] docstring The docstring of the feature.
79
+ def initialize(name, docstring)
80
+ @name = name
81
+ @docstring = docstring
82
+ end
83
+
84
+ # Converts the feature to a hash representation.
85
+ # @return [Hash] Returns a hash representation of the feature.
86
+ def to_hash
87
+ hash = {}
88
+ hash[:name] = name
89
+ hash[:description] = docstring unless docstring.empty?
90
+ hash
91
+ end
92
+ end
93
+
94
+ attr_reader :properties, :parameters, :features
95
+
96
+ # Initializes a new resource type.
97
+ # @param [String] name The resource type name.
98
+ # @return [void]
99
+ def initialize(name)
100
+ super(PuppetStrings::Yard::CodeObjects::Types.instance, name)
101
+ end
102
+
103
+ # Gets the type of the code object.
104
+ # @return Returns the type of the code object.
105
+ def type
106
+ :puppet_type
107
+ end
108
+
109
+ # Adds a parameter to the resource type
110
+ # @param [PuppetStrings::Yard::CodeObjects::Type::Parameter] parameter The parameter to add.
111
+ # @return [void]
112
+ def add_parameter(parameter)
113
+ @parameters ||= []
114
+ @parameters << parameter
115
+ end
116
+
117
+ # Adds a property to the resource type
118
+ # @param [PuppetStrings::Yard::CodeObjects::Type::Property] property The property to add.
119
+ # @return [void]
120
+ def add_property(property)
121
+ @properties ||= []
122
+ @properties << property
123
+ end
124
+
125
+ # Adds a feature to the resource type.
126
+ # @param [PuppetStrings::Yard::CodeObjects::Type::Feature] feature The feature to add.
127
+ # @return [void]
128
+ def add_feature(feature)
129
+ @features ||= []
130
+ @features << feature
131
+ end
132
+
133
+ # Converts the code object to a hash representation.
134
+ # @return [Hash] Returns a hash representation of the code object.
135
+ def to_hash
136
+ hash = {}
137
+ hash[:name] = name
138
+ hash[:file] = file
139
+ hash[:line] = line
140
+ hash[:docstring] = PuppetStrings::Json.docstring_to_hash(docstring)
141
+ hash[:properties] = properties.map(&:to_hash) if properties && !properties.empty?
142
+ hash[:parameters] = parameters.map(&:to_hash) if parameters && !parameters.empty?
143
+ hash[:features] = features.map(&:to_hash) if features && !features.empty?
144
+ hash
145
+ end
146
+ end
@@ -0,0 +1,16 @@
1
+ # The module for custom YARD handlers.
2
+ module PuppetStrings::Yard::Handlers
3
+ # The module for custom Ruby YARD handlers.
4
+ module Ruby
5
+ require 'puppet-strings/yard/handlers/ruby/type_handler'
6
+ require 'puppet-strings/yard/handlers/ruby/provider_handler'
7
+ require 'puppet-strings/yard/handlers/ruby/function_handler'
8
+ end
9
+
10
+ # The module for custom Puppet YARD handlers.
11
+ module Puppet
12
+ require 'puppet-strings/yard/handlers/puppet/class_handler'
13
+ require 'puppet-strings/yard/handlers/puppet/defined_type_handler'
14
+ require 'puppet-strings/yard/handlers/puppet/function_handler'
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ # Implements the base handler for Puppet language handlers.
2
+ class PuppetStrings::Yard::Handlers::Puppet::Base < YARD::Handlers::Base
3
+ # Determine sif the handler handles the given statement.
4
+ # @param statement The statement that was parsed.
5
+ # @return [Boolean] Returns true if the statement is handled by this handler or false if not.
6
+ def self.handles?(statement)
7
+ handlers.any? {|handler| statement.is_a?(handler)}
8
+ end
9
+
10
+ protected
11
+ # Sets the parameter tag types for the given code object.
12
+ # This also performs some validation on the parameter tags.
13
+ # @param object The code object to set the parameter tag types for.
14
+ # @return [void]
15
+ def set_parameter_types(object)
16
+ # Ensure there is an actual parameter for each parameter tag
17
+ tags = object.tags(:param)
18
+ tags.each do |tag|
19
+ next if statement.parameters.find { |p| tag.name == p.name }
20
+ log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{statement.file}:#{statement.line}."
21
+ end
22
+
23
+ # Assign the types for the parameter
24
+ statement.parameters.each do |parameter|
25
+ tag = tags.find { |t| t.name == parameter.name }
26
+ unless tag
27
+ log.warn "Missing @param tag for parameter '#{parameter.name}' near #{statement.file}:#{statement.line}." unless object.docstring.empty?
28
+
29
+ # Add a tag with an empty docstring
30
+ object.add_tag YARD::Tags::Tag.new(:param, '', [parameter.type || 'Any'], parameter.name)
31
+ next
32
+ end
33
+
34
+ # Warn if the parameter is typed and the tag also has a type
35
+ log.warn "The @param tag for parameter '#{parameter.name}' should not contain a type specification near #{statement.file}:#{statement.line}: ignoring in favor of parameter type information." if parameter.type && tag.types && !tag.types.empty?
36
+
37
+ if parameter.type
38
+ tag.types = [parameter.type]
39
+ elsif !tag.types
40
+ tag.types = ['Any']
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ require 'puppet-strings/yard/handlers/puppet/base'
2
+ require 'puppet-strings/yard/parsers'
3
+ require 'puppet-strings/yard/code_objects'
4
+
5
+ # Implements the handler for Puppet classes.
6
+ class PuppetStrings::Yard::Handlers::Puppet::ClassHandler < PuppetStrings::Yard::Handlers::Puppet::Base
7
+ handles PuppetStrings::Yard::Parsers::Puppet::ClassStatement
8
+
9
+ process do
10
+ # Register the object
11
+ object = PuppetStrings::Yard::CodeObjects::Class.new(statement)
12
+ register object
13
+
14
+ # Log a warning if missing documentation
15
+ log.warn "Missing documentation for Puppet class '#{object.name}' at #{statement.file}:#{statement.line}." if object.docstring.empty?
16
+
17
+ # Set the parameter types
18
+ set_parameter_types(object)
19
+
20
+ # Mark the class as public if it doesn't already have an api tag
21
+ object.add_tag YARD::Tags::Tag.new(:api, 'public') unless object.has_tag? :api
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'puppet-strings/yard/handlers/puppet/base'
2
+ require 'puppet-strings/yard/parsers'
3
+ require 'puppet-strings/yard/code_objects'
4
+
5
+ # Implements the handler for Puppet defined types.
6
+ class PuppetStrings::Yard::Handlers::Puppet::DefinedTypeHandler < PuppetStrings::Yard::Handlers::Puppet::Base
7
+ handles PuppetStrings::Yard::Parsers::Puppet::DefinedTypeStatement
8
+
9
+ process do
10
+ # Register the object
11
+ object = PuppetStrings::Yard::CodeObjects::DefinedType.new(statement)
12
+ register object
13
+
14
+ # Log a warning if missing documentation
15
+ log.warn "Missing documentation for Puppet defined type '#{object.name}' at #{statement.file}:#{statement.line}." if object.docstring.empty?
16
+
17
+ # Set the parameter types
18
+ set_parameter_types(object)
19
+
20
+ # Mark the defined type as public if it doesn't already have an api tag
21
+ object.add_tag YARD::Tags::Tag.new(:api, 'public') unless object.has_tag? :api
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ require 'puppet-strings/yard/handlers/puppet/base'
2
+ require 'puppet-strings/yard/parsers'
3
+ require 'puppet-strings/yard/code_objects'
4
+
5
+ # Implements the handler for Puppet classes.
6
+ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Yard::Handlers::Puppet::Base
7
+ handles PuppetStrings::Yard::Parsers::Puppet::FunctionStatement
8
+
9
+ process do
10
+ # Register the object
11
+ object = PuppetStrings::Yard::CodeObjects::Function.new(statement.name, PuppetStrings::Yard::CodeObjects::Function::PUPPET)
12
+ object.source = statement.source
13
+ object.source_type = parser.parser_type
14
+ register object
15
+
16
+ # Log a warning if missing documentation
17
+ log.warn "Missing documentation for Puppet function '#{object.name}' at #{statement.file}:#{statement.line}." if object.docstring.empty?
18
+
19
+ # Set the parameter tag types
20
+ set_parameter_types(object)
21
+
22
+ # Add a return tag
23
+ add_return_tag(object)
24
+
25
+ # Set the parameters on the object
26
+ object.parameters = statement.parameters.map { |p| [p.name, p.value] }
27
+
28
+ # Mark the class as public if it doesn't already have an api tag
29
+ object.add_tag YARD::Tags::Tag.new(:api, 'public') unless object.has_tag? :api
30
+ end
31
+
32
+ private
33
+ def add_return_tag(object)
34
+ tag = object.tag(:return)
35
+ if tag
36
+ tag.types = ['Any'] unless tag.types
37
+ return
38
+ end
39
+ log.warn "Missing @return tag near #{statement.file}:#{statement.line}."
40
+ object.add_tag YARD::Tags::Tag.new(:return, '', 'Any')
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ require 'ripper'
2
+
3
+ # Implements the base handler for Ruby language handlers.
4
+ class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base
5
+ # A regular expression for detecting the start of a Ruby heredoc.
6
+ # Note: the first character of the heredoc start may have been cut off by YARD.
7
+ HEREDOC_START = /^<?<[\-~]?['"]?(\w+)['"]?[^\n]*[\n]?/
8
+
9
+ protected
10
+ # Converts the given Ruby AST node to a string representation.
11
+ # @param node The Ruby AST node to convert.
12
+ # @return [String] Returns a string representation of the node or nil if a string representation was not possible.
13
+ def node_as_string(node)
14
+ return nil unless node
15
+ case node.type
16
+ when :symbol, :symbol_literal
17
+ node.source[1..-1]
18
+ when :label
19
+ node.source[0..-2]
20
+ when :dyna_symbol
21
+ node.source
22
+ when :string_literal
23
+ content = node.jump(:tstring_content)
24
+ return content.source if content != node
25
+
26
+ # This attempts to work around a bug in YARD (https://github.com/lsegal/yard/issues/779)
27
+ # Check to see if the string source appears to have a heredoc open tag (or "most" of one)
28
+ # If so, remove the first line and the last line (if the latter contains the heredoc tag)
29
+ source = node.source
30
+ if source =~ HEREDOC_START
31
+ lines = source.split("\n")
32
+ source = lines[1..(lines.last.include?($1) ? -2 : -1)].join("\n") if lines.size > 1
33
+ end
34
+
35
+ source
36
+ end
37
+ end
38
+ end