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
@@ -0,0 +1,15 @@
1
+ # Convert arguments into booleans, integers, or whatever.
2
+ class Puppet::Settings::ValueTranslator
3
+ def [](value)
4
+ # Handle different data types correctly
5
+ return case value
6
+ when /^false$/i; false
7
+ when /^true$/i; true
8
+ when /^\d+$/i; Integer(value)
9
+ when true; true
10
+ when false; false
11
+ else
12
+ value.gsub(/^["']|["']$/,'').sub(/\s+$/, '')
13
+ end
14
+ end
15
+ end
@@ -1,8 +1,8 @@
1
- # This class is basically a hidden class that knows how to act on the
2
- # CA. Its job is to provide a CLI-like interface to the CA class.
3
1
  module Puppet
4
2
  module SSL
5
3
  class CertificateAuthority
4
+ # This class is basically a hidden class that knows how to act on the
5
+ # CA. Its job is to provide a CLI-like interface to the CA class.
6
6
  class Interface
7
7
  INTERFACE_METHODS = [:destroy, :list, :revoke, :generate, :sign, :print, :verify, :fingerprint]
8
8
 
@@ -27,6 +27,13 @@ module Puppet::Test
27
27
  # other features such as "around_test", but we didn't see a compelling
28
28
  # reason to deal with that right now.
29
29
  class TestHelper
30
+ # Call this method once, as early as possible, such as before loading tests
31
+ # that call Puppet.
32
+ # @return nil
33
+ def self.initialize()
34
+ initialize_settings_before_each
35
+ end
36
+
30
37
  # Call this method once, when beginning a test run--prior to running
31
38
  # any individual tests.
32
39
  # @return nil
@@ -146,9 +153,7 @@ module Puppet::Test
146
153
  def self.initialize_settings_before_each()
147
154
  Puppet.settings.preferred_run_mode = "user"
148
155
  # Initialize "app defaults" settings to a good set of test values
149
- app_defaults_for_tests.each do |key, value|
150
- Puppet.settings.set_value(key, value, :application_defaults)
151
- end
156
+ Puppet.settings.initialize_app_defaults(app_defaults_for_tests)
152
157
 
153
158
  # Avoid opening ports to the outside world
154
159
  Puppet.settings[:bindaddress] = "127.0.0.1"
@@ -12,8 +12,7 @@ class Puppet::Transaction
12
12
  require 'puppet/transaction/resource_harness'
13
13
  require 'puppet/resource/status'
14
14
 
15
- attr_accessor :component, :catalog, :ignoreschedules, :for_network_device
16
- attr_accessor :configurator
15
+ attr_accessor :catalog, :ignoreschedules, :for_network_device
17
16
 
18
17
  # The report, once generated.
19
18
  attr_reader :report
@@ -1,34 +1,119 @@
1
1
  require 'puppet'
2
2
  require 'puppet/indirector'
3
3
 
4
- # A class for reporting what happens on each client. Reports consist of
5
- # two types of data: Logs and Metrics. Logs are the output that each
6
- # change produces, and Metrics are all of the numerical data involved
7
- # in the transaction.
4
+ # This class is used to report what happens on a client.
5
+ # There are two types of data in a report; _Logs_ and _Metrics_.
6
+ #
7
+ # * **Logs** - are the output that each change produces.
8
+ # * **Metrics** - are all of the numerical data involved in the transaction.
9
+ #
10
+ # Use {Puppet::Reports} class to create a new custom report type. This class is indirectly used
11
+ # as a source of data to report in such a registered report.
12
+ #
13
+ # ##Metrics
14
+ # There are three types of metrics in each report, and each type of metric has one or more values.
15
+ #
16
+ # * Time: Keeps track of how long things took.
17
+ # * Total: Total time for the configuration run
18
+ # * File:
19
+ # * Exec:
20
+ # * User:
21
+ # * Group:
22
+ # * Config Retrieval: How long the configuration took to retrieve
23
+ # * Service:
24
+ # * Package:
25
+ # * Resources: Keeps track of the following stats:
26
+ # * Total: The total number of resources being managed
27
+ # * Skipped: How many resources were skipped, because of either tagging or scheduling restrictions
28
+ # * Scheduled: How many resources met any scheduling restrictions
29
+ # * Out of Sync: How many resources were out of sync
30
+ # * Applied: How many resources were attempted to be fixed
31
+ # * Failed: How many resources were not successfully fixed
32
+ # * Restarted: How many resources were restarted because their dependencies changed
33
+ # * Failed Restarts: How many resources could not be restarted
34
+ # * Changes: The total number of changes in the transaction.
35
+ #
36
+ # @api public
8
37
  class Puppet::Transaction::Report
9
38
  extend Puppet::Indirector
10
39
 
11
40
  indirects :report, :terminus_class => :processor
12
41
 
13
- attr_accessor :configuration_version, :host, :environment
14
- attr_reader :resource_statuses, :logs, :metrics, :time, :kind, :status,
15
- :puppet_version, :report_format
16
-
17
- # This is necessary since Marshall doesn't know how to
18
- # dump hash with default proc (see below @records)
42
+ # The version of the configuration
43
+ # @todo Uncertain what this is?
44
+ # @return [???] the configuration version
45
+ attr_accessor :configuration_version
46
+
47
+ # The host name for which the report is generated
48
+ # @return [String] the host name
49
+ attr_accessor :host
50
+
51
+ # The name of the environment the host is in
52
+ # @return [String] the environment name
53
+ attr_accessor :environment
54
+
55
+ # A hash with a map from resource to status
56
+ # @return [Hash<{String => String}>] Resource name to status string.
57
+ # @todo Uncertain if the types in the hash are correct...
58
+ attr_reader :resource_statuses
59
+
60
+ # A list of log messages.
61
+ # @return [Array<String>] logged messages
62
+ attr_reader :logs
63
+
64
+ # A hash of metric name to metric value.
65
+ # @return [Hash<{String => Object}>] A map of metric name to value.
66
+ # @todo Uncertain if all values are numbers - now marked as Object.
67
+ #
68
+ attr_reader :metrics
69
+
70
+ # The time when the report data was generated.
71
+ # @return [Time] A time object indicating when the report data was generated
72
+ #
73
+ attr_reader :time
74
+
75
+ # The 'kind' of report is the name of operation that triggered the report to be produced.
76
+ # Typically "apply".
77
+ # @return [String] the kind of operation that triggered the generation of the report.
78
+ #
79
+ attr_reader :kind
80
+
81
+ # The status of the client run is an enumeration: 'failed', 'changed' or 'unchanged'
82
+ # @return [String] the status of the run - one of the values 'failed', 'changed', or 'unchanged'
83
+ #
84
+ attr_reader :status
85
+
86
+ # @return [String] The Puppet version in String form.
87
+ # @see Puppet::version()
88
+ #
89
+ attr_reader :puppet_version
90
+
91
+ # @return [Integer] (3) a report format version number
92
+ # @todo Unclear what this is - a version?
93
+ #
94
+ attr_reader :report_format
95
+
96
+ # This is necessary since Marshal doesn't know how to
97
+ # dump hash with default proc (see below "@records") ?
98
+ # @todo there is no "@records" to see below, uncertain what this is for.
99
+ # @api private
100
+ #
19
101
  def self.default_format
20
102
  :yaml
21
103
  end
22
104
 
105
+ # @api private
23
106
  def <<(msg)
24
107
  @logs << msg
25
108
  self
26
109
  end
27
110
 
111
+ # @api private
28
112
  def add_times(name, value)
29
113
  @external_times[name] = value
30
114
  end
31
115
 
116
+ # @api private
32
117
  def add_metric(name, hash)
33
118
  metric = Puppet::Util::Metric.new(name)
34
119
 
@@ -40,10 +125,12 @@ class Puppet::Transaction::Report
40
125
  metric
41
126
  end
42
127
 
128
+ # @api private
43
129
  def add_resource_status(status)
44
130
  @resource_statuses[status.resource] = status
45
131
  end
46
132
 
133
+ # @api private
47
134
  def compute_status(resource_metrics, change_metric)
48
135
  if (resource_metrics["failed"] || 0) > 0
49
136
  'failed'
@@ -54,10 +141,12 @@ class Puppet::Transaction::Report
54
141
  end
55
142
  end
56
143
 
144
+ # @api private
57
145
  def prune_internal_data
58
146
  resource_statuses.delete_if {|name,res| res.resource_type == 'Whit'}
59
147
  end
60
148
 
149
+ # @api private
61
150
  def finalize_report
62
151
  prune_internal_data
63
152
 
@@ -69,6 +158,7 @@ class Puppet::Transaction::Report
69
158
  @status = compute_status(resource_metrics, change_metric)
70
159
  end
71
160
 
161
+ # @api private
72
162
  def initialize(kind, configuration_version=nil, environment=nil)
73
163
  @metrics = {}
74
164
  @logs = []
@@ -84,11 +174,18 @@ class Puppet::Transaction::Report
84
174
  @status = 'failed' # assume failed until the report is finalized
85
175
  end
86
176
 
177
+ # @return [String] the host name
178
+ # @api public
179
+ #
87
180
  def name
88
181
  host
89
182
  end
90
183
 
91
184
  # Provide a human readable textual summary of this report.
185
+ # @note This is intended for debugging purposes
186
+ # @return [String] A string with a textual summary of this report.
187
+ # @api public
188
+ #
92
189
  def summary
93
190
  report = raw_summary
94
191
 
@@ -115,7 +212,10 @@ class Puppet::Transaction::Report
115
212
  ret
116
213
  end
117
214
 
118
- # Provide a raw hash summary of this report.
215
+ # Provides a raw hash summary of this report.
216
+ # @return [Hash<{String => Object}>] A hash with metrics key to value map
217
+ # @api public
218
+ #
119
219
  def raw_summary
120
220
  report = { "version" => { "config" => configuration_version, "puppet" => Puppet.version } }
121
221
 
@@ -131,9 +231,16 @@ class Puppet::Transaction::Report
131
231
  report
132
232
  end
133
233
 
134
- # Based on the contents of this report's metrics, compute a single number
135
- # that represents the report. The resulting number is a bitmask where
234
+ # Computes a single number that represents the report's status.
235
+ # The computation is based on the contents of this report's metrics.
236
+ # The resulting number is a bitmask where
136
237
  # individual bits represent the presence of different metrics.
238
+ #
239
+ # * 0x2 set if there are changes
240
+ # * 0x4 set if there are failures
241
+ # @return [Integer] A bitmask where 0x2 is set if there are changes, and 0x4 is set of there are failures.
242
+ # @api public
243
+ #
137
244
  def exit_status
138
245
  status = 0
139
246
  status |= 2 if @metrics["changes"]["total"] > 0
@@ -141,6 +248,8 @@ class Puppet::Transaction::Report
141
248
  status
142
249
  end
143
250
 
251
+ # @api private
252
+ #
144
253
  def to_yaml_properties
145
254
  instance_variables - [:@external_times]
146
255
  end
@@ -13,7 +13,67 @@ require 'puppet/util/tagging'
13
13
 
14
14
  # see the bottom of the file for the rest of the inclusions
15
15
 
16
+
16
17
  module Puppet
18
+ # The base class for all Puppet types.
19
+ #
20
+ # A type describes:
21
+ #--
22
+ # * **Attributes** - properties, parameters, and meta-parameters are different types of attributes of a type.
23
+ # * **Properties** - these are the properties of the managed resource (attributes of the entity being managed; like
24
+ # a file's owner, group and mode). A property describes two states; the 'is' (current state) and the 'should' (wanted
25
+ # state).
26
+ # * **Ensurable** - a set of traits that control the lifecycle (create, remove, etc.) of a managed entity.
27
+ # There is a default set of operations associated with being _ensurable_, but this can be changed.
28
+ # * **Name/Identity** - one property is the name/identity of a resource, the _namevar_ that uniquely identifies
29
+ # one instance of a type from all others.
30
+ # * **Parameters** - additional attributes of the type (that does not directly related to an instance of the managed
31
+ # resource; if an operation is recursive or not, where to look for things, etc.). A Parameter (in contrast to Property)
32
+ # has one current value where a Property has two (current-state and wanted-state).
33
+ # * **Meta-Parameters** - parameters that are available across all types. A meta-parameter typically has
34
+ # additional semantics; like the `require` meta-parameter. A new type typically does not add new meta-parameters,
35
+ # but you need to be aware of their existence so you do not inadvertently shadow an existing meta-parameters.
36
+ # * **Parent** - a type can have a super type (that it inherits from).
37
+ # * **Validation** - If not just a basic data type, or an enumeration of symbolic values, it is possible to provide
38
+ # validation logic for a type, properties and parameters.
39
+ # * **Munging** - munging/unmunging is the process of turning a value in external representation (as used
40
+ # by a provider) into an internal representation and vice versa. A Type supports adding custom logic for these.
41
+ # * **Auto Requirements** - a type can specify automatic relationships to resources to ensure that if they are being
42
+ # managed, they will be processed before this type.
43
+ # * **Providers** - a provider is an implementation of a type's behavior - the management of a resource in the
44
+ # system being managed. A provider is often platform specific and is selected at runtime based on
45
+ # criteria/predicates specified in the configured providers. See {Puppet::Provider} for details.
46
+ # * **Device Support** - A type has some support for being applied to a device; i.e. something that is managed
47
+ # by running logic external to the device itself. There are several methods that deals with type
48
+ # applicability for these special cases such as {apply_to_device}.
49
+ #
50
+ # Additional Concepts:
51
+ # --
52
+ # * **Resource-type** - A _resource type_ is a term used to denote the type of a resource; internally a resource
53
+ # is really an instance of a Ruby class i.e. {Puppet::Resource} which defines its behavior as "resource data".
54
+ # Conceptually however, a resource is an instance of a subclass of Type (e.g. File), where such a class describes
55
+ # its interface (what can be said/what is known about a resource of this type),
56
+ # * **Managed Entity** - This is not a term in general use, but is used here when there is a need to make
57
+ # a distinction between a resource (a description of what/how something should be managed), and what it is
58
+ # managing (a file in the file system). The term _managed entity_ is a reference to the "file in the file system"
59
+ # * **Isomorphism** - the quality of being _isomorphic_ means that two resource instances with the same name
60
+ # refers to the same managed entity. Or put differently; _an isomorphic name is the identity of a resource_.
61
+ # As an example, `exec` resources (that executes some command) have the command (i.e. the command line string) as
62
+ # their name, and these resources are said to be non-isomorphic.
63
+ #
64
+ # @note The Type class deals with multiple concerns; some methods provide an internal DSL for convenient definition
65
+ # of types, other methods deal with various aspects while running; wiring up a resource (expressed in Puppet DSL
66
+ # or Ruby DSL) with its _resource type_ (i.e. an instance of Type) to enable validation, transformation of values
67
+ # (munge/unmunge), etc. Lastly, Type is also responsible for dealing with Providers; the concrete implementations
68
+ # of the behavior that constitutes how a particular Type behaves on a particular type of system (e.g. how
69
+ # commands are executed on a flavor of Linux, on Windows, etc.). This means that as you are reading through the
70
+ # documentation of this class, you will be switching between these concepts, as well as switching between
71
+ # the conceptual level "a resource is an instance of a resource-type" and the actual implementation classes
72
+ # (Type, Resource, Provider, and various utility and helper classes).
73
+ #
74
+ # @api public
75
+ #
76
+ #
17
77
  class Type
18
78
  include Puppet::Util
19
79
  include Puppet::Util::Errors
@@ -21,9 +81,15 @@ class Type
21
81
  include Puppet::Util::Logging
22
82
  include Puppet::Util::Tagging
23
83
 
24
- ###############################
25
84
  # Comparing type instances.
26
85
  include Comparable
86
+
87
+ # Compares this type against the given _other_ (type) and returns -1, 0, or +1 depending on the order.
88
+ # @param other [Object] the object to compare against (produces nil, if not kind of Type}
89
+ # @return [-1, 0, +1, nil] produces -1 if this type is before the given _other_ type, 0 if equals, and 1 if after.
90
+ # Returns nil, if the given _other_ is not a kind of Type.
91
+ # @see Comparable
92
+ #
27
93
  def <=>(other)
28
94
  # We only order against other types, not arbitrary objects.
29
95
  return nil unless other.is_a? Puppet::Type
@@ -32,22 +98,30 @@ class Type
32
98
  self.ref <=> other.ref
33
99
  end
34
100
 
35
- ###############################
36
101
  # Code related to resource type attributes.
37
102
  class << self
38
103
  include Puppet::Util::ClassGen
39
104
  include Puppet::Util::Warnings
105
+
106
+ # @return [Array<Puppet::Property>] The list of declared properties for the resource type.
107
+ # The returned lists contains instances if Puppet::Property or its subclasses.
40
108
  attr_reader :properties
41
109
  end
42
110
 
43
- # All parameters, in the appropriate order. The key_attributes come first, then
44
- # the provider, then the properties, and finally the params and metaparams
45
- # in the order they were specified in the files.
111
+ # Returns all the attribute names of the type in the appropriate order.
112
+ # The {key_attributes} come first, then the {provider}, then the {properties}, and finally
113
+ # the {parameters} and {metaparams},
114
+ # all in the order they were specified in the respective files.
115
+ # @return [Array<String>] all type attribute names in a defined order.
116
+ #
46
117
  def self.allattrs
47
118
  key_attributes | (parameters & [:provider]) | properties.collect { |property| property.name } | parameters | metaparams
48
119
  end
49
120
 
50
- # Find the class associated with any given attribute.
121
+ # Returns the class associated with the given attribute name.
122
+ # @param name [String] the name of the attribute to obtain the class for
123
+ # @return [Class, nil] the class for the given attribute, or nil if the name does not refer to an existing attribute
124
+ #
51
125
  def self.attrclass(name)
52
126
  @attrclasses ||= {}
53
127
 
@@ -63,8 +137,11 @@ class Type
63
137
  @attrclasses[name]
64
138
  end
65
139
 
66
- # What type of parameter are we dealing with? Cache the results, because
67
- # this method gets called so many times.
140
+ # Returns the attribute type (`:property`, `;param`, `:meta`).
141
+ # @comment What type of parameter are we dealing with? Cache the results, because
142
+ # this method gets called so many times.
143
+ # @return [Symbol] a symbol describing the type of attribute (`:property`, `;param`, `:meta`)
144
+ #
68
145
  def self.attrtype(attr)
69
146
  @attrtypes ||= {}
70
147
  unless @attrtypes.include?(attr)
@@ -77,13 +154,35 @@ class Type
77
154
 
78
155
  @attrtypes[attr]
79
156
  end
80
-
157
+
158
+ # Provides iteration over meta-parameters.
159
+ # @yieldparam p [Puppet::Parameter] each meta parameter
160
+ # @return [void]
161
+ #
81
162
  def self.eachmetaparam
82
163
  @@metaparams.each { |p| yield p.name }
83
164
  end
84
165
 
85
- # Create the 'ensure' class. This is a separate method so other types
86
- # can easily call it and create their own 'ensure' values.
166
+ # Creates a new `ensure` property with configured default values or with configuration by an optional block.
167
+ # This method is a convenience method for creating a property `ensure` with default accepted values.
168
+ # If no block is specified, the new `ensure` property will accept the default symbolic
169
+ # values `:present`, and `:absent` - see {Puppet::Property::Ensure}.
170
+ # If something else is wanted, pass a block and make calls to {Puppet::Property.newvalue} from this block
171
+ # to define each possible value. If a block is passed, the defaults are not automatically added to the set of
172
+ # valid values.
173
+ #
174
+ # @note This method will be automatically called without a block if the type implements the methods
175
+ # specified by {ensurable?}. It is recommended to always call this method and not rely on this automatic
176
+ # specification to clearly state that the type is ensurable.
177
+ #
178
+ # @overload ensurable()
179
+ # @overload ensurable({|| ... })
180
+ # @yield [ ] A block evaluated in scope of the new Parameter
181
+ # @yieldreturn [void]
182
+ # @return [void]
183
+ # @dsl type
184
+ # @api public
185
+ #
87
186
  def self.ensurable(&block)
88
187
  if block_given?
89
188
  self.newproperty(:ensure, :parent => Puppet::Property::Ensure, &block)
@@ -94,7 +193,12 @@ class Type
94
193
  end
95
194
  end
96
195
 
97
- # Should we add the 'ensure' property to this class?
196
+ # Returns true if the type implements the default behavior expected by being _ensurable_ "by default".
197
+ # A type is _ensurable_ by default if it responds to `:exists`, `:create`, and `:destroy`.
198
+ # If a type implements these methods and have not already specified that it is _ensurable_, it will be
199
+ # made so with the defaults specified in {ensurable}.
200
+ # @return [Boolean] whether the type is _ensurable_ or not.
201
+ #
98
202
  def self.ensurable?
99
203
  # If the class has all three of these methods defined, then it's
100
204
  # ensurable.
@@ -103,34 +207,60 @@ class Type
103
207
  }
104
208
  end
105
209
 
106
- # These `apply_to` methods are horrible. They should really be implemented
107
- # as part of the usual system of constraints that apply to a type and
108
- # provider pair, but were implemented as a separate shadow system.
210
+ # @comment These `apply_to` methods are horrible. They should really be implemented
211
+ # as part of the usual system of constraints that apply to a type and
212
+ # provider pair, but were implemented as a separate shadow system.
213
+ #
214
+ # @comment We should rip them out in favour of a real constraint pattern around the
215
+ # target device - whatever that looks like - and not have this additional
216
+ # magic here. --daniel 2012-03-08
217
+ #
218
+ # Makes this type applicable to `:device`.
219
+ # @return [Symbol] Returns `:device`
220
+ # @api private
109
221
  #
110
- # We should rip them out in favour of a real constraint pattern around the
111
- # target device - whatever that looks like - and not have this additional
112
- # magic here. --daniel 2012-03-08
113
222
  def self.apply_to_device
114
223
  @apply_to = :device
115
224
  end
116
225
 
226
+ # Makes this type applicable to `:host`.
227
+ # @return [Symbol] Returns `:host`
228
+ # @api private
229
+ #
117
230
  def self.apply_to_host
118
231
  @apply_to = :host
119
232
  end
120
233
 
234
+ # Makes this type applicable to `:both` (i.e. `:host` and `:device`).
235
+ # @return [Symbol] Returns `:both`
236
+ # @api private
237
+ #
121
238
  def self.apply_to_all
122
239
  @apply_to = :both
123
240
  end
124
241
 
242
+ # Makes this type apply to `:host` if not already applied to something else.
243
+ # @return [Symbol] a `:device`, `:host`, or `:both` enumeration
244
+ # @api private
125
245
  def self.apply_to
126
246
  @apply_to ||= :host
127
247
  end
128
248
 
249
+ # Returns true if this type is applicable to the given target.
250
+ # @param target [Symbol] should be :device, :host or :target, if anything else, :host is enforced
251
+ # @return [Boolean] true
252
+ # @api private
253
+ #
129
254
  def self.can_apply_to(target)
130
255
  [ target == :device ? :device : :host, :both ].include?(apply_to)
131
256
  end
132
257
 
133
- # Deal with any options passed into parameters.
258
+ # Processes the options for a named parameter.
259
+ # @param name [String] the name of a parameter
260
+ # @param options [Hash] a hash of options
261
+ # @option options [Boolean] :boolean if option set to true, an access method on the form _name_? is added for the param
262
+ # @return [void]
263
+ #
134
264
  def self.handle_param_options(name, options)
135
265
  # If it's a boolean parameter, create a method to test the value easily
136
266
  if options[:boolean]
@@ -143,28 +273,59 @@ class Type
143
273
  end
144
274
  end
145
275
 
146
- # Is the parameter in question a meta-parameter?
276
+ # Is the given parameter a meta-parameter?
277
+ # @return [Boolean] true if the given parameter is a meta-parameter.
278
+ #
147
279
  def self.metaparam?(param)
148
280
  @@metaparamhash.include?(param.intern)
149
281
  end
150
282
 
151
- # Find the metaparameter class associated with a given metaparameter name.
152
- # Must accept a `nil` name, and return nil.
283
+ # Returns the meta-parameter class associated with the given meta-parameter name.
284
+ # Accepts a `nil` name, and return nil.
285
+ # @param name [String, nil] the name of a meta-parameter
286
+ # @return [Class,nil] the class for the given meta-parameter, or `nil` if no such meta-parameter exists, (or if
287
+ # the given meta-parameter name is `nil`.
288
+ #
153
289
  def self.metaparamclass(name)
154
290
  return nil if name.nil?
155
291
  @@metaparamhash[name.intern]
156
292
  end
157
293
 
294
+ # Returns all meta-parameter names.
295
+ # @return [Array<String>] all meta-parameter names
296
+ #
158
297
  def self.metaparams
159
298
  @@metaparams.collect { |param| param.name }
160
299
  end
161
300
 
301
+ # Returns the documentation for a given meta-parameter of this type.
302
+ # @todo the type for the param metaparam
303
+ # @param metaparam [??? Puppet::Parameter] the meta-parameter to get documentation for.
304
+ # @return [String] the documentation associated with the given meta-parameter, or nil of not such documentation
305
+ # exists.
306
+ # @raises [?] if the given metaparam is not a meta-parameter in this type
307
+ #
162
308
  def self.metaparamdoc(metaparam)
163
309
  @@metaparamhash[metaparam].doc
164
310
  end
165
311
 
166
- # Create a new metaparam. Requires a block and a name, stores it in the
167
- # @parameters array, and does some basic checking on it.
312
+ # Creates a new meta-parameter.
313
+ # This creates a new meta-parameter that is added to all types.
314
+ # @param name [Symbol] the name of the parameter
315
+ # @param options [Hash] a hash with options.
316
+ # @option options [Class<inherits Puppet::Parameter>] :parent (Puppet::Parameter) the super class of this parameter
317
+ # @option options [Hash{String => Object}] :attributes a hash that is applied to the generated class
318
+ # by calling setter methods corresponding to this hash's keys/value pairs. This is done before the given
319
+ # block is evaluated.
320
+ # @option options [Boolean] :boolean (false) specifies if this is a boolean parameter
321
+ # @option options [Boolean] :namevar (false) specifies if this parameter is the namevar
322
+ # @option options [Symbol, Array<Symbol>] :required_features specifies required provider features by name
323
+ # @return [Class<inherits Puppet::Parameter>] the created parameter
324
+ # @yield [ ] a required block that is evaluated in the scope of the new meta-parameter
325
+ # @api public
326
+ # @dsl type
327
+ # @todo Verify that this description is ok
328
+ #
168
329
  def self.newmetaparam(name, options = {}, &block)
169
330
  @@metaparams ||= []
170
331
  @@metaparamhash ||= {}
@@ -190,6 +351,11 @@ class Type
190
351
  param
191
352
  end
192
353
 
354
+ # Returns parameters that act as a key.
355
+ # All parameters that return true from #isnamevar? or is named `:name` are included in the returned result.
356
+ # @todo would like a better explanation
357
+ # @return Array<??? Puppet::Parameter>
358
+ #
193
359
  def self.key_attribute_parameters
194
360
  @key_attribute_parameters ||= (
195
361
  params = @parameters.find_all { |param|
@@ -198,11 +364,43 @@ class Type
198
364
  )
199
365
  end
200
366
 
367
+ # Returns cached {key_attribute_parameters} names
368
+ # @todo what is a 'key_attribute' ?
369
+ # @return [Array<String>] cached key_attribute names
370
+ #
201
371
  def self.key_attributes
202
372
  # This is a cache miss around 0.05 percent of the time. --daniel 2012-07-17
203
373
  @key_attributes_cache ||= key_attribute_parameters.collect { |p| p.name }
204
374
  end
205
375
 
376
+ # Returns a mapping from the title string to setting of attribute value(s).
377
+ # This default implementation provides a mapping of title to the one and only _namevar_ present
378
+ # in the type's definition.
379
+ # @note Advanced: some logic requires this mapping to be done differently, using a different
380
+ # validation/pattern, breaking up the title
381
+ # into several parts assigning each to an individual attribute, or even use a composite identity where
382
+ # all namevars are seen as part of the unique identity (such computation is done by the {#uniqueness} method.
383
+ # These advanced options are rarely used (only one of the built in puppet types use this, and then only
384
+ # a small part of the available functionality), and the support for these advanced mappings is not
385
+ # implemented in a straight forward way. For these reasons, this method has been marked as private).
386
+ #
387
+ # @raise [Puppet::DevError] if there is no title pattern and there are two or more key attributes
388
+ # @return [Array<Array<Regexp, Array<Array <Symbol, Proc>>>>, nil] a structure with a regexp and the first key_attribute ???
389
+ # @comment This wonderful piece of logic creates a structure used by Resource.parse_title which
390
+ # has the capability to assign parts of the title to one or more attributes; It looks like an implementation
391
+ # of a composite identity key (all parts of the key_attributes array are in the key). This can also
392
+ # be seen in the method uniqueness_key.
393
+ # The implementation in this method simply assigns the title to the one and only namevar (which is name
394
+ # or a variable marked as namevar).
395
+ # If there are multiple namevars (any in addition to :name?) then this method MUST be implemented
396
+ # as it raises an exception if there is more than 1. Note that in puppet, it is only File that uses this
397
+ # to create a different pattern for assigning to the :path attribute
398
+ # This requires further digging.
399
+ # The entire construct is somewhat strange, since resource checks if the method "title_patterns" is
400
+ # implemented (it seems it always is) - why take this more expensive regexp mathching route for all
401
+ # other types?
402
+ # @api private
403
+ #
206
404
  def self.title_patterns
207
405
  case key_attributes.length
208
406
  when 0; []
@@ -213,12 +411,29 @@ class Type
213
411
  end
214
412
  end
215
413
 
414
+ # Produces a _uniqueness_key_
415
+ # @todo Explain what a uniqueness_key is
416
+ # @return [Object] an object that is a _uniqueness_key_ for this object
417
+ #
216
418
  def uniqueness_key
217
419
  self.class.key_attributes.sort_by { |attribute_name| attribute_name.to_s }.map{ |attribute_name| self[attribute_name] }
218
420
  end
219
421
 
220
- # Create a new parameter. Requires a block and a name, stores it in the
221
- # @parameters array, and does some basic checking on it.
422
+ # Creates a new parameter.
423
+ # @param name [Symbol] the name of the parameter
424
+ # @param options [Hash] a hash with options.
425
+ # @option options [Class<inherits Puppet::Parameter>] :parent (Puppet::Parameter) the super class of this parameter
426
+ # @option options [Hash{String => Object}] :attributes a hash that is applied to the generated class
427
+ # by calling setter methods corresponding to this hash's keys/value pairs. This is done before the given
428
+ # block is evaluated.
429
+ # @option options [Boolean] :boolean (false) specifies if this is a boolean parameter
430
+ # @option options [Boolean] :namevar (false) specifies if this parameter is the namevar
431
+ # @option options [Symbol, Array<Symbol>] :required_features specifies required provider features by name
432
+ # @return [Class<inherits Puppet::Parameter>] the created parameter
433
+ # @yield [ ] a required block that is evaluated in the scope of the new parameter
434
+ # @api public
435
+ # @dsl type
436
+ #
222
437
  def self.newparam(name, options = {}, &block)
223
438
  options[:attributes] ||= {}
224
439
 
@@ -242,12 +457,24 @@ class Type
242
457
  param
243
458
  end
244
459
 
245
- # Create a new property. The first parameter must be the name of the property;
246
- # this is how users will refer to the property when creating new instances.
247
- # The second parameter is a hash of options; the options are:
248
- # * <tt>:parent</tt>: The parent class for the property. Defaults to Puppet::Property.
249
- # * <tt>:retrieve</tt>: The method to call on the provider or @parent object (if
250
- # the provider is not set) to retrieve the current value.
460
+ # Creates a new property.
461
+ # @param name [Symbol] the name of the property
462
+ # @param options [Hash] a hash with options.
463
+ # @option options [Symbol] :array_matching (:first) specifies how the current state is matched against
464
+ # the wanted state. Use `:first` if the property is single valued, and (`:all`) otherwise.
465
+ # @option options [Class<inherits Puppet::Property>] :parent (Puppet::Property) the super class of this property
466
+ # @option options [Hash{String => Object}] :attributes a hash that is applied to the generated class
467
+ # by calling setter methods corresponding to this hash's keys/value pairs. This is done before the given
468
+ # block is evaluated.
469
+ # @option options [Boolean] :boolean (false) specifies if this is a boolean parameter
470
+ # @option options [Symbol] :retrieve the method to call on the provider (or `parent` if `provider` is not set)
471
+ # to retrieve the current value of this property.
472
+ # @option options [Symbol, Array<Symbol>] :required_features specifies required provider features by name
473
+ # @return [Class<inherits Puppet::Property>] the created property
474
+ # @yield [ ] a required block that is evaluated in the scope of the new property
475
+ # @api public
476
+ # @dsl type
477
+ #
251
478
  def self.newproperty(name, options = {}, &block)
252
479
  name = name.intern
253
480
 
@@ -295,22 +522,25 @@ class Type
295
522
  @paramhash[param].doc
296
523
  end
297
524
 
298
- # Return the parameter names
525
+ # @return [Array<String>] Returns the parameter names
299
526
  def self.parameters
300
527
  return [] unless defined?(@parameters)
301
528
  @parameters.collect { |klass| klass.name }
302
529
  end
303
530
 
304
- # Find the parameter class associated with a given parameter name.
531
+ # @return [Puppet::Parameter] Returns the parameter class associated with the given parameter name.
305
532
  def self.paramclass(name)
306
533
  @paramhash[name]
307
534
  end
308
535
 
309
- # Return the property class associated with a name
536
+ # @return [Puppet::Property] Returns the property class ??? associated with the given property name
310
537
  def self.propertybyname(name)
311
538
  @validproperties[name]
312
539
  end
313
540
 
541
+ # Returns whether or not the given name is the name of a property, parameter or meta-parameter
542
+ # @return [Boolean] true if the given attribute name is the name of an existing property, parameter or meta-parameter
543
+ #
314
544
  def self.validattr?(name)
315
545
  name = name.intern
316
546
  return true if name == :name
@@ -323,37 +553,43 @@ class Type
323
553
  @validattrs[name]
324
554
  end
325
555
 
326
- # does the name reflect a valid property?
556
+ # @return [Boolean] Returns true if the given name is the name of an existing property
327
557
  def self.validproperty?(name)
328
558
  name = name.intern
329
559
  @validproperties.include?(name) && @validproperties[name]
330
560
  end
331
561
 
332
- # Return the list of validproperties
562
+ # @return [Array<Symbol>, {}] Returns a list of valid property names, or an empty hash if there are none.
563
+ # @todo An empty hash is returned if there are no defined parameters (not an empty array). This looks like
564
+ # a bug.
565
+ #
333
566
  def self.validproperties
334
567
  return {} unless defined?(@parameters)
335
568
 
336
569
  @validproperties.keys
337
570
  end
338
571
 
339
- # does the name reflect a valid parameter?
572
+ # @return [Boolean] Returns true if the given name is the name of an existing parameter
340
573
  def self.validparameter?(name)
341
574
  raise Puppet::DevError, "Class #{self} has not defined parameters" unless defined?(@parameters)
342
575
  !!(@paramhash.include?(name) or @@metaparamhash.include?(name))
343
576
  end
344
577
 
345
- # This is a forward-compatibility method - it's the validity interface we'll use in Puppet::Resource.
578
+ # (see validattr?)
579
+ # @note see comment in code - how should this be documented? Are some of the other query methods deprecated?
580
+ # (or should be).
581
+ # @comment This is a forward-compatibility method - it's the validity interface we'll use in Puppet::Resource.
346
582
  def self.valid_parameter?(name)
347
583
  validattr?(name)
348
584
  end
349
585
 
350
- # Are we deleting this resource?
586
+ # @return [Boolean] Returns true if the wanted state of the resoure is that it should be absent (i.e. to be deleted).
351
587
  def deleting?
352
588
  obj = @parameters[:ensure] and obj.should == :absent
353
589
  end
354
590
 
355
- # Create a new property if it is valid but doesn't exist
356
- # Returns: true if a new parameter was added, false otherwise
591
+ # Creates a new property value holder for the resource if it is valid and does not already exist
592
+ # @return [Boolean] true if a new parameter was added, false otherwise
357
593
  def add_property_parameter(prop_name)
358
594
  if self.class.validproperty?(prop_name) && !@parameters[prop_name]
359
595
  self.newattr(prop_name)
@@ -362,20 +598,24 @@ class Type
362
598
  false
363
599
  end
364
600
 
365
- #
366
- # The name_var is the key_attribute in the case that there is only one.
367
- #
601
+ # @return [Symbol, Boolean] Returns the name of the namevar if there is only one or false otherwise.
602
+ # @comment This is really convoluted and part of the support for multiple namevars (?).
603
+ # If there is only one namevar, the produced value is naturally this namevar, but if there are several?
604
+ # The logic caches the name of the namevar if it is a single name, but otherwise always
605
+ # calls key_attributes, and then caches the first if there was only one, otherwise it returns
606
+ # false and caches this (which is then subsequently returned as a cache hit).
607
+ #
368
608
  def name_var
369
609
  return @name_var_cache unless @name_var_cache.nil?
370
610
  key_attributes = self.class.key_attributes
371
611
  @name_var_cache = (key_attributes.length == 1) && key_attributes.first
372
612
  end
373
613
 
374
- # abstract accessing parameters and properties, and normalize access to
375
- # always be symbols, not strings This returns a value, not an object.
376
- # It returns the 'is' value, but you can also specifically return 'is' and
377
- # 'should' values using 'object.is(:property)' or
378
- # 'object.should(:property)'.
614
+ # Gets the 'is' (current state) value of a parameter or property by name.
615
+ # To explicitly get the 'is' value use `o.is(:name)`, and to get the 'should' value
616
+ # use `o.should(:name)`
617
+ # @param name [String] the name of the attribute to obtain the 'is' value for.
618
+ # @return [Object] current value of the given attribute
379
619
  def [](name)
380
620
  name = name.intern
381
621
  fail("Invalid parameter #{name}(#{name.inspect})") unless self.class.validattr?(name)
@@ -393,9 +633,9 @@ class Type
393
633
  end
394
634
  end
395
635
 
396
- # Abstract setting parameters and properties, and normalize
397
- # access to always be symbols, not strings. This sets the 'should'
398
- # value on properties, and otherwise just sets the appropriate parameter.
636
+ # Sets the 'should' (wanted state) value of a property, or the value of a parameter.
637
+ # @return
638
+ # @raise [Puppet::Error] if the setting of the value fails, or if the given name is nil.
399
639
  def []=(name,value)
400
640
  name = name.intern
401
641
 
@@ -422,8 +662,16 @@ class Type
422
662
  nil
423
663
  end
424
664
 
425
- # remove a property from the object; useful in testing or in cleanup
665
+ # Removes a property from the object; useful in testing or in cleanup
426
666
  # when an error has been encountered
667
+ # @todo Incomprehensible - the comment says "Remove a property", the code refers to @parameters, and
668
+ # the method parameter is called "attr" - What is it, property, parameter, both (i.e an attribute) or what?
669
+ # @todo Don't know what the attr is (name or Property/Parameter?). Guessing it is a String name...
670
+ # @todo Is it possible to delete a meta-parameter?
671
+ # @todo What does delete mean? Is it deleted from the type or is its value state 'is'/'should' deleted?
672
+ # @param attr [String] the attribute to delete from this object. WHAT IS THE TYPE?
673
+ # @raise [Puppet::DecError] when an attempt is made to delete an attribute that does not exists.
674
+ #
427
675
  def delete(attr)
428
676
  attr = attr.intern
429
677
  if @parameters.has_key?(attr)
@@ -433,7 +681,11 @@ class Type
433
681
  end
434
682
  end
435
683
 
436
- # iterate across the existing properties
684
+ # Iterates over the existing properties.
685
+ # @todo what does this mean? As opposed to iterating over the "non existing properties" ??? Is it an
686
+ # iteration over those properties that have state? CONFUSING.
687
+ # @yieldparam property [Puppet::Property] each property
688
+ # @return [void]
437
689
  def eachproperty
438
690
  # properties is a private method
439
691
  properties.each { |property|
@@ -441,21 +693,38 @@ class Type
441
693
  }
442
694
  end
443
695
 
444
- # Create a transaction event. Called by Transaction or by
445
- # a property.
696
+ # Creates a transaction event.
697
+ # Called by Transaction or by a property.
698
+ # Merges the given options with the options `:resource`, `:file`, `:line`, and `:tags`, initialized from
699
+ # values in this object. For possible options to pass (if any ????) see {Puppet::Transaction::Event}.
700
+ # @todo Needs a better explanation "Why should I care who is calling this method?", What do I need to know
701
+ # about events and how they work? Where can I read about them?
702
+ # @param options [Hash] options merged with a fixed set of options defined by this method, passed on to {Puppet::Transaction::Event}.
703
+ # @return [Puppet::Transaction::Event] the created event
446
704
  def event(options = {})
447
705
  Puppet::Transaction::Event.new({:resource => self, :file => file, :line => line, :tags => tags}.merge(options))
448
706
  end
449
707
 
450
- # retrieve the 'should' value for a specified property
708
+ # @return [Object, nil] Returns the 'should' (wanted state) value for a specified property, or nil if the
709
+ # given attribute name is not a property (i.e. if it is a parameter, meta-parameter, or does not exist).
451
710
  def should(name)
452
711
  name = name.intern
453
712
  (prop = @parameters[name] and prop.is_a?(Puppet::Property)) ? prop.should : nil
454
713
  end
455
714
 
456
- # Create the actual attribute instance. Requires either the attribute
457
- # name or class as the first argument, then an optional hash of
715
+ # Creates an instance to represent/manage the given attribute.
716
+ # Requires either the attribute name or class as the first argument, then an optional hash of
458
717
  # attributes to set during initialization.
718
+ # @todo The original comment is just wrong - the method does not accept a hash of options
719
+ # @todo Detective work required; this method interacts with provider to ask if it supports a parameter of
720
+ # the given class. it then returns the parameter if it exists, otherwise creates a parameter
721
+ # with its :resource => self.
722
+ # @overload newattr(name)
723
+ # @param name [String] Unclear what name is (probably a symbol) - Needs investigation.
724
+ # @overload newattr(klass)
725
+ # @param klass [Class] a class supported as an attribute class - Needs clarification what that means.
726
+ # @return [???] Probably returns a new instance of the class - Needs investigation.
727
+ #
459
728
  def newattr(name)
460
729
  if name.is_a?(Class)
461
730
  klass = name
@@ -477,31 +746,46 @@ class Type
477
746
  @parameters[name] = klass.new(:resource => self)
478
747
  end
479
748
 
480
- # return the value of a parameter
749
+ # Returns the value of this object's parameter given by name
750
+ # @param name [String] the name of the parameter
751
+ # @return [Object] the value
481
752
  def parameter(name)
482
753
  @parameters[name.to_sym]
483
754
  end
484
755
 
756
+ # Returns a shallow copy of this object's hash of parameters.
757
+ # @todo Add that this is not only "parameters", but also "properties" and "meta-parameters" ?
758
+ # Changes to the contained parameters will have an effect on the parameters of this type, but changes to
759
+ # the returned hash does not.
760
+ # @return [Hash{String => Puppet:???Parameter}] a new hash being a shallow copy of the parameters map name to parameter
485
761
  def parameters
486
762
  @parameters.dup
487
763
  end
488
764
 
489
- # Is the named property defined?
765
+ # @return [Boolean] Returns whether the property given by name is defined or not.
766
+ # @todo what does it mean to be defined?
490
767
  def propertydefined?(name)
491
768
  name = name.intern unless name.is_a? Symbol
492
769
  @parameters.include?(name)
493
770
  end
494
771
 
495
- # Return an actual property instance by name; to return the value, use 'resource[param]'
496
- # LAK:NOTE(20081028) Since the 'parameter' method is now a superset of this method,
497
- # this one should probably go away at some point.
772
+ # Returns a {Puppet::Property} instance by name.
773
+ # To return the value, use 'resource[param]'
774
+ # @todo LAK:NOTE(20081028) Since the 'parameter' method is now a superset of this method,
775
+ # this one should probably go away at some point. - Does this mean it should be deprecated ?
776
+ # @return [Puppet::Property] the property with the given name, or nil if not a property or does not exist.
498
777
  def property(name)
499
778
  (obj = @parameters[name.intern] and obj.is_a?(Puppet::Property)) ? obj : nil
500
779
  end
501
780
 
502
- # For any parameters or properties that have defaults and have not yet been
503
- # set, set them now. This method can be handed a list of attributes,
504
- # and if so it will only set defaults for those attributes.
781
+ # @todo comment says "For any parameters or properties that have defaults and have not yet been
782
+ # set, set them now. This method can be handed a list of attributes,
783
+ # and if so it will only set defaults for those attributes."
784
+ # @todo Needs a better explanation, and investigation about the claim an array can be passed (it is passed
785
+ # to self.class.attrclass to produce a class on which a check is made if it has a method class :default (does
786
+ # not seem to support an array...
787
+ # @return [void]
788
+ #
505
789
  def set_default(attr)
506
790
  return unless klass = self.class.attrclass(attr)
507
791
  return unless klass.method_defined?(:default)
@@ -516,7 +800,14 @@ class Type
516
800
  end
517
801
  end
518
802
 
519
- # Convert our object to a hash. This just includes properties.
803
+ # @todo the comment says: "Convert our object to a hash. This just includes properties."
804
+ # @todo this is confused, again it is the @parameters instance variable that is consulted, and
805
+ # each value is copied - does it contain "properties" and "parameters" or both? Does it contain
806
+ # meta-parameters?
807
+ #
808
+ # @return [Hash{ ??? => ??? }] a hash of WHAT?. The hash is a shallow copy, any changes to the
809
+ # objects returned in this hash will be reflected in the original resource having these attributes.
810
+ #
520
811
  def to_hash
521
812
  rethash = {}
522
813
 
@@ -527,31 +818,47 @@ class Type
527
818
  rethash
528
819
  end
529
820
 
821
+ # @return [String] the name of this object's class
822
+ # @todo Would that be "file" for the "File" resource type? of "File" or something else?
823
+ #
530
824
  def type
531
825
  self.class.name
532
826
  end
533
827
 
534
- # Return a specific value for an attribute.
828
+ # @todo Comment says "Return a specific value for an attribute.", as opposed to what "An upspecific value"???
829
+ # @todo is this the 'is' or the 'should' value?
830
+ # @todo why is the return restricted to things that respond to :value? (Only non structural basic data types
831
+ # supported?
832
+ #
833
+ # @return [Object, nil] the value of the attribute having the given name, or nil if the given name is not
834
+ # an attribute, or the referenced attribute does not respond to `:value`.
535
835
  def value(name)
536
836
  name = name.intern
537
837
 
538
838
  (obj = @parameters[name] and obj.respond_to?(:value)) ? obj.value : nil
539
839
  end
540
840
 
841
+ # @todo What is this used for? Needs a better explanation.
842
+ # @return [???] the version of the catalog or 0 if there is no catalog.
541
843
  def version
542
844
  return 0 unless catalog
543
845
  catalog.version
544
846
  end
545
847
 
546
- # Return all of the property objects, in the order specified in the
547
- # class.
848
+ # @return [Array<Puppet::Property>] Returns all of the property objects, in the order specified in the
849
+ # class.
850
+ # @todo "what does the 'order specified in the class' mean? The order the properties where added in the
851
+ # ruby file adding a new type with new properties?
852
+ #
548
853
  def properties
549
854
  self.class.properties.collect { |prop| @parameters[prop.name] }.compact
550
855
  end
551
856
 
552
- # Is this type's name isomorphic with the object? That is, if the
553
- # name conflicts, does it necessarily mean that the objects conflict?
857
+ # Returns true if the type's notion of name is the identity of a resource.
858
+ # See the overview of this class for a longer explanation of the concept _isomorphism_.
554
859
  # Defaults to true.
860
+ #
861
+ # @return [Boolan] true, if this type's name is isomorphic with the object
555
862
  def self.isomorphic?
556
863
  if defined?(@isomorphic)
557
864
  return @isomorphic
@@ -560,14 +867,18 @@ class Type
560
867
  end
561
868
  end
562
869
 
870
+ # @todo check that this gets documentation (it is at the class level as well as instance).
871
+ # (see isomorphic?)
563
872
  def isomorphic?
564
873
  self.class.isomorphic?
565
874
  end
566
875
 
567
- # is the instance a managed instance? A 'yes' here means that
568
- # the instance was created from the language, vs. being created
569
- # in order resolve other questions, such as finding a package
570
- # in a list
876
+ # Returns true if the instance is a managed instance.
877
+ # A 'yes' here means that the instance was created from the language, vs. being created
878
+ # in order resolve other questions, such as finding a package in a list.
879
+ # @note An object that is managed always stays managed, but an object that is not managed
880
+ # may become managed later in its lifecycle.
881
+ # @return [Boolean] true if the object is managed
571
882
  def managed?
572
883
  # Once an object is managed, it always stays managed; but an object
573
884
  # that is listed as unmanaged might become managed later in the process,
@@ -590,12 +901,25 @@ class Type
590
901
  ###############################
591
902
  # Code related to the container behaviour.
592
903
 
904
+
905
+ # Returns true if the search should be done in depth-first order.
906
+ # This implementation always returns false.
907
+ # @todo What is this used for?
908
+ #
909
+ # @return [Boolean] true if the search should be done in depth first order.
910
+ #
593
911
  def depthfirst?
594
912
  false
595
913
  end
596
914
 
597
- # Remove an object. The argument determines whether the object's
598
- # subscriptions get eliminated, too.
915
+ # Removes this object (FROM WHERE?)
916
+ # @todo removes if from where?
917
+ # @overload remove(rmdeps)
918
+ # @deprecated Use remove()
919
+ # @param rmdeps [Boolean] intended to indicate that all subscriptions should also be removed, ignored.
920
+ # @overload remove()
921
+ # @return [void]
922
+ #
599
923
  def remove(rmdeps = true)
600
924
  # This is hackish (mmm, cut and paste), but it works for now, and it's
601
925
  # better than warnings.
@@ -616,19 +940,32 @@ class Type
616
940
  ###############################
617
941
  # Code related to evaluating the resources.
618
942
 
943
+
944
+ # Returns the ancestors - WHAT?
945
+ # This implementation always returns an empty list.
946
+ # @todo WHAT IS THIS ?
947
+ # @return [Array<???>] returns a list of ancestors.
619
948
  def ancestors
620
949
  []
621
950
  end
622
951
 
623
- # Flush the provider, if it supports it. This is called by the
624
- # transaction.
952
+ # Flushes the provider if supported by the provider, else no action.
953
+ # This is called by the transaction.
954
+ # @todo What does Flushing the provider mean? Why is it interesting to know that this is
955
+ # called by the transaction? (It is not explained anywhere what a transaction is).
956
+ #
957
+ # @return [???, nil] WHAT DOES IT RETURN? GUESS IS VOID
625
958
  def flush
626
959
  self.provider.flush if self.provider and self.provider.respond_to?(:flush)
627
960
  end
628
961
 
629
- # if all contained objects are in sync, then we're in sync
630
- # FIXME I don't think this is used on the type instances any more,
631
- # it's really only used for testing
962
+ # Returns true if all contained objects are in sync.
963
+ # @todo "contained in what?" in the given "in" parameter?
964
+ #
965
+ # @todo deal with the comment _"FIXME I don't think this is used on the type instances any more,
966
+ # it's really only used for testing"_
967
+ # @return [Boolean] true if in sync, false otherwise.
968
+ #
632
969
  def insync?(is)
633
970
  insync = true
634
971
 
@@ -662,7 +999,12 @@ class Type
662
999
  insync
663
1000
  end
664
1001
 
665
- # retrieve the current value of all contained properties
1002
+ # Retrieves the current value of all contained properties.
1003
+ # Parameters and meta-parameters are not included in the result.
1004
+ # @todo As oposed to all non contained properties? How is this different than any of the other
1005
+ # methods that also "gets" properties/parameters/etc. ?
1006
+ # @return [Array<Object>] array of all property values (mix of types)
1007
+ # @raise [fail???] if there is a provider and it is not suitable for the host this is evaluated for.
666
1008
  def retrieve
667
1009
  fail "Provider #{provider.class.name} is not functional on this host" if self.provider.is_a?(Puppet::Provider) and ! provider.class.suitable?
668
1010
 
@@ -689,15 +1031,22 @@ class Type
689
1031
  result
690
1032
  end
691
1033
 
1034
+ # ???
1035
+ # @todo what does this do? It seems to create a new Resource based on the result of calling #retrieve
1036
+ # and if that is a Hash, else this method produces nil.
1037
+ # @return [Puppet::Resource, nil] a new Resource, or nil, if this object did not produce a Hash as the
1038
+ # result from #retrieve
1039
+ #
692
1040
  def retrieve_resource
693
1041
  resource = retrieve
694
1042
  resource = Resource.new(type, title, :parameters => resource) if resource.is_a? Hash
695
1043
  resource
696
1044
  end
697
1045
 
698
- # Get a hash of the current properties. Returns a hash with
699
- # the actual property instance as the key and the current value
700
- # as the, um, value.
1046
+ # Returns a hash of the current properties and their values.
1047
+ # If a resource is absent, it's value is the symbol `:absent`
1048
+ # @return [Hash{Puppet::Property => Object}] mapping of property instance to its value
1049
+ #
701
1050
  def currentpropvalues
702
1051
  # It's important to use the 'properties' method here, as it follows the order
703
1052
  # in which they're defined in the class. It also guarantees that 'ensure'
@@ -719,7 +1068,8 @@ class Type
719
1068
  end
720
1069
  end
721
1070
 
722
- # Are we running in noop mode?
1071
+ # Returns the `noop` run mode status of this.
1072
+ # @return [Boolean] true if running in noop mode.
723
1073
  def noop?
724
1074
  # If we're not a host_config, we're almost certainly part of
725
1075
  # Settings, and we want to ignore 'noop'
@@ -732,11 +1082,15 @@ class Type
732
1082
  end
733
1083
  end
734
1084
 
1085
+ # (see #noop?)
735
1086
  def noop
736
1087
  noop?
737
1088
  end
738
1089
 
739
- # Retrieve all known instances. Either requires providers or must be overridden.
1090
+ # Retrieves all known instances.
1091
+ # @todo Retrieves them from where? Known to whom?
1092
+ # Either requires providers or must be overridden.
1093
+ # @raise [Puppet::DevError] when there are no providers and the implementation has not overridded this method.
740
1094
  def self.instances
741
1095
  raise Puppet::DevError, "#{self.name} has no providers and has not overridden 'instances'" if provider_hash.empty?
742
1096
 
@@ -766,7 +1120,10 @@ class Type
766
1120
  end.flatten.compact
767
1121
  end
768
1122
 
769
- # Return a list of one suitable provider per source, with the default provider first.
1123
+ # Returns a list of one suitable provider per source, with the default provider first.
1124
+ # @todo Needs better explanation; what does "source" mean in this context?
1125
+ # @return [Array<Puppet::Provider>] list of providers
1126
+ #
770
1127
  def self.providers_by_source
771
1128
  # Put the default provider first (can be nil), then the rest of the suitable providers.
772
1129
  sources = []
@@ -779,7 +1136,11 @@ class Type
779
1136
  end.compact
780
1137
  end
781
1138
 
782
- # Convert a simple hash into a Resource instance.
1139
+ # Converts a simple hash into a Resource instance.
1140
+ # @todo as opposed to a complex hash? Other raised exceptions?
1141
+ # @param [Hash{Symbol, String => Object}] resource attribute to value map to initialize the created resource from
1142
+ # @return [Puppet::Resource] the resource created from the hash
1143
+ # @raise [Puppet::Error] if a title is missing in the given hash
783
1144
  def self.hash2resource(hash)
784
1145
  hash = hash.inject({}) { |result, ary| result[ary[0].to_sym] = ary[1]; result }
785
1146
 
@@ -804,7 +1165,10 @@ class Type
804
1165
  resource
805
1166
  end
806
1167
 
807
- # Create the path for logging and such.
1168
+ # Creates the path for logging and such.
1169
+ # @todo "and such?", what?
1170
+ # @api private
1171
+ #
808
1172
  def pathbuilder
809
1173
  if p = parent
810
1174
  [p.pathbuilder, self.ref].flatten
@@ -814,7 +1178,7 @@ class Type
814
1178
  end
815
1179
 
816
1180
  ###############################
817
- # Add all of the meta parameters.
1181
+ # Add all of the meta-parameters.
818
1182
  newmetaparam(:noop) do
819
1183
  desc "Boolean flag indicating whether work should actually
820
1184
  be done."
@@ -1009,6 +1373,10 @@ class Type
1009
1373
  end
1010
1374
  end
1011
1375
 
1376
+ # RelationshipMetaparam is an implementation supporting the meta-parameters `:require`, `:subscribe`,
1377
+ # `:notify`, and `:before`.
1378
+ #
1379
+ #
1012
1380
  class RelationshipMetaparam < Puppet::Parameter
1013
1381
  class << self
1014
1382
  attr_accessor :direction, :events, :callback, :subclasses
@@ -1020,6 +1388,7 @@ class Type
1020
1388
  @subclasses << sub
1021
1389
  end
1022
1390
 
1391
+ # @return [Array<Puppet::Resource>] turns attribute value(s) into list of resources
1023
1392
  def munge(references)
1024
1393
  references = [references] unless references.is_a?(Array)
1025
1394
  references.collect do |ref|
@@ -1031,6 +1400,10 @@ class Type
1031
1400
  end
1032
1401
  end
1033
1402
 
1403
+ # Checks each reference to assert that what it references exists in the catalog.
1404
+ #
1405
+ # @raise [???fail] if the referenced resource can not be found
1406
+ # @return [void]
1034
1407
  def validate_relationship
1035
1408
  @value.each do |ref|
1036
1409
  unless @resource.catalog.resource(ref.to_s)
@@ -1040,14 +1413,19 @@ class Type
1040
1413
  end
1041
1414
  end
1042
1415
 
1043
- # Create edges from each of our relationships. :in
1044
- # relationships are specified by the event-receivers, and :out
1045
- # relationships are specified by the event generator. This
1046
- # way 'source' and 'target' are consistent terms in both edges
1047
- # and events -- that is, an event targets edges whose source matches
1048
- # the event's source. The direction of the relationship determines
1416
+ # Creates edges for all relationships.
1417
+ # The `:in` relationships are specified by the event-receivers, and `:out`
1418
+ # relationships are specified by the event generator.
1419
+ # @todo references to "event-receivers" and "event generator" means in this context - are those just
1420
+ # the resources at the two ends of the relationship?
1421
+ # This way 'source' and 'target' are consistent terms in both edges
1422
+ # and events, i.e. an event targets edges whose source matches
1423
+ # the event's source. The direction of the relationship determines
1049
1424
  # which resource is applied first and which resource is considered
1050
1425
  # to be the event generator.
1426
+ # @return [Array<Puppet::Relationship>]
1427
+ # @raise [???fail] when a reference can not be resolved
1428
+ #
1051
1429
  def to_edges
1052
1430
  @value.collect do |reference|
1053
1431
  reference.catalog = resource.catalog
@@ -1086,6 +1464,8 @@ class Type
1086
1464
  end
1087
1465
  end
1088
1466
 
1467
+ # @todo document this, have no clue what this does... it retuns "RelationshipMetaparam.subclasses"
1468
+ #
1089
1469
  def self.relationship_params
1090
1470
  RelationshipMetaparam.subclasses
1091
1471
  end
@@ -1236,15 +1616,33 @@ class Type
1236
1616
  # Add the feature handling module.
1237
1617
  extend Puppet::Util::ProviderFeatures
1238
1618
 
1619
+ # The provider that has been selected for the instance of the resource type.
1620
+ # @return [Puppet::Provider,nil] the selected provider or nil, if none has been selected
1621
+ #
1239
1622
  attr_reader :provider
1240
1623
 
1241
1624
  # the Type class attribute accessors
1242
1625
  class << self
1626
+ # The loader of providers to use when loading providers from disk.
1627
+ # Although it looks like this attribute provides a way to operate with different loaders of
1628
+ # providers that is not the case; the attribute is written when a new type is created,
1629
+ # and should not be changed thereafter.
1630
+ # @api private
1631
+ #
1243
1632
  attr_accessor :providerloader
1633
+
1634
+ # @todo Don't know if this is a name, or a reference to a Provider instance (now marked up as an instance
1635
+ # of Provider.
1636
+ # @return [Puppet::Provider, nil] The default provider for this type, or nil if non is defines
1637
+ #
1244
1638
  attr_writer :defaultprovider
1245
1639
  end
1246
1640
 
1247
- # Find the default provider.
1641
+ # The default provider, or the most suitable provider if no default provider was set.
1642
+ # @note a warning will be issued if no default provider has been configured and a search for the most
1643
+ # suitable provider returns more than one equally suitable provider.
1644
+ # @return [Puppet::Provider, nil] the default or most suitable provider, or nil if no provider was found
1645
+ #
1248
1646
  def self.defaultprovider
1249
1647
  return @defaultprovider if @defaultprovider
1250
1648
 
@@ -1267,16 +1665,26 @@ class Type
1267
1665
  @defaultprovider = defaults.shift unless defaults.empty?
1268
1666
  end
1269
1667
 
1668
+ # @return [Hash{??? => Puppet::Provider}] Returns a hash of WHAT EXACTLY for the given type
1669
+ # @todo what goes into this hash?
1270
1670
  def self.provider_hash_by_type(type)
1271
1671
  @provider_hashes ||= {}
1272
1672
  @provider_hashes[type] ||= {}
1273
1673
  end
1274
1674
 
1675
+ # @return [Hash{ ??? => Puppet::Provider}] Returns a hash of WHAT EXACTLY for this type.
1676
+ # @see provider_hash_by_type method to get the same for some other type
1275
1677
  def self.provider_hash
1276
1678
  Puppet::Type.provider_hash_by_type(self.name)
1277
1679
  end
1278
1680
 
1279
- # Retrieve a provider by name.
1681
+ # Returns the provider having the given name.
1682
+ # This will load a provider if it is not already loaded. The returned provider is the first found provider
1683
+ # having the given name, where "first found" semantics is defined by the {providerloader} in use.
1684
+ #
1685
+ # @param name [String] the name of the provider to get
1686
+ # @return [Puppet::Provider, nil] the found provider, or nil if no provider of the given name was found
1687
+ #
1280
1688
  def self.provider(name)
1281
1689
  name = name.intern
1282
1690
 
@@ -1285,19 +1693,41 @@ class Type
1285
1693
  provider_hash[name]
1286
1694
  end
1287
1695
 
1288
- # Just list all of the providers.
1696
+ # Returns a list of loaded providers by name.
1697
+ # This method will not load/search for available providers.
1698
+ # @return [Array<String>] list of loaded provider names
1699
+ #
1289
1700
  def self.providers
1290
1701
  provider_hash.keys
1291
1702
  end
1292
1703
 
1704
+ # Returns true if the given name is a reference to a provider and if this is a suitable provider for
1705
+ # this type.
1706
+ # @todo How does the provider know if it is suitable for the type? Is it just suitable for the platform/
1707
+ # environment where this method is executing?
1708
+ # @param name [String] the name of the provider for which validity is checked
1709
+ # @return [Boolean] true if the given name references a provider that is suitable
1710
+ #
1293
1711
  def self.validprovider?(name)
1294
1712
  name = name.intern
1295
1713
 
1296
1714
  (provider_hash.has_key?(name) && provider_hash[name].suitable?)
1297
1715
  end
1298
1716
 
1299
- # Create a new provider of a type. This method must be called
1300
- # directly on the type that it's implementing.
1717
+ # Creates a new provider of a type.
1718
+ # This method must be called directly on the type that it's implementing.
1719
+ # @todo Fix Confusing Explanations!
1720
+ # Is this a new provider of a Type (metatype), or a provider of an instance of Type (a resource), or
1721
+ # a Provider (the implementation of a Type's behavior). CONFUSED. It calls magically named methods like
1722
+ # "providify" ...
1723
+ # @param name [String, Symbol] the name of the WHAT? provider? type?
1724
+ # @param options [Hash{Symbol => Object}] a hash of options, used by this method, and passed on to {#genclass}, (see
1725
+ # it for additional options to pass).
1726
+ # @option options [Puppet::Provider] :parent the parent provider (what is this?)
1727
+ # @option options [Puppet::Type] :resource_type the resource type, defaults to this type if unspecified
1728
+ # @return [Puppet::Provider] a provider ???
1729
+ # @raise [Puppet::DevError] when the parent provider could not be found.
1730
+ #
1301
1731
  def self.provide(name, options = {}, &block)
1302
1732
  name = name.intern
1303
1733
 
@@ -1339,8 +1769,9 @@ class Type
1339
1769
  provider
1340
1770
  end
1341
1771
 
1342
- # Make sure we have a :provider parameter defined. Only gets called if there
1343
- # are providers.
1772
+ # Ensures there is a `:provider` parameter defined.
1773
+ # Should only be called if there are providers.
1774
+ # @return [void]
1344
1775
  def self.providify
1345
1776
  return if @paramhash.has_key? :provider
1346
1777
 
@@ -1358,10 +1789,14 @@ class Type
1358
1789
  # This is so we can refer back to the type to get a list of
1359
1790
  # providers for documentation.
1360
1791
  class << self
1792
+ # The reference to a parent type for the parameter `:provider` used to get a list of
1793
+ # providers for documentation purposes.
1794
+ #
1361
1795
  attr_accessor :parenttype
1362
1796
  end
1363
1797
 
1364
- # We need to add documentation for each provider.
1798
+ # Provides the ability to add documentation to a provider.
1799
+ #
1365
1800
  def self.doc
1366
1801
  # Since we're mixing @doc with text from other sources, we must normalize
1367
1802
  # its indentation with scrub. But we don't need to manually scrub the
@@ -1373,6 +1808,8 @@ class Type
1373
1808
  }.join
1374
1809
  end
1375
1810
 
1811
+ # @todo this does what? where and how?
1812
+ # @returns [String] the name of the provider
1376
1813
  defaultto {
1377
1814
  prov = @resource.class.defaultprovider
1378
1815
  prov.name if prov
@@ -1401,6 +1838,9 @@ class Type
1401
1838
  end.parenttype = self
1402
1839
  end
1403
1840
 
1841
+ # @todo this needs a better explanation
1842
+ # Removes the implementation class of a given provider.
1843
+ # @return [Object] returns what {Puppet::Util::ClassGen#rmclass} returns
1404
1844
  def self.unprovide(name)
1405
1845
  if @defaultprovider and @defaultprovider.name == name
1406
1846
  @defaultprovider = nil
@@ -1409,7 +1849,12 @@ class Type
1409
1849
  rmclass(name, :hash => provider_hash, :prefix => "Provider")
1410
1850
  end
1411
1851
 
1412
- # Return an array of all of the suitable providers.
1852
+ # Returns a list of suitable providers for the given type.
1853
+ # A call to this method will load all providers if not already loaded and ask each if it is
1854
+ # suitable - those that are are included in the result.
1855
+ # @note This method also does some special processing which rejects a provider named `:fake` (for testing purposes).
1856
+ # @return [Array<Puppet::Provider>] Returns an array of all suitable providers.
1857
+ #
1413
1858
  def self.suitableprovider
1414
1859
  providerloader.loadall if provider_hash.empty?
1415
1860
  provider_hash.find_all { |name, provider|
@@ -1419,6 +1864,9 @@ class Type
1419
1864
  }.reject { |p| p.name == :fake } # For testing
1420
1865
  end
1421
1866
 
1867
+ # @return [Boolean] Returns true if this is something else than a `:provider`, or if it
1868
+ # is a provider and it is suitable, or if there is a default provider. Otherwise, false is returned.
1869
+ #
1422
1870
  def suitable?
1423
1871
  # If we don't use providers, then we consider it suitable.
1424
1872
  return true unless self.class.paramclass(:provider)
@@ -1437,6 +1885,16 @@ class Type
1437
1885
  false
1438
1886
  end
1439
1887
 
1888
+ # Sets the provider to the given provider/name.
1889
+ # @overload provider=(name)
1890
+ # Sets the provider to the result of resolving the name to an instance of Provider.
1891
+ # @param name [String] the name of the provider
1892
+ # @overload provider=(provider)
1893
+ # Sets the provider to the given instances of Provider.
1894
+ # @param provider [Puppet::Provider] the provider to set
1895
+ # @return [Puppet::Provider] the provider set
1896
+ # @raise [ArgumentError] if the provider could not be found/resolved.
1897
+ #
1440
1898
  def provider=(name)
1441
1899
  if name.is_a?(Puppet::Provider)
1442
1900
  @provider = name
@@ -1451,15 +1909,30 @@ class Type
1451
1909
  ###############################
1452
1910
  # All of the relationship code.
1453
1911
 
1454
- # Specify a block for generating a list of objects to autorequire. This
1455
- # makes it so that you don't have to manually specify things that you clearly
1456
- # require.
1912
+
1913
+ # Adds a block producing a single name (or list of names) of the given resource type name to autorequire.
1914
+ # @example Autorequire the files File['foo', 'bar']
1915
+ # autorequire( 'file', {|| ['foo', 'bar'] })
1916
+ #
1917
+ # @todo original = _"Specify a block for generating a list of objects to autorequire.
1918
+ # This makes it so that you don't have to manually specify things that you clearly require."_
1919
+ # @param name [String] the name of a type of which one or several resources should be autorequired e.g. "file"
1920
+ # @yield [ ] a block returning list of names of given type to auto require
1921
+ # @yieldreturn [String, Array<String>] one or several resource names for the named type
1922
+ # @return [void]
1923
+ # @dsl type
1924
+ # @api public
1925
+ #
1457
1926
  def self.autorequire(name, &block)
1458
1927
  @autorequires ||= {}
1459
1928
  @autorequires[name] = block
1460
1929
  end
1461
1930
 
1462
- # Yield each of those autorequires in turn, yo.
1931
+ # Provides iteration over added auto-requirements (see {autorequire}).
1932
+ # @yieldparam type [String] the name of the type to autoriquire an instance of
1933
+ # @yieldparam block [Proc] a block producing one or several dependencies to auto require (see {autorequire}).
1934
+ # @yieldreturn [void]
1935
+ # @return [void]
1463
1936
  def self.eachautorequire
1464
1937
  @autorequires ||= {}
1465
1938
  @autorequires.each { |type, block|
@@ -1467,8 +1940,13 @@ class Type
1467
1940
  }
1468
1941
  end
1469
1942
 
1470
- # Figure out of there are any objects we can automatically add as
1471
- # dependencies.
1943
+ # Adds dependencies to the catalog from added autorequirements.
1944
+ # See {autorequire} for how to add an auto-requirement.
1945
+ # @todo needs details - see the param rel_catalog, and type of this param
1946
+ # @param rel_catalog [Puppet::Catalog, nil] the catalog to add dependencies to. Defaults to the
1947
+ # catalog (TODO: what is the type of the catalog).
1948
+ # @raise [Puppet::DevError] if there is no catalog
1949
+ #
1472
1950
  def autorequire(rel_catalog = nil)
1473
1951
  rel_catalog ||= catalog
1474
1952
  raise(Puppet::DevError, "You cannot add relationships without a catalog") unless rel_catalog
@@ -1499,7 +1977,12 @@ class Type
1499
1977
  reqs
1500
1978
  end
1501
1979
 
1502
- # Build the dependencies associated with an individual object.
1980
+ # Builds the dependencies associated with an individual object.
1981
+ # @todo Which object is the "individual object", as opposed to "object as a group?" or should it simply
1982
+ # be "this object" as in "this resource" ?
1983
+ # @todo Does this method "build dependencies" or "build what it depends on" ... CONFUSING
1984
+ #
1985
+ # @return [Array<???>] list of WHAT? resources? edges?
1503
1986
  def builddepends
1504
1987
  # Handle the requires
1505
1988
  self.class.relationship_params.collect do |klass|
@@ -1509,21 +1992,40 @@ class Type
1509
1992
  end.flatten.reject { |r| r.nil? }
1510
1993
  end
1511
1994
 
1512
- # Define the initial list of tags.
1995
+ # Sets the initial list of tags...
1996
+ # @todo The initial list of tags, that ... that what?
1997
+ # @return [void] ???
1513
1998
  def tags=(list)
1514
1999
  tag(self.class.name)
1515
2000
  tag(*list)
1516
2001
  end
1517
2002
 
1518
- # Types (which map to resources in the languages) are entirely composed of
1519
- # attribute value pairs. Generally, Puppet calls any of these things an
1520
- # 'attribute', but these attributes always take one of three specific
1521
- # forms: parameters, metaparams, or properties.
1522
-
1523
- # In naming methods, I have tried to consistently name the method so
1524
- # that it is clear whether it operates on all attributes (thus has 'attr' in
1525
- # the method name, or whether it operates on a specific type of attributes.
2003
+ # @comment - these two comments were floating around here, and turned up as documentation
2004
+ # for the attribute "title", much to my surprise and amusement. Clearly these comments
2005
+ # are orphaned ... I think they can just be removed as what they say should be covered
2006
+ # by the now added yardoc. <irony>(Yo! to quote some of the other actual awsome specific comments applicable
2007
+ # to objects called from elsewhere, or not. ;-)</irony>
2008
+ #
2009
+ # @comment Types (which map to resources in the languages) are entirely composed of
2010
+ # attribute value pairs. Generally, Puppet calls any of these things an
2011
+ # 'attribute', but these attributes always take one of three specific
2012
+ # forms: parameters, metaparams, or properties.
2013
+
2014
+ # @comment In naming methods, I have tried to consistently name the method so
2015
+ # that it is clear whether it operates on all attributes (thus has 'attr' in
2016
+ # the method name, or whether it operates on a specific type of attributes.
2017
+
2018
+
2019
+ # The title attribute of WHAT ???
2020
+ # @todo Figure out what this is the title attribute of (it appears on line 1926 currently).
2021
+ # @return [String] the title
1526
2022
  attr_writer :title
2023
+
2024
+ # The noop attribute of WHAT ??? does WHAT???
2025
+ # @todo Figure out what this is the noop attribute of (it appears on line 1931 currently).
2026
+ # @return [???] the noop WHAT ??? (mode? if so of what, or noop for an instance of the type, or for all
2027
+ # instances of a type, or for what???
2028
+ #
1527
2029
  attr_writer :noop
1528
2030
 
1529
2031
  include Enumerable
@@ -1532,9 +2034,14 @@ class Type
1532
2034
 
1533
2035
  public
1534
2036
 
1535
- # the Type class attribute accessors
2037
+ # The Type class attribute accessors
1536
2038
  class << self
2039
+ # @return [String] the name of the resource type; e.g., "File"
2040
+ #
1537
2041
  attr_reader :name
2042
+
2043
+ # @return [Boolean] true if the type should send itself a refresh event on change.
2044
+ #
1538
2045
  attr_accessor :self_refresh
1539
2046
  include Enumerable, Puppet::Util::ClassGen
1540
2047
  include Puppet::MetaType::Manager
@@ -1543,7 +2050,9 @@ class Type
1543
2050
  include Puppet::Util::Logging
1544
2051
  end
1545
2052
 
1546
- # all of the variables that must be initialized for each subclass
2053
+ # Initializes all of the variables that must be initialized for each subclass.
2054
+ # @todo Does the explanation make sense?
2055
+ # @return [void]
1547
2056
  def self.initvars
1548
2057
  # all of the instances of this class
1549
2058
  @objects = Hash.new
@@ -1571,6 +2080,11 @@ class Type
1571
2080
 
1572
2081
  end
1573
2082
 
2083
+ # Returns the name of this type (if specified) or the parent type #to_s.
2084
+ # The returned name is on the form "Puppet::Type::<name>", where the first letter of name is
2085
+ # capitalized.
2086
+ # @return [String] the fully qualified name Puppet::Type::<name> where the first letter of name is captialized
2087
+ #
1574
2088
  def self.to_s
1575
2089
  if defined?(@name)
1576
2090
  "Puppet::Type::#{@name.to_s.capitalize}"
@@ -1579,26 +2093,42 @@ class Type
1579
2093
  end
1580
2094
  end
1581
2095
 
1582
- # Create a block to validate that our object is set up entirely. This will
1583
- # be run before the object is operated on.
2096
+ # Creates a `validate` method that is used to validate a resource before it is operated on.
2097
+ # The validation should raise exceptions if the validation finds errors. (It is not recommended to
2098
+ # issue warnings as this typically just ends up in a logfile - you should fail if a validation fails).
2099
+ # The easiest way to raise an appropriate exception is to call the method {Puppet::Util::Errors.fail} with
2100
+ # the message as an argument.
2101
+ #
2102
+ # @yield [ ] a required block called with self set to the instance of a Type class representing a resource.
2103
+ # @return [void]
2104
+ # @dsl type
2105
+ # @api public
2106
+ #
1584
2107
  def self.validate(&block)
1585
2108
  define_method(:validate, &block)
1586
2109
  #@validate = block
1587
2110
  end
1588
2111
 
1589
- # Origin information.
1590
- attr_accessor :file, :line
2112
+ # @return [String] The file from which this type originates from
2113
+ attr_accessor :file
2114
+
2115
+ # @return [Integer] The line in {#file} from which this type originates from
2116
+ attr_accessor :line
1591
2117
 
1592
- # The catalog that this resource is stored in.
2118
+ # @todo what does this mean "this resource" (sounds like this if for an instance of the type, not the meta Type),
2119
+ # but not sure if this is about the catalog where the meta Type is included)
2120
+ # @return [??? TODO] The catalog that this resource is stored in.
1593
2121
  attr_accessor :catalog
1594
2122
 
1595
- # is the resource exported
2123
+ # @return [Boolean] Flag indicating if this type is exported
1596
2124
  attr_accessor :exported
1597
2125
 
1598
- # is the resource virtual (it should not :-))
2126
+ # @return [Boolean] Flag indicating if the type is virtual (it should not be).
1599
2127
  attr_accessor :virtual
1600
2128
 
1601
- # create a log at specified level
2129
+ # Creates a log entry with the given message at the log level specified by the parameter `loglevel`
2130
+ # @return [void]
2131
+ #
1602
2132
  def log(msg)
1603
2133
 
1604
2134
  Puppet::Util::Log.create(
@@ -1616,9 +2146,24 @@ class Type
1616
2146
 
1617
2147
  public
1618
2148
 
2149
+ # @return [Hash] hash of parameters originally defined
2150
+ # @api private
1619
2151
  attr_reader :original_parameters
1620
2152
 
1621
- # initialize the type instance
2153
+ # Creates an instance of Type from a hash or a {Puppet::Resource}.
2154
+ # @todo Unclear if this is a new Type or a new instance of a given type (the initialization ends
2155
+ # with calling validate - which seems like validation of an instance of a given type, not a new
2156
+ # meta type.
2157
+ #
2158
+ # @todo Explain what the Hash and Resource are. There seems to be two different types of
2159
+ # resources; one that causes the title to be set to resource.title, and one that
2160
+ # causes the title to be resource.ref ("for components") - what is a component?
2161
+ #
2162
+ # @overaload initialize(hsh)
2163
+ # @param hsh [Hash]
2164
+ # @overload initialize(resource)
2165
+ # @param resource [Puppet:Resource]
2166
+ #
1622
2167
  def initialize(resource)
1623
2168
  resource = self.class.hash2resource(resource) unless resource.is_a?(Puppet::Resource)
1624
2169
 
@@ -1655,12 +2200,32 @@ class Type
1655
2200
 
1656
2201
  private
1657
2202
 
1658
- # Set our resource's name.
2203
+ # Sets the name of the resource from a hash containing a mapping of `name_var` to value.
2204
+ # Sets the value of the property/parameter appointed by the `name_var` (if it is defined). The value set is
2205
+ # given by the corresponding entry in the given hash - e.g. if name_var appoints the name `:path` the value
2206
+ # of `:path` is set to the value at the key `:path` in the given hash. As a side effect this key/value is then
2207
+ # removed from the given hash.
2208
+ #
2209
+ # @note This method mutates the given hash by removing the entry with a key equal to the value
2210
+ # returned from name_var!
2211
+ # @param hash [Hash] a hash of what
2212
+ # @return [void]
1659
2213
  def set_name(hash)
1660
2214
  self[name_var] = hash.delete(name_var) if name_var
1661
2215
  end
1662
2216
 
1663
- # Set all of the parameters from a hash, in the appropriate order.
2217
+ # Sets parameters from the given hash.
2218
+ # Values are set in _attribute order_ i.e. higher priority attributes before others, otherwise in
2219
+ # the order they were specified (as opposed to just setting them in the order they happen to appear in
2220
+ # when iterating over the given hash).
2221
+ #
2222
+ # Attributes that are not included in the given hash are set to their default value.
2223
+ #
2224
+ # @todo Is this description accurate? Is "ensure" an example of such a higher priority attribute?
2225
+ # @return [void]
2226
+ # @raise [Puppet::DevError] when impossible to set the value due to some problem
2227
+ # @raise [ArgumentError, TypeError, Puppet::Error] when faulty arguments have been passed
2228
+ #
1664
2229
  def set_parameters(hash)
1665
2230
  # Use the order provided by allattrs, but add in any
1666
2231
  # extra attributes from the resource so we get failures
@@ -1691,7 +2256,14 @@ class Type
1691
2256
 
1692
2257
  public
1693
2258
 
1694
- # Set up all of our autorequires.
2259
+ # Finishes any outstanding processing.
2260
+ # This method should be called as a final step in setup,
2261
+ # to allow the parameters that have associated auto-require needs to be processed.
2262
+ #
2263
+ # @todo what is the expected sequence here - who is responsible for calling this? When?
2264
+ # Is the returned type correct?
2265
+ # @return [Array<Puppet::Parameter>] the validated list/set of attributes
2266
+ #
1695
2267
  def finish
1696
2268
  # Make sure all of our relationships are valid. Again, must be done
1697
2269
  # when the entire catalog is instantiated.
@@ -1702,13 +2274,22 @@ class Type
1702
2274
  end.flatten.reject { |r| r.nil? }
1703
2275
  end
1704
2276
 
1705
- # For now, leave the 'name' method functioning like it used to. Once 'title'
1706
- # works everywhere, I'll switch it.
2277
+ # @comment For now, leave the 'name' method functioning like it used to. Once 'title'
2278
+ # works everywhere, I'll switch it.
2279
+ # Returns the resource's name
2280
+ # @todo There is a comment in source that this is not quite the same as ':title' and that a switch should
2281
+ # be made...
2282
+ # @return [String] the name of a resource
1707
2283
  def name
1708
2284
  self[:name]
1709
2285
  end
1710
2286
 
1711
- # Look up our parent in the catalog, if we have one.
2287
+ # Returns the parent of this in the catalog.
2288
+ # In case of an erroneous catalog where multiple parents have been produced, the first found (non deterministic)
2289
+ # parent is returned.
2290
+ # @return [???, nil] WHAT (which types can be the parent of a resource in a catalog?), or nil if there
2291
+ # is no catalog.
2292
+ #
1712
2293
  def parent
1713
2294
  return nil unless catalog
1714
2295
 
@@ -1724,24 +2305,36 @@ class Type
1724
2305
  @parent
1725
2306
  end
1726
2307
 
1727
- # Return the "type[name]" style reference.
2308
+ # Returns a reference to this as a string in "Type[name]" format.
2309
+ # @return [String] a reference to this object on the form 'Type[name]'
2310
+ #
1728
2311
  def ref
1729
2312
  # memoizing this is worthwhile ~ 3 percent of calls are the "first time
1730
2313
  # around" in an average run of Puppet. --daniel 2012-07-17
1731
2314
  @ref ||= "#{self.class.name.to_s.capitalize}[#{self.title}]"
1732
2315
  end
1733
2316
 
2317
+ # (see self_refresh)
2318
+ # @todo check that meaningful yardoc is produced - this method delegates to "self.class.self_refresh"
2319
+ # @return [Boolean] - ??? returns true when ... what?
2320
+ #
1734
2321
  def self_refresh?
1735
2322
  self.class.self_refresh
1736
2323
  end
1737
2324
 
1738
- # Mark that we're purging.
2325
+ # Marks the object as "being purged".
2326
+ # This method is used by transactions to forbid deletion when there are dependencies.
2327
+ # @todo what does this mean; "mark that we are purging" (purging what from where). How to use/when?
2328
+ # Is this internal API in transactions?
2329
+ # @see purging?
1739
2330
  def purging
1740
2331
  @purging = true
1741
2332
  end
1742
2333
 
1743
- # Is this resource being purged? Used by transactions to forbid
1744
- # deletion when there are dependencies.
2334
+ # Returns whether this resource is being purged or not.
2335
+ # This method is used by transactions to forbid deletion when there are dependencies.
2336
+ # @return [Boolean] the current "purging" state
2337
+ #
1745
2338
  def purging?
1746
2339
  if defined?(@purging)
1747
2340
  @purging
@@ -1750,8 +2343,15 @@ class Type
1750
2343
  end
1751
2344
  end
1752
2345
 
1753
- # Retrieve the title of an object. If no title was set separately,
1754
- # then use the object's name.
2346
+ # Returns the title of this object, or it's name if title was not explicetly set.
2347
+ # If the title is not already set, it will be computed by looking up the {#name_var} and using
2348
+ # that value as the title.
2349
+ # @todo it is somewhat confusing that if the name_var is a valid parameter, it is assumed to
2350
+ # be the name_var called :name, but if it is a property, it uses the name_var.
2351
+ # It is further confusing as Type in some respects supports multiple namevars.
2352
+ #
2353
+ # @return [String] Returns the title of this object, or it's name if title was not explicetly set.
2354
+ # @raise [??? devfail] if title is not set, and name_var can not be found.
1755
2355
  def title
1756
2356
  unless @title
1757
2357
  if self.class.validparameter?(name_var)
@@ -1766,11 +2366,16 @@ class Type
1766
2366
  @title
1767
2367
  end
1768
2368
 
1769
- # convert to a string
2369
+ # Produces a reference to this in reference format.
2370
+ # @see #ref
2371
+ #
1770
2372
  def to_s
1771
2373
  self.ref
1772
2374
  end
1773
2375
 
2376
+ # @todo What to resource? Which one of the resource forms is prroduced? returned here?
2377
+ # @return [??? Resource] a resource that WHAT???
2378
+ #
1774
2379
  def to_resource
1775
2380
  resource = self.retrieve_resource
1776
2381
  resource.tag(*self.tags)
@@ -1787,13 +2392,21 @@ class Type
1787
2392
  resource
1788
2393
  end
1789
2394
 
2395
+ # @return [Boolean] Returns whether the resource is virtual or not
1790
2396
  def virtual?; !!@virtual; end
2397
+ # @return [Boolean] Returns whether the resource is exported or not
1791
2398
  def exported?; !!@exported; end
1792
2399
 
2400
+ # @return [Boolean] Returns whether the resource is applicable to `:device`
2401
+ # @todo Explain what this means
2402
+ # @api private
1793
2403
  def appliable_to_device?
1794
2404
  self.class.can_apply_to(:device)
1795
2405
  end
1796
2406
 
2407
+ # @return [Boolean] Returns whether the resource is applicable to `:host`
2408
+ # @todo Explain what this means
2409
+ # @api private
1797
2410
  def appliable_to_host?
1798
2411
  self.class.can_apply_to(:host)
1799
2412
  end