puppet 3.0.2 → 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (320) hide show
  1. data/Gemfile +13 -11
  2. data/README.md +9 -7
  3. data/README_DEVELOPER.md +21 -30
  4. data/bin/extlookup2hiera +0 -0
  5. data/conf/auth.conf +42 -26
  6. data/conf/fileserver.conf +41 -0
  7. data/conf/tagmail.conf +16 -0
  8. data/examples/hiera/modules/data/manifests/common.pp +2 -1
  9. data/examples/hiera/modules/ntp/manifests/config.pp +4 -3
  10. data/examples/hiera/modules/ntp/manifests/data.pp +2 -1
  11. data/examples/hiera/modules/users/manifests/common.pp +2 -1
  12. data/examples/hiera/modules/users/manifests/dc1.pp +2 -1
  13. data/examples/hiera/modules/users/manifests/development.pp +2 -1
  14. data/examples/hiera/site.pp +1 -1
  15. data/ext/debian/fileserver.conf +39 -15
  16. data/ext/envpuppet +2 -0
  17. data/ext/gentoo/puppet/fileserver.conf +41 -12
  18. data/ext/ips/puppet-agent +1 -6
  19. data/ext/ips/puppetagent.xml +0 -4
  20. data/ext/osx/postflight.erb +109 -0
  21. data/ext/project_data.yaml +2 -2
  22. data/ext/redhat/fileserver.conf +41 -12
  23. data/ext/redhat/puppet.spec.erb +8 -13
  24. data/install.rb +2 -5
  25. data/lib/puppet.rb +30 -13
  26. data/lib/puppet/application.rb +34 -16
  27. data/lib/puppet/application/agent.rb +4 -4
  28. data/lib/puppet/application/master.rb +25 -5
  29. data/lib/puppet/defaults.rb +11 -7
  30. data/lib/puppet/dsl.rb +7 -3
  31. data/lib/puppet/dsl/actions.rb +283 -0
  32. data/lib/puppet/dsl/blank_slate.rb +55 -0
  33. data/lib/puppet/dsl/context.rb +393 -0
  34. data/lib/puppet/dsl/parser.rb +57 -0
  35. data/lib/puppet/dsl/resource_decorator.rb +56 -0
  36. data/lib/puppet/dsl/resource_reference.rb +95 -0
  37. data/lib/puppet/dsl/type_reference.rb +102 -0
  38. data/lib/puppet/error.rb +1 -1
  39. data/lib/puppet/face/help.rb +2 -4
  40. data/lib/puppet/face/man.rb +8 -2
  41. data/lib/puppet/feature/pson.rb +1 -3
  42. data/lib/puppet/indirector/catalog/active_record.rb +3 -0
  43. data/lib/puppet/indirector/catalog/compiler.rb +1 -2
  44. data/lib/puppet/indirector/catalog/queue.rb +4 -0
  45. data/lib/puppet/indirector/catalog/static_compiler.rb +30 -0
  46. data/lib/puppet/indirector/catalog/store_configs.rb +3 -0
  47. data/lib/puppet/indirector/certificate_request/rest.rb +1 -0
  48. data/lib/puppet/indirector/certificate_revocation_list/rest.rb +1 -0
  49. data/lib/puppet/indirector/certificate_status/file.rb +4 -0
  50. data/lib/puppet/indirector/certificate_status/rest.rb +1 -0
  51. data/lib/puppet/indirector/facts/active_record.rb +3 -0
  52. data/lib/puppet/indirector/facts/couch.rb +3 -0
  53. data/lib/puppet/indirector/facts/inventory_active_record.rb +4 -0
  54. data/lib/puppet/indirector/facts/store_configs.rb +3 -0
  55. data/lib/puppet/indirector/file_metadata/rest.rb +2 -0
  56. data/lib/puppet/indirector/instrumentation_data/local.rb +3 -0
  57. data/lib/puppet/indirector/instrumentation_data/rest.rb +3 -0
  58. data/lib/puppet/indirector/instrumentation_listener/local.rb +3 -0
  59. data/lib/puppet/indirector/instrumentation_listener/rest.rb +3 -0
  60. data/lib/puppet/indirector/instrumentation_probe/local.rb +3 -0
  61. data/lib/puppet/indirector/instrumentation_probe/rest.rb +3 -0
  62. data/lib/puppet/indirector/node/active_record.rb +3 -0
  63. data/lib/puppet/indirector/node/rest.rb +2 -2
  64. data/lib/puppet/indirector/node/store_configs.rb +3 -0
  65. data/lib/puppet/indirector/node/write_only_yaml.rb +32 -0
  66. data/lib/puppet/indirector/queue.rb +0 -1
  67. data/lib/puppet/indirector/request.rb +1 -2
  68. data/lib/puppet/indirector/resource/active_record.rb +4 -0
  69. data/lib/puppet/indirector/resource/ral.rb +3 -0
  70. data/lib/puppet/indirector/resource/rest.rb +3 -0
  71. data/lib/puppet/indirector/resource/store_configs.rb +3 -0
  72. data/lib/puppet/indirector/run/local.rb +3 -0
  73. data/lib/puppet/indirector/ssl_file.rb +16 -14
  74. data/lib/puppet/indirector/status/local.rb +3 -0
  75. data/lib/puppet/indirector/status/rest.rb +4 -0
  76. data/lib/puppet/interface.rb +78 -3
  77. data/lib/puppet/interface/action.rb +39 -3
  78. data/lib/puppet/interface/action_builder.rb +74 -1
  79. data/lib/puppet/interface/action_manager.rb +33 -3
  80. data/lib/puppet/interface/documentation.rb +116 -5
  81. data/lib/puppet/interface/face_collection.rb +6 -7
  82. data/lib/puppet/interface/option.rb +10 -1
  83. data/lib/puppet/interface/option_builder.rb +29 -1
  84. data/lib/puppet/interface/option_manager.rb +21 -6
  85. data/lib/puppet/metatype/manager.rb +47 -9
  86. data/lib/puppet/module_tool.rb +0 -1
  87. data/lib/puppet/network/formats.rb +0 -2
  88. data/lib/puppet/node.rb +2 -3
  89. data/lib/puppet/node/environment.rb +14 -1
  90. data/lib/puppet/parameter.rb +309 -44
  91. data/lib/puppet/parameter/package_options.rb +5 -0
  92. data/lib/puppet/parameter/path.rb +26 -3
  93. data/lib/puppet/parameter/value.rb +30 -6
  94. data/lib/puppet/parameter/value_collection.rb +82 -20
  95. data/lib/puppet/parser.rb +3 -0
  96. data/lib/puppet/parser/ast/definition.rb +2 -5
  97. data/lib/puppet/parser/ast/hostclass.rb +2 -3
  98. data/lib/puppet/parser/ast/node.rb +2 -5
  99. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  100. data/lib/puppet/parser/compiler.rb +10 -0
  101. data/lib/puppet/parser/functions.rb +111 -7
  102. data/lib/puppet/parser/functions/create_resources.rb +23 -2
  103. data/lib/puppet/parser/functions/defined.rb +1 -1
  104. data/lib/puppet/parser/functions/extlookup.rb +2 -1
  105. data/lib/puppet/parser/functions/fail.rb +1 -1
  106. data/lib/puppet/parser/functions/file.rb +1 -1
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
  108. data/lib/puppet/parser/functions/generate.rb +1 -1
  109. data/lib/puppet/parser/functions/hiera.rb +1 -1
  110. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  111. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  112. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  113. data/lib/puppet/parser/functions/include.rb +1 -1
  114. data/lib/puppet/parser/functions/inline_template.rb +1 -1
  115. data/lib/puppet/parser/functions/md5.rb +1 -1
  116. data/lib/puppet/parser/functions/realize.rb +1 -1
  117. data/lib/puppet/parser/functions/regsubst.rb +54 -57
  118. data/lib/puppet/parser/functions/require.rb +1 -0
  119. data/lib/puppet/parser/functions/search.rb +1 -1
  120. data/lib/puppet/parser/functions/sha1.rb +1 -1
  121. data/lib/puppet/parser/functions/shellquote.rb +1 -1
  122. data/lib/puppet/parser/functions/split.rb +1 -2
  123. data/lib/puppet/parser/functions/sprintf.rb +7 -10
  124. data/lib/puppet/parser/functions/tag.rb +1 -1
  125. data/lib/puppet/parser/functions/tagged.rb +1 -1
  126. data/lib/puppet/parser/functions/template.rb +1 -1
  127. data/lib/puppet/parser/functions/versioncmp.rb +1 -5
  128. data/lib/puppet/parser/parser_support.rb +11 -27
  129. data/lib/puppet/parser/scope.rb +48 -4
  130. data/lib/puppet/parser/type_loader.rb +31 -7
  131. data/lib/puppet/property.rb +304 -70
  132. data/lib/puppet/property/ensure.rb +14 -1
  133. data/lib/puppet/property/keyvalue.rb +17 -8
  134. data/lib/puppet/property/list.rb +3 -0
  135. data/lib/puppet/property/ordered_list.rb +7 -0
  136. data/lib/puppet/provider.rb +275 -53
  137. data/lib/puppet/provider/augeas/augeas.rb +17 -3
  138. data/lib/puppet/provider/confiner.rb +30 -1
  139. data/lib/puppet/provider/group/pw.rb +2 -2
  140. data/lib/puppet/provider/package/pip.rb +0 -1
  141. data/lib/puppet/provider/package/pkgin.rb +2 -0
  142. data/lib/puppet/provider/service/bsd.rb +1 -1
  143. data/lib/puppet/provider/service/freebsd.rb +10 -6
  144. data/lib/puppet/provider/service/init.rb +1 -1
  145. data/lib/puppet/provider/service/service.rb +1 -1
  146. data/lib/puppet/provider/user/pw.rb +2 -2
  147. data/lib/puppet/provider/user/useradd.rb +2 -3
  148. data/lib/puppet/reference/configuration.rb +6 -0
  149. data/lib/puppet/reports.rb +44 -4
  150. data/lib/puppet/reports/tagmail.rb +1 -1
  151. data/lib/puppet/resource.rb +38 -25
  152. data/lib/puppet/resource/type.rb +14 -6
  153. data/lib/puppet/settings.rb +66 -142
  154. data/lib/puppet/settings/config_file.rb +99 -0
  155. data/lib/puppet/settings/file_setting.rb +92 -24
  156. data/lib/puppet/settings/value_translator.rb +15 -0
  157. data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
  158. data/lib/puppet/test/test_helper.rb +8 -3
  159. data/lib/puppet/transaction.rb +1 -2
  160. data/lib/puppet/transaction/report.rb +122 -13
  161. data/lib/puppet/type.rb +763 -150
  162. data/lib/puppet/type/augeas.rb +4 -0
  163. data/lib/puppet/type/file/ensure.rb +1 -1
  164. data/lib/puppet/type/file/group.rb +1 -1
  165. data/lib/puppet/type/file/mode.rb +2 -0
  166. data/lib/puppet/type/file/selcontext.rb +1 -0
  167. data/lib/puppet/type/group.rb +12 -0
  168. data/lib/puppet/type/mount.rb +2 -2
  169. data/lib/puppet/type/notify.rb +1 -1
  170. data/lib/puppet/type/router.rb +1 -1
  171. data/lib/puppet/type/service.rb +1 -0
  172. data/lib/puppet/type/ssh_authorized_key.rb +3 -1
  173. data/lib/puppet/type/user.rb +8 -1
  174. data/lib/puppet/util.rb +8 -0
  175. data/lib/puppet/util/autoload.rb +7 -10
  176. data/lib/puppet/util/classgen.rb +58 -33
  177. data/lib/puppet/util/command_line.rb +120 -77
  178. data/lib/puppet/util/constant_inflector.rb +2 -0
  179. data/lib/puppet/util/execution.rb +63 -33
  180. data/lib/puppet/util/filetype.rb +1 -1
  181. data/lib/puppet/util/manifest_filetype_helper.rb +22 -0
  182. data/lib/puppet/util/methodhelper.rb +19 -0
  183. data/lib/puppet/util/monkey_patches.rb +46 -0
  184. data/lib/puppet/util/plugins.rb +2 -2
  185. data/lib/puppet/util/provider_features.rb +24 -8
  186. data/lib/puppet/util/rubygems.rb +8 -1
  187. data/lib/puppet/util/zaml.rb +1 -1
  188. data/lib/puppet/version.rb +74 -3
  189. data/spec/integration/application/apply_spec.rb +1 -1
  190. data/spec/integration/defaults_spec.rb +1 -0
  191. data/spec/integration/dsl/classes_spec.rb +191 -0
  192. data/spec/integration/dsl/defaults_spec.rb +38 -0
  193. data/spec/integration/dsl/definitions_spec.rb +73 -0
  194. data/spec/integration/dsl/functions_spec.rb +95 -0
  195. data/spec/integration/dsl/nodes_spec.rb +96 -0
  196. data/spec/integration/dsl/params_spec.rb +146 -0
  197. data/spec/integration/dsl/relationships_spec.rb +46 -0
  198. data/spec/integration/dsl/resources_spec.rb +202 -0
  199. data/spec/integration/dsl/type_loading_spec.rb +64 -0
  200. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  201. data/spec/integration/network/formats_spec.rb +32 -45
  202. data/spec/integration/parser/collector_spec.rb +105 -25
  203. data/spec/integration/parser/scope_spec.rb +64 -1
  204. data/spec/integration/resource/catalog_spec.rb +2 -4
  205. data/spec/integration/type/package_spec.rb +1 -1
  206. data/spec/lib/matchers/catalog.rb +50 -0
  207. data/spec/lib/puppet_spec/compiler.rb +11 -0
  208. data/spec/lib/puppet_spec/dsl.rb +29 -0
  209. data/spec/spec_helper.rb +17 -3
  210. data/spec/unit/application/agent_spec.rb +0 -1
  211. data/spec/unit/application/apply_spec.rb +1 -1
  212. data/spec/unit/application/face_base_spec.rb +11 -4
  213. data/spec/unit/application/indirection_base_spec.rb +4 -8
  214. data/spec/unit/application/kick_spec.rb +5 -2
  215. data/spec/unit/application/master_spec.rb +0 -6
  216. data/spec/unit/application_spec.rb +38 -14
  217. data/spec/unit/dsl/actions_spec.rb +402 -0
  218. data/spec/unit/dsl/blank_slate_spec.rb +27 -0
  219. data/spec/unit/dsl/context_spec.rb +678 -0
  220. data/spec/unit/dsl/parser_spec.rb +56 -0
  221. data/spec/unit/dsl/resource_decorator_spec.rb +94 -0
  222. data/spec/unit/dsl/resource_reference_spec.rb +150 -0
  223. data/spec/unit/dsl/type_reference_spec.rb +164 -0
  224. data/spec/unit/face/help_spec.rb +5 -7
  225. data/spec/unit/indirector/certificate_request/rest_spec.rb +4 -0
  226. data/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +4 -0
  227. data/spec/unit/indirector/certificate_status/rest_spec.rb +4 -0
  228. data/spec/unit/indirector/file_metadata/rest_spec.rb +5 -0
  229. data/spec/unit/indirector/hiera_spec.rb +3 -1
  230. data/spec/unit/indirector/queue_spec.rb +1 -7
  231. data/spec/unit/indirector/ssl_file_spec.rb +66 -39
  232. data/spec/unit/module_spec.rb +1 -1
  233. data/spec/unit/network/authstore_spec.rb +22 -1
  234. data/spec/unit/network/formats_spec.rb +1 -1
  235. data/spec/unit/node/environment_spec.rb +13 -0
  236. data/spec/unit/parser/collector_spec.rb +1 -1
  237. data/spec/unit/parser/compiler_spec.rb +26 -0
  238. data/spec/unit/parser/functions/create_resources_spec.rb +12 -1
  239. data/spec/unit/parser/functions/extlookup_spec.rb +4 -4
  240. data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
  241. data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
  242. data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
  243. data/spec/unit/parser/functions/hiera_spec.rb +1 -1
  244. data/spec/unit/parser/functions/regsubst_spec.rb +4 -4
  245. data/spec/unit/parser/functions/split_spec.rb +4 -4
  246. data/spec/unit/parser/functions/sprintf_spec.rb +2 -2
  247. data/spec/unit/parser/functions/versioncmp_spec.rb +4 -4
  248. data/spec/unit/parser/functions_spec.rb +51 -1
  249. data/spec/unit/parser/parser_spec.rb +0 -14
  250. data/spec/unit/parser/type_loader_spec.rb +15 -1
  251. data/spec/unit/provider/augeas/augeas_spec.rb +31 -0
  252. data/spec/unit/provider/package/apt_spec.rb +0 -2
  253. data/spec/unit/provider/package/pip_spec.rb +12 -2
  254. data/spec/unit/provider/service/freebsd_spec.rb +8 -0
  255. data/spec/unit/provider/service/gentoo_spec.rb +20 -20
  256. data/spec/unit/provider/service/openrc_spec.rb +20 -20
  257. data/spec/unit/provider/service/src_spec.rb +4 -4
  258. data/spec/unit/provider/service/systemd_spec.rb +0 -8
  259. data/spec/unit/provider/service/windows_spec.rb +1 -1
  260. data/spec/unit/provider/user/useradd_spec.rb +2 -9
  261. data/spec/unit/relationship_spec.rb +2 -2
  262. data/spec/unit/resource/catalog_spec.rb +2 -2
  263. data/spec/unit/resource/type_spec.rb +49 -25
  264. data/spec/unit/resource_spec.rb +34 -2
  265. data/spec/unit/settings/config_file_spec.rb +100 -0
  266. data/spec/unit/settings/file_setting_spec.rb +87 -84
  267. data/spec/unit/settings/value_translator_spec.rb +77 -0
  268. data/spec/unit/settings_spec.rb +96 -29
  269. data/spec/unit/type/file/ensure_spec.rb +75 -36
  270. data/spec/unit/type/file_spec.rb +0 -68
  271. data/spec/unit/type/group_spec.rb +10 -0
  272. data/spec/unit/util/autoload_spec.rb +6 -0
  273. data/spec/unit/util/command_line_spec.rb +54 -62
  274. data/spec/unit/util/manifest_filetype_helper_spec.rb +29 -0
  275. data/spec/unit/util/metric_spec.rb +0 -9
  276. data/spec/unit/util/posix_spec.rb +0 -4
  277. data/spec/unit/util/rdoc_spec.rb +0 -12
  278. data/spec/unit/util/zaml_spec.rb +188 -130
  279. data/spec/unit/version_spec.rb +42 -0
  280. metadata +123 -90
  281. data/README_HIERA.md +0 -148
  282. data/conf/epm.list +0 -8
  283. data/conf/namespaceauth.conf +0 -20
  284. data/conf/puppet-queue.conf +0 -10
  285. data/examples/allatonce +0 -13
  286. data/examples/assignments +0 -11
  287. data/examples/components +0 -73
  288. data/examples/etc/init.d/sleeper +0 -70
  289. data/examples/etc/otherfile +0 -0
  290. data/examples/etc/puppet/fileserver.conf +0 -13
  291. data/examples/etc/puppet/namespaceauth.conf +0 -20
  292. data/examples/etc/puppet/puppet.conf +0 -10
  293. data/examples/etc/puppet/tagmail.conf +0 -1
  294. data/examples/execs +0 -16
  295. data/examples/file.bl +0 -11
  296. data/examples/filedefaults +0 -10
  297. data/examples/fileparsing +0 -116
  298. data/examples/filerecursion +0 -15
  299. data/examples/functions +0 -3
  300. data/examples/groups +0 -7
  301. data/examples/head +0 -30
  302. data/examples/importing +0 -8
  303. data/examples/mac_dscl.pp +0 -28
  304. data/examples/mac_dscl_revert.pp +0 -26
  305. data/examples/mac_pkgdmg.pp +0 -7
  306. data/examples/modules/sample_module.pp +0 -10
  307. data/examples/modules/sample_module/lib/puppet/parser/functions/hostname_to_dn.rb +0 -36
  308. data/examples/modules/sample_module/manifests/init.pp +0 -12
  309. data/examples/modules/sample_module/templates/sample.erb +0 -5
  310. data/examples/nodes +0 -20
  311. data/examples/one +0 -8
  312. data/examples/relationships +0 -34
  313. data/examples/selectors +0 -28
  314. data/examples/simpletests +0 -11
  315. data/examples/svncommit +0 -13
  316. data/lib/puppet/dsl/resource_api.rb +0 -120
  317. data/lib/puppet/dsl/resource_type_api.rb +0 -34
  318. data/spec/integration/parser/ruby_manifest_spec.rb +0 -127
  319. data/spec/unit/dsl/resource_api_spec.rb +0 -180
  320. data/spec/unit/dsl/resource_type_api_spec.rb +0 -53
@@ -3,14 +3,13 @@ require 'puppet/interface'
3
3
  module Puppet::Interface::FaceCollection
4
4
  @faces = Hash.new { |hash, key| hash[key] = {} }
5
5
 
6
+ @loader = Puppet::Util::Autoload.new(:application, 'puppet/face')
7
+
6
8
  def self.faces
7
9
  unless @loaded
8
10
  @loaded = true
9
- $LOAD_PATH.each do |dir|
10
- Dir.glob("#{dir}/puppet/face/*.rb").
11
- collect {|f| File.basename(f, '.rb') }.
12
- each {|name| self[name, :current] }
13
- end
11
+ names = @loader.files_to_load.map {|fn| ::File.basename(fn, '.rb')}.uniq
12
+ names.each {|name| self[name, :current]}
14
13
  end
15
14
  @faces.keys.select {|name| @faces[name].length > 0 }
16
15
  end
@@ -58,7 +57,7 @@ module Puppet::Interface::FaceCollection
58
57
  # other Ruby library that we might want to use. --daniel 2011-04-06
59
58
  if safely_require name then
60
59
  # If we wanted :current, we need to index to find that; direct version
61
- # requests just work as they go. --daniel 2011-04-06
60
+ # requests just work as they go. --daniel 2011-04-06
62
61
  if version == :current then
63
62
  # We need to find current out of this. This is the largest version
64
63
  # number that doesn't have a dedicated on-disk file present; those
@@ -99,7 +98,7 @@ module Puppet::Interface::FaceCollection
99
98
  end
100
99
 
101
100
  def self.safely_require(name, version = nil)
102
- path = File.join 'puppet' ,'face', version.to_s, name.to_s
101
+ path = @loader.expand(version ? ::File.join(version.to_s, name.to_s) : name)
103
102
  require path
104
103
  true
105
104
 
@@ -1,8 +1,15 @@
1
1
  require 'puppet/interface'
2
2
 
3
+ # This represents an option on an action or face (to be globally applied
4
+ # to its actions). Options should be constructed by calling
5
+ # {Puppet::Interface::OptionManager#option}, which is available on
6
+ # {Puppet::Interface}, and then calling methods of
7
+ # {Puppet::Interface::OptionBuilder} in the supplied block.
8
+ # @api public
3
9
  class Puppet::Interface::Option
4
10
  include Puppet::Interface::TinyDocs
5
11
 
12
+ # @api private
6
13
  def initialize(parent, *declaration, &block)
7
14
  @parent = parent
8
15
  @optparse = []
@@ -69,18 +76,20 @@ class Puppet::Interface::Option
69
76
  # to_s and optparse_to_name are roughly mirrored, because they are used to
70
77
  # transform options to name symbols, and vice-versa. This isn't a full
71
78
  # bidirectional transformation though. --daniel 2011-04-07
79
+
72
80
  def to_s
73
81
  @name.to_s.tr('_', '-')
74
82
  end
75
83
 
84
+ # @api private
76
85
  def optparse_to_optionname(declaration)
77
86
  unless found = declaration.match(/^-+(?:\[no-\])?([^ =]+)/) then
78
87
  raise ArgumentError, "Can't find a name in the declaration #{declaration.inspect}"
79
88
  end
80
89
  name = found.captures.first
81
90
  end
82
-
83
91
 
92
+ # @api private
84
93
  def optparse_to_name(declaration)
85
94
  name = optparse_to_optionname(declaration).tr('-', '_')
86
95
  raise "#{name.inspect} is an invalid option name" unless name.to_s =~ /^[a-z]\w*$/
@@ -1,13 +1,19 @@
1
1
  require 'puppet/interface/option'
2
2
 
3
+ # @api public
3
4
  class Puppet::Interface::OptionBuilder
5
+ # The option under construction
6
+ # @return [Puppet::Interface::Option]
7
+ # @api private
4
8
  attr_reader :option
5
9
 
10
+ # Build an option
11
+ # @return [Puppet::Interface::Option]
12
+ # @api private
6
13
  def self.build(face, *declaration, &block)
7
14
  new(face, *declaration, &block).option
8
15
  end
9
16
 
10
- private
11
17
  def initialize(face, *declaration, &block)
12
18
  @face = face
13
19
  @option = Puppet::Interface::Option.new(face, *declaration)
@@ -26,6 +32,15 @@ class Puppet::Interface::OptionBuilder
26
32
  end
27
33
 
28
34
  # Override some methods that deal in blocks, not objects.
35
+
36
+ # Sets a block to be executed when an action is invoked before the
37
+ # main action code. This is most commonly used to validate an option.
38
+ # @yieldparam action [Puppet::Interface::Action] The action being
39
+ # invoked
40
+ # @yieldparam args [Array] The arguments given to the action
41
+ # @yieldparam options [Hash<Symbol=>Object>] Any options set
42
+ # @api public
43
+ # @dsl Faces
29
44
  def before_action(&block)
30
45
  block or raise ArgumentError, "#{@option} before_action requires a block"
31
46
  if @option.before_action
@@ -37,6 +52,10 @@ class Puppet::Interface::OptionBuilder
37
52
  @option.before_action = block
38
53
  end
39
54
 
55
+ # Sets a block to be executed after an action is invoked.
56
+ # !(see before_action)
57
+ # @api public
58
+ # @dsl Faces
40
59
  def after_action(&block)
41
60
  block or raise ArgumentError, "#{@option} after_action requires a block"
42
61
  if @option.after_action
@@ -48,10 +67,19 @@ class Puppet::Interface::OptionBuilder
48
67
  @option.after_action = block
49
68
  end
50
69
 
70
+ # Sets whether the option is required. If no argument is given it
71
+ # defaults to setting it as a required option.
72
+ # @api public
73
+ # @dsl Faces
51
74
  def required(value = true)
52
75
  @option.required = value
53
76
  end
54
77
 
78
+ # Sets a block that will be used to compute the default value for this
79
+ # option. It will be evaluated when the action is invoked. The block
80
+ # should take no arguments.
81
+ # @api public
82
+ # @dsl Faces
55
83
  def default_to(&block)
56
84
  block or raise ArgumentError, "#{@option} default_to requires a block"
57
85
  if @option.has_default?
@@ -1,7 +1,13 @@
1
1
  require 'puppet/interface/option_builder'
2
2
 
3
+ # This class is not actually public API, but the method
4
+ # {Puppet::Interface::OptionManager#option option} is public when used
5
+ # as part of the Faces DSL (i.e. from within a
6
+ # {Puppet::Interface.define define} block).
7
+ # @api public
3
8
  module Puppet::Interface::OptionManager
4
-
9
+
10
+ # @api private
5
11
  def display_global_options(*args)
6
12
  @display_global_options ||= []
7
13
  [args].flatten.each do |refopt|
@@ -12,11 +18,12 @@ module Puppet::Interface::OptionManager
12
18
  @display_global_options
13
19
  end
14
20
  alias :display_global_option :display_global_options
15
-
21
+
16
22
  def all_display_global_options
17
23
  walk_inheritance_tree(@display_global_options, :all_display_global_options)
18
24
  end
19
-
25
+
26
+ # @api private
20
27
  def walk_inheritance_tree(start, sym)
21
28
  result = (start ||= [])
22
29
  if self.is_a?(Class) and superclass.respond_to?(sym)
@@ -26,13 +33,18 @@ module Puppet::Interface::OptionManager
26
33
  end
27
34
  return result
28
35
  end
29
-
30
- # Declare that this app can take a specific option, and provide
31
- # the code to do so.
36
+
37
+ # Declare that this app can take a specific option, and provide the
38
+ # code to do so. See {Puppet::Interface::ActionBuilder#option} for
39
+ # details.
40
+ #
41
+ # @api public
42
+ # @dsl Faces
32
43
  def option(*declaration, &block)
33
44
  add_option Puppet::Interface::OptionBuilder.build(self, *declaration, &block)
34
45
  end
35
46
 
47
+ # @api private
36
48
  def add_option(option)
37
49
  # @options collects the added options in the order they're declared.
38
50
  # @options_hash collects the options keyed by alias for quick lookups.
@@ -61,10 +73,12 @@ module Puppet::Interface::OptionManager
61
73
  return option
62
74
  end
63
75
 
76
+ # @api private
64
77
  def options
65
78
  walk_inheritance_tree(@options, :options)
66
79
  end
67
80
 
81
+ # @api private
68
82
  def get_option(name, with_inherited_options = true)
69
83
  @options_hash ||= {}
70
84
 
@@ -80,6 +94,7 @@ module Puppet::Interface::OptionManager
80
94
  return result
81
95
  end
82
96
 
97
+ # @api private
83
98
  def option?(name)
84
99
  options.include? name.to_sym
85
100
  end
@@ -2,20 +2,29 @@ require 'puppet'
2
2
  require 'puppet/util/classgen'
3
3
  require 'puppet/node/environment'
4
4
 
5
- # Methods dealing with Type management. This module gets included into the
6
- # Puppet::Type class, it's just split out here for clarity.
5
+ # This module defines methods dealing with Type management.
6
+ # This module gets included into the Puppet::Type class, it's just split out here for clarity.
7
+ # @api public
8
+ #
7
9
  module Puppet::MetaType
8
10
  module Manager
9
11
  include Puppet::Util::ClassGen
10
12
 
11
- # remove all type instances; this is mostly only useful for testing
13
+ # An implementation specific method that removes all type instances during testing.
14
+ # @note Only use this method for testing purposes.
15
+ # @api private
16
+ #
12
17
  def allclear
13
18
  @types.each { |name, type|
14
19
  type.clear
15
20
  }
16
21
  end
17
22
 
18
- # iterate across all of the subclasses of Type
23
+ # Iterates over all already loaded Type subclasses.
24
+ # @yield [t] a block receiving each type
25
+ # @yieldparam t [Puppet::Type] each defined type
26
+ # @yieldreturn [Object] the last returned object is also returned from this method
27
+ # @return [Object] the last returned value from the block.
19
28
  def eachtype
20
29
  @types.each do |name, type|
21
30
  # Only consider types that have names
@@ -25,12 +34,32 @@ module Manager
25
34
  end
26
35
  end
27
36
 
28
- # Load all types. Only currently used for documentation.
37
+ # Loads all types.
38
+ # @note Should only be used for purposes such as generating documentation as this is potentially a very
39
+ # expensive operation.
40
+ # @return [void]
41
+ #
29
42
  def loadall
30
43
  typeloader.loadall
31
44
  end
32
45
 
33
- # Define a new type.
46
+ # Defines a new type or redefines an existing type with the given name.
47
+ # A convenience method on the form `new<name>` where name is the name of the type is also created.
48
+ # (If this generated method happens to clash with an existing method, a warning is issued and the original
49
+ # method is kept).
50
+ #
51
+ # @param name [String] the name of the type to create or redefine.
52
+ # @param options [Hash] options passed on to {Puppet::Util::ClassGen#genclass} as the option `:attributes` after
53
+ # first having removed any present `:parent` option.
54
+ # @option options [Puppet::Type] :parent the parent (super type) of this type. If nil, the default is
55
+ # Puppet::Type. This option is not passed on as an attribute to genclass.
56
+ # @yield [ ] a block evaluated in the context of the created class, thus allowing further detailing of
57
+ # that class.
58
+ # @return [Class<inherits Puppet::Type>] the created subclass
59
+ # @see Puppet::Util::ClassGen.genclass
60
+ #
61
+ # @dsl type
62
+ # @api public
34
63
  def newtype(name, options = {}, &block)
35
64
  # Handle backward compatibility
36
65
  unless options.is_a?(Hash)
@@ -96,7 +125,9 @@ module Manager
96
125
  klass
97
126
  end
98
127
 
99
- # Remove an existing defined type. Largely used for testing.
128
+ # Removes an existing type.
129
+ # @note Only use this for testing.
130
+ # @api private
100
131
  def rmtype(name)
101
132
  # Then create the class.
102
133
 
@@ -105,7 +136,11 @@ module Manager
105
136
  singleton_class.send(:remove_method, "new#{name}") if respond_to?("new#{name}")
106
137
  end
107
138
 
108
- # Return a Type instance by name.
139
+ # Returns a Type instance by name.
140
+ # This will load the type if not already defined.
141
+ # @param [String, Symbol] name of the wanted Type
142
+ # @return [Puppet::Type, nil] the type or nil if the type was not defined and could not be loaded
143
+ #
109
144
  def type(name)
110
145
  @types ||= {}
111
146
 
@@ -129,7 +164,10 @@ module Manager
129
164
  return @types[name]
130
165
  end
131
166
 
132
- # Create a loader for Puppet types.
167
+ # Creates a loader for Puppet types.
168
+ # Defaults to an instance of {Puppet::Util::Autoload} if no other auto loader has been set.
169
+ # @return [Puppet::Util::Autoload] the loader to use.
170
+ # @api private
133
171
  def typeloader
134
172
  unless defined?(@typeloader)
135
173
  @typeloader = Puppet::Util::Autoload.new(self, "puppet/type", :wrap => false)
@@ -4,7 +4,6 @@ require 'pathname'
4
4
  require 'fileutils'
5
5
  require 'puppet/util/colors'
6
6
 
7
- # Define tool
8
7
  module Puppet
9
8
  module ModuleTool
10
9
  extend Puppet::Util::Colors
@@ -101,8 +101,6 @@ Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw", :weigh
101
101
  end
102
102
 
103
103
  Puppet::Network::FormatHandler.create_serialized_formats(:pson, :weight => 10, :required_methods => [:render_method, :intern_method]) do
104
- confine :true => Puppet.features.pson?
105
-
106
104
  def intern(klass, text)
107
105
  data_to_instance(klass, PSON.parse(text))
108
106
  end
@@ -18,9 +18,8 @@ class Puppet::Node
18
18
 
19
19
  attr_accessor :name, :classes, :source, :ipaddress, :parameters
20
20
  attr_reader :time, :facts
21
- #
22
- # Load json before trying to register.
23
- Puppet.features.pson? and ::PSON.register_document_type('Node',self)
21
+
22
+ ::PSON.register_document_type('Node',self)
24
23
 
25
24
  def self.from_pson(pson)
26
25
  raise ArgumentError, "No name provided in pson data" unless name = pson['name']
@@ -1,7 +1,9 @@
1
1
  require 'puppet/util'
2
2
  require 'puppet/util/cacher'
3
+ require 'puppet/util/manifest_filetype_helper'
3
4
  require 'monitor'
4
5
 
6
+
5
7
  # Just define it, so this class has fewer load dependencies.
6
8
  class Puppet::Node
7
9
  end
@@ -88,6 +90,17 @@ class Puppet::Node::Environment
88
90
  }
89
91
  end
90
92
 
93
+ # Yields each modules' plugin directory.
94
+ #
95
+ # @yield [String] Yields the plugin directory from each module to the block.
96
+ # @api public
97
+ def each_plugin_directory(&block)
98
+ modules.map(&:plugin_directory).each do |lib|
99
+ lib = Puppet::Util::Autoload.cleanpath(lib)
100
+ yield lib if File.directory?(lib)
101
+ end
102
+ end
103
+
91
104
  def module(name)
92
105
  modules.find {|mod| mod.name == name}
93
106
  end
@@ -205,7 +218,7 @@ class Puppet::Node::Environment
205
218
  private
206
219
 
207
220
  def perform_initial_import
208
- return empty_parse_result if Puppet.settings[:ignoreimport]
221
+ return empty_parse_result if Puppet.settings[:ignoreimport] or Puppet::Util::ManifestFiletypeHelper.is_ruby_filename?(Puppet.settings.value(:manifest, name))
209
222
  parser = Puppet::Parser::Parser.new(self)
210
223
  if code = Puppet.settings.uninterpolated_value(:code, name.to_s) and code != ""
211
224
  parser.string = code
@@ -3,6 +3,22 @@ require 'puppet/util/log_paths'
3
3
  require 'puppet/util/logging'
4
4
  require 'puppet/util/docs'
5
5
 
6
+ # The Parameter class is the implementation of a resource's attributes of _parameter_ kind.
7
+ # The Parameter class is also the base class for {Puppet::Property}, and is used to describe meta-parameters
8
+ # (parameters that apply to all resource types).
9
+ # A Parameter (in contrast to a Property) has a single value where a property has both a current and a wanted value.
10
+ # The Parameter class methods are used to configure and create an instance of Parameter that represents
11
+ # one particular attribute data type; its valid value(s), and conversion to/from internal form.
12
+ #
13
+ # The intention is that a new parameter is created by using the DSL method {Puppet::Type.newparam}, or
14
+ # {Puppet::Type.newmetaparam} if the parameter should be applicable to all resource types.
15
+ #
16
+ # A Parameter that does not specify and valid values (via {newvalues}) accepts any value.
17
+ #
18
+ # @see Puppet::Type
19
+ # @see Puppet::Property
20
+ # @api public
21
+ #
6
22
  class Puppet::Parameter
7
23
  include Puppet::Util
8
24
  include Puppet::Util::Errors
@@ -15,12 +31,71 @@ class Puppet::Parameter
15
31
  class << self
16
32
  include Puppet::Util
17
33
  include Puppet::Util::Docs
18
- attr_reader :validater, :munger, :name, :default, :required_features, :value_collection
34
+ # Unused?
35
+ # @todo The term "validater" only appears in this location in the Puppet code base. There is `validate`
36
+ # which seems to works fine without this attribute declaration.
37
+ # @api private
38
+ #
39
+ attr_reader :validater
40
+
41
+ # Unused?
42
+ # @todo The term "munger" only appears in this location in the Puppet code base. There is munge and unmunge
43
+ # and they seem to work perfectly fine without this attribute declaration.
44
+ # @api private
45
+ #
46
+ attr_reader :munger
47
+
48
+ # @return [Symbol] The parameter name as given when it was created.
49
+ attr_reader :name
50
+
51
+ # @return [Object] The default value of the parameter as determined by the {defaultto} method, or nil if no
52
+ # default has been set.
53
+ attr_reader :default
54
+
55
+ # @comment This somewhat odd documentation construct is because the getter and setter are not
56
+ # orthogonal; the setter uses varargs and this confuses yard. To overcome the problem both the
57
+ # getter and the setter are documented here. If this issues is fixed, a todo will be displayed
58
+ # for the setter method, and the setter documentation can be moved there.
59
+ # Since the attribute is actually RW it should perhaps instead just be implemented as a setter
60
+ # and a getter method (and no attr_xxx declaration).
61
+ #
62
+ # @!attribute [rw] required_features
63
+ # @return [Array<Symbol>] The names of the _provider features_ required for this parameter to work.
64
+ # the returned names are always all lower case symbols.
65
+ # @overload required_features
66
+ # Returns the required _provider features_ as an array of lower case symbols
67
+ # @overload required_features=(*args)
68
+ # @param *args [Symbol] one or more names of required provider features
69
+ # Sets the required_provider_features_ from one or more values, or array. The given arguments
70
+ # are flattened, and internalized.
71
+ # @api public
72
+ # @dsl type
73
+ #
74
+ attr_reader :required_features
75
+
76
+ # @return [Puppet::Parameter::ValueCollection] The set of valid values (or an empty set that accepts any value).
77
+ # @api private
78
+ #
79
+ attr_reader :value_collection
80
+
81
+ # @return [Boolean] Flag indicating whether this parameter is a meta-parameter or not.
19
82
  attr_accessor :metaparam
20
83
 
21
- # Define the default value for a given parameter or parameter. This
22
- # means that 'nil' is an invalid default value. This defines
23
- # the 'default' instance method.
84
+ # Defines how the `default` value of a parameter is computed.
85
+ # The computation of the parameter's default value is defined by providing a value or a block.
86
+ # A default of `nil` can not be used.
87
+ # @overload defaultto(value)
88
+ # Defines the default value with a literal value
89
+ # @param value [Object] the literal value to use as the default value
90
+ # @overload defaultto({|| ... })
91
+ # Defines that the default value is produced by the given block. The given block
92
+ # should produce the default value.
93
+ # @raise [Puppet::DevError] if value is nil, and no block is given.
94
+ # @return [void]
95
+ # @see Parameter.default
96
+ # @dsl type
97
+ # @api public
98
+ #
24
99
  def defaultto(value = nil, &block)
25
100
  if block
26
101
  define_method(:default, &block)
@@ -33,8 +108,12 @@ class Puppet::Parameter
33
108
  end
34
109
  end
35
110
 
36
- # Return a documentation string. If there are valid values,
37
- # then tack them onto the string.
111
+ # Produces a documentation string.
112
+ # If an enumeration of _valid values_ has been defined, it is appended to the documentation
113
+ # for this parameter specified with the {desc} method.
114
+ # @return [String] Returns a documentation string.
115
+ # @api public
116
+ #
38
117
  def doc
39
118
  @doc ||= ""
40
119
 
@@ -50,21 +129,49 @@ class Puppet::Parameter
50
129
  @doc
51
130
  end
52
131
 
132
+ # Removes the `default` method if defined.
133
+ # Has no effect if the default method is not defined.
134
+ # This method is intended to be used in a DSL scenario where a parameter inherits from a parameter
135
+ # with a default value that is not wanted in the derived parameter (otherwise, simply do not define
136
+ # a default value method).
137
+ #
138
+ # @return [void]
139
+ # @see desc
140
+ # @api public
141
+ # @dsl type
142
+ #
53
143
  def nodefault
54
144
  undef_method :default if public_method_defined? :default
55
145
  end
56
146
 
57
- # Store documentation for this parameter.
147
+ # Sets the documentation for this parameter.
148
+ # @param str [String] The documentation string to set
149
+ # @return [String] the given `str` parameter
150
+ # @see doc
151
+ # @dsl type
152
+ # @api public
153
+ #
58
154
  def desc(str)
59
155
  @doc = str
60
156
  end
61
157
 
158
+ # Initializes the instance variables.
159
+ # Clears the internal value collection (set of allowed values).
160
+ # @return [void]
161
+ # @api private
162
+ #
62
163
  def initvars
63
164
  @value_collection = ValueCollection.new
64
165
  end
65
166
 
66
- # This is how we munge the value. Basically, this is our
67
- # opportunity to convert the value from one form into another.
167
+ # @overload munge {|| ... }
168
+ # Defines an optional method used to convert the parameter value from DSL/string form to an internal form.
169
+ # If a munge method is not defined, the DSL/string value is used as is.
170
+ # @note This adds a method with the name `unsafe_munge` in the created parameter class. Later this method is
171
+ # called in a context where exceptions will be rescued and handled.
172
+ # @dsl type
173
+ # @api public
174
+ #
68
175
  def munge(&block)
69
176
  # I need to wrap the unsafe version in begin/rescue parameterments,
70
177
  # but if I directly call the block then it gets bound to the
@@ -73,55 +180,105 @@ class Puppet::Parameter
73
180
  define_method(:unsafe_munge, &block)
74
181
  end
75
182
 
76
- # Does the parameter support reverse munging?
77
- # This will be called when something wants to access the parameter
78
- # in a canonical form different to what the storage form is.
183
+ # @overload unmunge {|| ... }
184
+ # Defines an optional method used to convert the parameter value to DSL/string form from an internal form.
185
+ # If an `unmunge` method is not defined, the internal form is used.
186
+ # @see munge
187
+ # @note This adds a method with the name `unmunge` in the created parameter class.
188
+ # @dsl type
189
+ # @api public
190
+ #
79
191
  def unmunge(&block)
80
192
  define_method(:unmunge, &block)
81
193
  end
82
194
 
83
- # Mark whether we're the namevar.
195
+ # Sets a marker indicating that this parameter is the _namevar_ (unique identifier) of the type
196
+ # where the parameter is contained.
197
+ # This also makes the parameter a required value. The marker can not be unset once it has been set.
198
+ # @return [void]
199
+ # @dsl type
200
+ # @api public
201
+ #
84
202
  def isnamevar
85
203
  @isnamevar = true
86
204
  @required = true
87
205
  end
88
206
 
89
- # Is this parameter the namevar? Defaults to false.
207
+ # @return [Boolean] Returns whether this parameter is the _namevar_ or not.
208
+ # @api public
209
+ #
90
210
  def isnamevar?
91
211
  @isnamevar
92
212
  end
93
213
 
94
- # This parameter is required.
214
+ # Sets a marker indicating that this parameter is required.
215
+ # Once set, it is not possible to make a parameter optional.
216
+ # @return [void]
217
+ # @dsl type
218
+ # @api public
219
+ #
95
220
  def isrequired
96
221
  @required = true
97
222
  end
98
223
 
99
- # Specify features that are required for this parameter to work.
224
+ # @comment This method is not picked up by yard as it has a different signature than
225
+ # expected for an attribute (varargs). Instead, this method is documented as an overload
226
+ # of the attribute required_features. (Not ideal, but better than nothing).
227
+ # @todo If this text appears in documentation - see comment in source and makes corrections - it means
228
+ # that an issue in yardoc has been fixed.
229
+ #
100
230
  def required_features=(*args)
101
231
  @required_features = args.flatten.collect { |a| a.to_s.downcase.intern }
102
232
  end
103
233
 
104
- # Is this parameter required? Defaults to false.
234
+ # Returns whether this parameter is required or not.
235
+ # A parameter is required if a call has been made to the DSL method {isrequired}.
236
+ # @return [Boolean] Returns whether this parameter is required or not.
237
+ # @api public
238
+ #
105
239
  def required?
106
240
  @required
107
241
  end
108
242
 
109
- # Verify that we got a good value
243
+ # @overload validate {|| ... }
244
+ # Defines an optional method that is used to validate the parameter's value.
245
+ # Validation should raise appropriate exceptions, the return value of the given block is ignored.
246
+ # @return [void]
247
+ # @dsl type
248
+ # @api public
249
+ #
110
250
  def validate(&block)
111
251
  define_method(:unsafe_validate, &block)
112
252
  end
113
253
 
114
- # Define a new value for our parameter.
254
+ # Defines valid values for the parameter (enumeration or regular expressions).
255
+ # The set of valid values for the parameter can be limited to a (mix of) literal values and
256
+ # regular expression patterns.
257
+ # @note Each call to this method adds to the set of valid values
258
+ # @param names [Symbol, Regexp] The set of valid literal values and/or patterns for the parameter.
259
+ # @return [void]
260
+ # @dsl type
261
+ # @api public
262
+ #
115
263
  def newvalues(*names)
116
264
  @value_collection.newvalues(*names)
117
265
  end
118
266
 
267
+ # Makes the given `name` an alias for the given `other` name.
268
+ # Or said differently, the valid value `other` can now also be referred to via the given `name`.
269
+ # Aliasing may affect how the parameter's value is serialized/stored (it may store the `other` value
270
+ # instead of the alias).
271
+ # @api public
272
+ # @dsl type
273
+ #
119
274
  def aliasvalue(name, other)
120
275
  @value_collection.aliasvalue(name, other)
121
276
  end
122
277
  end
123
278
 
124
- # Just a simple method to proxy instance methods to class methods
279
+ # Creates instance (proxy) methods that delegates to a class method with the same name.
280
+ # @api private
281
+ #
125
282
  def self.proxymethods(*values)
126
283
  values.each { |val|
127
284
  define_method(val) do
@@ -130,21 +287,45 @@ class Puppet::Parameter
130
287
  }
131
288
  end
132
289
 
133
- # And then define one of these proxies for each method in our
134
- # ParamHandler class.
290
+ # @!method required?
291
+ # (see required?)
292
+ # @!method isnamevar?
293
+ # (see isnamevar?)
294
+ #
135
295
  proxymethods("required?", "isnamevar?")
136
296
 
297
+ # @return [Puppet::Resource] A reference to the resource this parameter is an attribute of (the _associated resource_).
137
298
  attr_accessor :resource
138
- # LAK 2007-05-09: Keep the @parent around for backward compatibility.
299
+
300
+ # @comment LAK 2007-05-09: Keep the @parent around for backward compatibility.
301
+ # @return [Puppet::Parameter] A reference to the parameter's parent kept for backwards compatibility.
302
+ # @api private
303
+ #
139
304
  attr_accessor :parent
140
305
 
306
+ # @!method line()
307
+ # @return [Integer] Returns the result of calling the same method on the associated resource.
308
+ # @!method file
309
+ # @return [Integer] Returns the result of calling the same method on the associated resource.
310
+ # @!method version
311
+ # @return [Integer] Returns the result of calling the same method on the associated resource.
312
+ #
141
313
  [:line, :file, :version].each do |param|
142
314
  define_method(param) do
143
315
  resource.send(param)
144
316
  end
145
317
  end
146
318
 
147
- # Basic parameter initialization.
319
+ # Initializes the parameter with a required resource reference and optional attribute settings.
320
+ # The option `:resource` must be specified or an exception is raised. Any additional options passed
321
+ # are used to initialize the attributes of this parameter by treating each key in the `options` hash as
322
+ # the name of the attribute to set, and the value as the value to set.
323
+ # @param options [Hash{Symbol => Object]] Options, where `resource` is required
324
+ # @option options [Puppet::Resource] :resource The resource this parameter holds a value for. Required.
325
+ # @raise [Puppet::DevError] If resource is not specified in the options hash.
326
+ # @api public
327
+ # @note A parameter should be created via the DSL method {Puppet::Type::newparam}
328
+ #
148
329
  def initialize(options = {})
149
330
  options = symbolize_options(options)
150
331
  if resource = options[:resource]
@@ -157,24 +338,35 @@ class Puppet::Parameter
157
338
  set_options(options)
158
339
  end
159
340
 
341
+ # Writes the given `msg` to the log with the loglevel indicated by the associated resource's
342
+ # `loglevel` parameter.
343
+ # @todo is loglevel a metaparameter? it is looked up with `resource[:loglevel]`
344
+ # @return [void]
345
+ # @api public
160
346
  def log(msg)
161
347
  send_log(resource[:loglevel], msg)
162
348
  end
163
349
 
164
- # Is this parameter a metaparam?
350
+ # @return [Boolean] Returns whether this parameter is a meta-parameter or not.
165
351
  def metaparam?
166
352
  self.class.metaparam
167
353
  end
168
354
 
169
- # each parameter class must define the name method, and parameter
170
- # instances do not change that name this implicitly means that a given
171
- # object can only have one parameter instance of a given parameter
172
- # class
355
+ # @!attribute [r] name
356
+ # @return [Symbol] The parameter's name as given when it was created.
357
+ # @note Since a Parameter defines the name at the class level, each Parameter class must be
358
+ # unique within a type's inheritance chain.
359
+ # @comment each parameter class must define the name method, and parameter
360
+ # instances do not change that name this implicitly means that a given
361
+ # object can only have one parameter instance of a given parameter
362
+ # class
173
363
  def name
174
364
  self.class.name
175
365
  end
176
366
 
177
- # for testing whether we should actually do anything
367
+ # @return [Boolean] Returns true if this parameter, the associated resource, or overall puppet mode is `noop`.
368
+ # @todo How is noop mode set for a parameter? Is this of value in DSL to inhibit a parameter?
369
+ #
178
370
  def noop
179
371
  @noop ||= false
180
372
  tmp = @noop || self.resource.noop || Puppet[:noop] || false
@@ -182,8 +374,11 @@ class Puppet::Parameter
182
374
  tmp
183
375
  end
184
376
 
185
- # return the full path to us, for logging and rollback; not currently
186
- # used
377
+ # @todo Original comment = _return the full path to us, for logging and rollback; not currently
378
+ # used_ This is difficult to figure out (if it is used or not as calls are certainly made to "pathbuilder"
379
+ # method is several places, not just sure if it is this implementation or not.
380
+ #
381
+ # @api private
187
382
  def pathbuilder
188
383
  if @resource
189
384
  return [@resource.pathbuilder, self.name]
@@ -192,18 +387,31 @@ class Puppet::Parameter
192
387
  end
193
388
  end
194
389
 
195
- # If the specified value is allowed, then munge appropriately.
196
- # If the developer uses a 'munge' hook, this method will get overridden.
390
+ # This is the default implementation of `munge` that simply produces the value (if it is valid).
391
+ # The DSL method {munge} should be used to define an overriding method if munging is required.
392
+ #
393
+ # @api private
394
+ #
197
395
  def unsafe_munge(value)
198
396
  self.class.value_collection.munge(value)
199
397
  end
200
398
 
201
- # no unmunge by default
399
+ # Unmunges the value by transforming it from internal form to DSL form.
400
+ # This is the default implementation of `unmunge` that simply returns the value without processing.
401
+ # The DSL method {unmunge} should be used to define an overriding method if required.
402
+ # @return [Object] the unmunged value
403
+ #
202
404
  def unmunge(value)
203
405
  value
204
406
  end
205
407
 
206
- # A wrapper around our munging that makes sure we raise useful exceptions.
408
+ # Munges the value to internal form.
409
+ # This implementation of `munge` provides exception handling around the specified munging of this parameter.
410
+ # @note This method should not be overridden. Use the DSL method {munge} to define a munging method
411
+ # if required.
412
+ # @param value [Object] the DSL value to munge
413
+ # @return [Object] the munged (internal) value
414
+ #
207
415
  def munge(value)
208
416
  begin
209
417
  ret = unsafe_munge(value)
@@ -216,13 +424,27 @@ class Puppet::Parameter
216
424
  ret
217
425
  end
218
426
 
219
- # Verify that the passed value is valid.
220
- # If the developer uses a 'validate' hook, this method will get overridden.
427
+ # This is the default implementation of `validate` that may be overridden by the DSL method {validate}.
428
+ # If no valid values have been defined, the given value is accepted, else it is validated against
429
+ # the literal values (enumerator) and/or patterns defined by calling {newvalues}.
430
+ #
431
+ # @param value [Object] the value to check for validity
432
+ # @raise [ArgumentError] if the value is not valid
433
+ # @return [void]
434
+ # @api private
435
+ #
221
436
  def unsafe_validate(value)
222
437
  self.class.value_collection.validate(value)
223
438
  end
224
439
 
440
+ # Performs validation of the given value against the rules defined by this parameter.
441
+ # @return [void]
442
+ # @todo Better description of when the various exceptions are raised.ArgumentError is rescued and
443
+ # changed into Puppet::Error.
444
+ # @raise [ArgumentError, TypeError, Puppet::DevError, Puppet::Error] under various conditions
225
445
  # A protected validation method that only ever raises useful exceptions.
446
+ # @api public
447
+ #
226
448
  def validate(value)
227
449
  begin
228
450
  unsafe_validate(value)
@@ -235,30 +457,54 @@ class Puppet::Parameter
235
457
  end
236
458
  end
237
459
 
460
+ # Sets the associated resource to nil.
461
+ # @todo Why - what is the intent/purpose of this?
462
+ # @return [nil]
463
+ #
238
464
  def remove
239
465
  @resource = nil
240
466
  end
241
467
 
468
+ # @return [Object] Gets the value of this parameter after performing any specified unmunging.
242
469
  def value
243
470
  unmunge(@value) unless @value.nil?
244
471
  end
245
472
 
246
- # Store the value provided. All of the checking should possibly be
247
- # late-binding (e.g., users might not exist when the value is assigned
248
- # but might when it is asked for).
473
+ # Sets the given value as the value of this parameter.
474
+ # @todo This original comment _"All of the checking should possibly be
475
+ # late-binding (e.g., users might not exist when the value is assigned
476
+ # but might when it is asked for)."_ does not seem to be correct, the implementation
477
+ # calls both validate an munge on the given value, so no late binding.
478
+ #
479
+ # The given value is validated and then munged (if munging has been specified). The result is store
480
+ # as the value of this arameter.
481
+ # @return [Object] The given `value` after munging.
482
+ # @raise (see #validate)
483
+ #
249
484
  def value=(value)
250
485
  validate(value)
251
486
 
252
487
  @value = munge(value)
253
488
  end
254
489
 
255
- # Retrieve the resource's provider. Some types don't have providers, in which
256
- # case we return the resource object itself.
490
+ # @return [Puppet::Provider] Returns the provider of the associated resource.
491
+ # @todo The original comment says = _"Retrieve the resource's provider.
492
+ # Some types don't have providers, in which case we return the resource object itself."_
493
+ # This does not seem to be true, the default implementation that sets this value may be
494
+ # {Puppet::Type.provider=} which always gets either the name of a provider or an instance of one.
495
+ #
257
496
  def provider
258
497
  @resource.provider
259
498
  end
260
499
 
261
- # The properties need to return tags so that logs correctly collect them.
500
+ # @return [Array<Symbol>] Returns an array of the associated resource's symbolic tags (including the parameter itself).
501
+ # Returns an array of the associated resource's symbolic tags (including the parameter itself).
502
+ # At a minimun, the array contains the name of the parameter. If the associated resource
503
+ # has tags, these tags are also included in the array.
504
+ # @todo The original comment says = _"The properties need to return tags so that logs correctly
505
+ # collect them."_ what if anything of that is of interest to document. Should tags and their relationship
506
+ # to logs be described. This is a more general concept.
507
+ #
262
508
  def tags
263
509
  unless defined?(@tags)
264
510
  @tags = []
@@ -269,10 +515,29 @@ class Puppet::Parameter
269
515
  @tags
270
516
  end
271
517
 
518
+ # @return [String] The name of the parameter in string form.
272
519
  def to_s
273
520
  name.to_s
274
521
  end
275
522
 
523
+ # Produces a String with the value formatted for display to a human.
524
+ # When the parameter value is a:
525
+ #
526
+ # * **single valued parameter value** the result is produced on the
527
+ # form `'value'` where _value_ is the string form of the parameter's value.
528
+ #
529
+ # * **Array** the list of values is enclosed in `[]`, and
530
+ # each produced value is separated by a comma.
531
+ #
532
+ # * **Hash** value is output with keys in sorted order enclosed in `{}` with each entry formatted
533
+ # on the form `'k' => v` where
534
+ # `k` is the key in string form and _v_ is the value of the key. Entries are comma separated.
535
+ #
536
+ # For both Array and Hash this method is called recursively to format contained values.
537
+ # @note this method does not protect against infinite structures.
538
+ #
539
+ # @return [String] The formatted value in string form.
540
+ #
276
541
  def self.format_value_for_display(value)
277
542
  if value.is_a? Array
278
543
  formatted_values = value.collect {|value| format_value_for_display(value)}.join(', ')