puppet 4.3.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (560) hide show
  1. checksums.yaml +7 -0
  2. data/COMMITTERS.md +2 -2
  3. data/CONTRIBUTING.md +6 -6
  4. data/LICENSE +1 -1
  5. data/README.md +8 -9
  6. data/conf/auth.conf +2 -2
  7. data/ext/README.environment +1 -1
  8. data/ext/build_defaults.yaml +1 -1
  9. data/ext/debian/README.source +1 -1
  10. data/ext/debian/control +1 -1
  11. data/ext/debian/copyright +4 -4
  12. data/ext/debian/puppetmaster.README.debian +11 -9
  13. data/ext/emacs/puppet-mode.el +1 -1
  14. data/ext/envpuppet +2 -2
  15. data/ext/ips/puppetagent.xml +1 -1
  16. data/ext/ips/puppetmaster.xml +1 -1
  17. data/ext/project_data.yaml +8 -0
  18. data/ext/puppet-test +3 -3
  19. data/ext/rack/example-passenger-vhost.conf +1 -1
  20. data/ext/redhat/puppet.spec.erb +2 -2
  21. data/ext/regexp_nodes/regexp_nodes.rb +1 -1
  22. data/ext/solaris/pkginfo +1 -1
  23. data/ext/solaris/smf/puppet.xml +1 -1
  24. data/ext/suse/puppet.spec +2 -2
  25. data/ext/upload_facts.rb +1 -1
  26. data/ext/windows/puppet_interactive.bat +6 -0
  27. data/ext/windows/puppet_shell.bat +9 -0
  28. data/ext/windows/run_puppet_interactive.bat +9 -0
  29. data/ext/yaml_nodes.rb +1 -1
  30. data/install.rb +30 -20
  31. data/lib/hiera/scope.rb +1 -1
  32. data/lib/puppet/agent.rb +1 -1
  33. data/lib/puppet/application/agent.rb +4 -2
  34. data/lib/puppet/application/apply.rb +7 -4
  35. data/lib/puppet/application/cert.rb +1 -1
  36. data/lib/puppet/application/device.rb +1 -1
  37. data/lib/puppet/application/filebucket.rb +1 -1
  38. data/lib/puppet/application/inspect.rb +1 -1
  39. data/lib/puppet/application/lookup.rb +45 -47
  40. data/lib/puppet/application/master.rb +2 -2
  41. data/lib/puppet/application/resource.rb +1 -1
  42. data/lib/puppet/configurer.rb +100 -22
  43. data/lib/puppet/data_providers/hiera_config.rb +28 -3
  44. data/lib/puppet/data_providers/hiera_interpolate.rb +30 -15
  45. data/lib/puppet/data_providers/hiera_support.rb +1 -1
  46. data/lib/puppet/data_providers/json_data_provider_factory.rb +2 -2
  47. data/lib/puppet/data_providers/lookup_adapter.rb +73 -26
  48. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -2
  49. data/lib/puppet/defaults.rb +69 -22
  50. data/lib/puppet/environments.rb +3 -1
  51. data/lib/puppet/face/config.rb +1 -1
  52. data/lib/puppet/face/epp.rb +1 -1
  53. data/lib/puppet/face/help/man.erb +1 -1
  54. data/lib/puppet/face/module/install.rb +6 -6
  55. data/lib/puppet/face/parser.rb +12 -9
  56. data/lib/puppet/face/status.rb +2 -1
  57. data/lib/puppet/feature/cfpropertylist.rb +3 -0
  58. data/lib/puppet/feature/telnet.rb +9 -0
  59. data/lib/puppet/file_serving/http_metadata.rb +46 -0
  60. data/lib/puppet/file_serving/metadata.rb +18 -2
  61. data/lib/puppet/file_serving/terminus_selector.rb +2 -0
  62. data/lib/puppet/file_system/file_impl.rb +2 -2
  63. data/lib/puppet/file_system/memory_impl.rb +1 -1
  64. data/lib/puppet/file_system/uniquefile.rb +1 -1
  65. data/lib/puppet/file_system.rb +2 -2
  66. data/lib/puppet/forge/repository.rb +1 -31
  67. data/lib/puppet/forge.rb +1 -1
  68. data/lib/puppet/functions/assert_type.rb +9 -9
  69. data/lib/puppet/functions/each.rb +5 -13
  70. data/lib/puppet/functions/filter.rb +5 -14
  71. data/lib/puppet/functions/lookup.rb +126 -150
  72. data/lib/puppet/functions/map.rb +6 -14
  73. data/lib/puppet/functions/match.rb +1 -0
  74. data/lib/puppet/functions/reduce.rb +5 -13
  75. data/lib/puppet/functions/reverse_each.rb +82 -0
  76. data/lib/puppet/functions/scanf.rb +15 -18
  77. data/lib/puppet/functions/slice.rb +22 -36
  78. data/lib/puppet/functions/split.rb +2 -2
  79. data/lib/puppet/functions/step.rb +88 -0
  80. data/lib/puppet/functions/type.rb +70 -0
  81. data/lib/puppet/functions.rb +45 -6
  82. data/lib/puppet/graph/rb_tree_map.rb +1 -1
  83. data/lib/puppet/indirector/catalog/compiler.rb +188 -5
  84. data/lib/puppet/indirector/facts/facter.rb +2 -13
  85. data/lib/puppet/indirector/file_content/http.rb +15 -0
  86. data/lib/puppet/indirector/file_metadata/http.rb +27 -0
  87. data/lib/puppet/indirector/generic_http.rb +16 -0
  88. data/lib/puppet/indirector/hiera.rb +3 -1
  89. data/lib/puppet/indirector/indirection.rb +6 -2
  90. data/lib/puppet/indirector/json.rb +2 -2
  91. data/lib/puppet/indirector/node/exec.rb +1 -1
  92. data/lib/puppet/indirector/node/ldap.rb +1 -1
  93. data/lib/puppet/indirector/rest.rb +2 -1
  94. data/lib/puppet/info_service/class_information_service.rb +13 -12
  95. data/lib/puppet/loaders.rb +1 -0
  96. data/lib/puppet/module.rb +6 -2
  97. data/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +9 -2
  98. data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +1 -1
  99. data/lib/puppet/module_tool/skeleton/templates/generator/tests/init.pp.erb +2 -2
  100. data/lib/puppet/module_tool/tar/mini.rb +3 -3
  101. data/lib/puppet/network/http/pool.rb +9 -0
  102. data/lib/puppet/node/environment.rb +11 -2
  103. data/lib/puppet/node.rb +11 -2
  104. data/lib/puppet/parser/ast/pops_bridge.rb +19 -22
  105. data/lib/puppet/parser/compiler.rb +4 -11
  106. data/lib/puppet/parser/environment_compiler.rb +0 -1
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
  108. data/lib/puppet/parser/functions/inline_template.rb +1 -1
  109. data/lib/puppet/parser/functions/lookup.rb +128 -149
  110. data/lib/puppet/parser/functions/map.rb +1 -1
  111. data/lib/puppet/parser/functions/match.rb +1 -0
  112. data/lib/puppet/parser/functions/scanf.rb +15 -26
  113. data/lib/puppet/parser/functions/slice.rb +17 -24
  114. data/lib/puppet/parser/functions/split.rb +1 -1
  115. data/lib/puppet/parser/functions.rb +28 -16
  116. data/lib/puppet/parser/resource.rb +19 -17
  117. data/lib/puppet/parser/scope.rb +176 -5
  118. data/lib/puppet/plugins/data_providers/data_provider.rb +56 -14
  119. data/lib/puppet/pops/adaptable.rb +4 -1
  120. data/lib/puppet/pops/adapters.rb +80 -12
  121. data/lib/puppet/pops/binder/binder.rb +21 -17
  122. data/lib/puppet/pops/binder/binder_issues.rb +8 -6
  123. data/lib/puppet/pops/binder/bindings_checker.rb +12 -8
  124. data/lib/puppet/pops/binder/bindings_composer.rb +16 -12
  125. data/lib/puppet/pops/binder/bindings_factory.rb +108 -104
  126. data/lib/puppet/pops/binder/bindings_model.rb +49 -47
  127. data/lib/puppet/pops/binder/config/diagnostic_producer.rb +10 -6
  128. data/lib/puppet/pops/binder/injector.rb +53 -48
  129. data/lib/puppet/pops/binder/key_factory.rb +10 -6
  130. data/lib/puppet/pops/binder/producers.rb +67 -62
  131. data/lib/puppet/pops/evaluator/access_operator.rb +98 -96
  132. data/lib/puppet/pops/evaluator/closure.rb +122 -106
  133. data/lib/puppet/pops/evaluator/collector_transformer.rb +34 -14
  134. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +0 -1
  135. data/lib/puppet/pops/evaluator/compare_operator.rb +13 -9
  136. data/lib/puppet/pops/evaluator/epp_evaluator.rb +9 -8
  137. data/lib/puppet/pops/evaluator/evaluator_impl.rb +78 -76
  138. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +85 -0
  139. data/lib/puppet/pops/evaluator/relationship_operator.rb +13 -11
  140. data/lib/puppet/pops/evaluator/runtime3_converter.rb +5 -0
  141. data/lib/puppet/pops/evaluator/runtime3_support.rb +47 -42
  142. data/lib/puppet/pops/functions/function.rb +6 -2
  143. data/lib/puppet/pops/issue_reporter.rb +6 -4
  144. data/lib/puppet/pops/issues.rb +50 -11
  145. data/lib/puppet/pops/loader/base_loader.rb +1 -1
  146. data/lib/puppet/pops/loader/loader.rb +1 -1
  147. data/lib/puppet/pops/loader/loader_paths.rb +15 -0
  148. data/lib/puppet/pops/loader/module_loaders.rb +17 -13
  149. data/lib/puppet/pops/loader/puppet_function_instantiator.rb +18 -13
  150. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +16 -3
  151. data/lib/puppet/pops/loader/type_definition_instantiator.rb +55 -0
  152. data/lib/puppet/pops/loaders.rb +51 -9
  153. data/lib/puppet/pops/lookup/explainer.rb +73 -3
  154. data/lib/puppet/pops/lookup/invocation.rb +21 -19
  155. data/lib/puppet/pops/lookup.rb +17 -12
  156. data/lib/puppet/pops/merge_strategy.rb +16 -19
  157. data/lib/puppet/pops/model/factory.rb +179 -157
  158. data/lib/puppet/pops/model/model.rb +17 -8
  159. data/lib/puppet/pops/model/model_label_provider.rb +14 -7
  160. data/lib/puppet/pops/model/model_meta.rb +17 -0
  161. data/lib/puppet/pops/model/model_tree_dumper.rb +8 -0
  162. data/lib/puppet/pops/parser/egrammar.ra +38 -14
  163. data/lib/puppet/pops/parser/eparser.rb +1353 -1276
  164. data/lib/puppet/pops/parser/epp_support.rb +11 -7
  165. data/lib/puppet/pops/parser/evaluating_parser.rb +17 -13
  166. data/lib/puppet/pops/parser/heredoc_support.rb +15 -11
  167. data/lib/puppet/pops/parser/lexer2.rb +428 -403
  168. data/lib/puppet/pops/parser/lexer_support.rb +85 -7
  169. data/lib/puppet/pops/parser/locator.rb +21 -0
  170. data/lib/puppet/pops/parser/parser_support.rb +19 -16
  171. data/lib/puppet/pops/parser/slurp_support.rb +16 -8
  172. data/lib/puppet/pops/types/class_loader.rb +23 -19
  173. data/lib/puppet/pops/types/enumeration.rb +9 -26
  174. data/lib/puppet/pops/types/iterable.rb +308 -0
  175. data/lib/puppet/pops/types/recursion_guard.rb +82 -0
  176. data/lib/puppet/pops/types/type_acceptor.rb +25 -0
  177. data/lib/puppet/pops/types/type_asserter.rb +10 -9
  178. data/lib/puppet/pops/types/type_calculator.rb +140 -387
  179. data/lib/puppet/pops/types/type_factory.rb +91 -57
  180. data/lib/puppet/pops/types/type_formatter.rb +334 -0
  181. data/lib/puppet/pops/types/type_mismatch_describer.rb +226 -59
  182. data/lib/puppet/pops/types/type_parser.rb +159 -112
  183. data/lib/puppet/pops/types/types.rb +2057 -1253
  184. data/lib/puppet/pops/utils.rb +11 -10
  185. data/lib/puppet/pops/validation/checker4_0.rb +115 -63
  186. data/lib/puppet/pops/validation/validator_factory_4_0.rb +8 -4
  187. data/lib/puppet/pops/validation.rb +11 -9
  188. data/lib/puppet/pops.rb +0 -8
  189. data/lib/puppet/provider/aixobject.rb +1 -1
  190. data/lib/puppet/provider/augeas/augeas.rb +1 -1
  191. data/lib/puppet/provider/cron/crontab.rb +1 -1
  192. data/lib/puppet/provider/exec/windows.rb +1 -1
  193. data/lib/puppet/provider/group/windows_adsi.rb +2 -2
  194. data/lib/puppet/provider/macauthorization/macauthorization.rb +10 -9
  195. data/lib/puppet/provider/nameservice/directoryservice.rb +35 -50
  196. data/lib/puppet/provider/package/appdmg.rb +3 -2
  197. data/lib/puppet/provider/package/dnf.rb +1 -1
  198. data/lib/puppet/provider/package/pip.rb +16 -9
  199. data/lib/puppet/provider/package/pip3.rb +1 -1
  200. data/lib/puppet/provider/package/pkg.rb +1 -1
  201. data/lib/puppet/provider/package/pkgdmg.rb +3 -2
  202. data/lib/puppet/provider/package/pkgng.rb +13 -4
  203. data/lib/puppet/provider/package/rpm.rb +0 -1
  204. data/lib/puppet/provider/package/windows.rb +1 -1
  205. data/lib/puppet/provider/package/yum.rb +2 -2
  206. data/lib/puppet/provider/package/zypper.rb +19 -0
  207. data/lib/puppet/provider/service/debian.rb +7 -20
  208. data/lib/puppet/provider/service/init.rb +7 -0
  209. data/lib/puppet/provider/service/launchd.rb +6 -12
  210. data/lib/puppet/provider/service/systemd.rb +9 -2
  211. data/lib/puppet/provider/sshkey/parsed.rb +1 -1
  212. data/lib/puppet/provider/user/aix.rb +1 -1
  213. data/lib/puppet/provider/user/directoryservice.rb +33 -58
  214. data/lib/puppet/provider/user/windows_adsi.rb +2 -2
  215. data/lib/puppet/provider/yumrepo/inifile.rb +6 -3
  216. data/lib/puppet/provider/zfs/zfs.rb +1 -1
  217. data/lib/puppet/provider/zpool/zpool.rb +1 -1
  218. data/lib/puppet/reference/configuration.rb +1 -1
  219. data/lib/puppet/reference/providers.rb +1 -1
  220. data/lib/puppet/resource/capability_finder.rb +20 -13
  221. data/lib/puppet/resource/catalog.rb +60 -3
  222. data/lib/puppet/resource/status.rb +11 -2
  223. data/lib/puppet/resource/type.rb +33 -42
  224. data/lib/puppet/resource.rb +15 -12
  225. data/lib/puppet/settings/config_file.rb +1 -1
  226. data/lib/puppet/settings/environment_conf.rb +13 -5
  227. data/lib/puppet/settings.rb +1 -1
  228. data/lib/puppet/ssl/certificate_factory.rb +3 -3
  229. data/lib/puppet/ssl/certificate_request.rb +4 -4
  230. data/lib/puppet/ssl/certificate_signer.rb +1 -1
  231. data/lib/puppet/ssl/validator/default_validator.rb +1 -1
  232. data/lib/puppet/test/test_helper.rb +16 -4
  233. data/lib/puppet/transaction/additional_resource_generator.rb +23 -5
  234. data/lib/puppet/transaction/report.rb +31 -1
  235. data/lib/puppet/transaction/resource_harness.rb +0 -25
  236. data/lib/puppet/transaction.rb +15 -2
  237. data/lib/puppet/type/augeas.rb +1 -1
  238. data/lib/puppet/type/cron.rb +12 -12
  239. data/lib/puppet/type/file/checksum_value.rb +53 -0
  240. data/lib/puppet/type/file/content.rb +26 -111
  241. data/lib/puppet/type/file/data_sync.rb +84 -0
  242. data/lib/puppet/type/file/ensure.rb +17 -14
  243. data/lib/puppet/type/file/selcontext.rb +1 -1
  244. data/lib/puppet/type/file/source.rb +103 -18
  245. data/lib/puppet/type/file.rb +91 -39
  246. data/lib/puppet/type/filebucket.rb +1 -1
  247. data/lib/puppet/type/group.rb +6 -2
  248. data/lib/puppet/type/interface.rb +8 -3
  249. data/lib/puppet/type/macauthorization.rb +1 -1
  250. data/lib/puppet/type/package.rb +6 -0
  251. data/lib/puppet/type/schedule.rb +1 -1
  252. data/lib/puppet/type/stage.rb +1 -1
  253. data/lib/puppet/type/user.rb +19 -17
  254. data/lib/puppet/type/yumrepo.rb +20 -0
  255. data/lib/puppet/type.rb +11 -11
  256. data/lib/puppet/util/autoload.rb +16 -11
  257. data/lib/puppet/util/checksums.rb +74 -31
  258. data/lib/puppet/util/execution.rb +1 -1
  259. data/lib/puppet/util/http_proxy.rb +72 -0
  260. data/lib/puppet/util/log.rb +2 -0
  261. data/lib/puppet/util/logging.rb +43 -1
  262. data/lib/puppet/util/monkey_patches.rb +2 -2
  263. data/lib/puppet/util/multi_match.rb +51 -0
  264. data/lib/puppet/util/network_device/cisco/device.rb +10 -2
  265. data/lib/puppet/util/network_device/cisco/interface.rb +21 -8
  266. data/lib/puppet/util/network_device/transport/ssh.rb +7 -3
  267. data/lib/puppet/util/network_device/transport/telnet.rb +39 -36
  268. data/lib/puppet/util/plist.rb +130 -0
  269. data/lib/puppet/util/resource_template.rb +1 -1
  270. data/lib/puppet/util/run_mode.rb +2 -2
  271. data/lib/puppet/util/skip_tags.rb +9 -0
  272. data/lib/puppet/util/windows/access_control_entry.rb +1 -1
  273. data/lib/puppet/util/windows/access_control_list.rb +3 -3
  274. data/lib/puppet/util/windows/adsi.rb +65 -28
  275. data/lib/puppet/util/windows/api_types.rb +24 -18
  276. data/lib/puppet/util/windows/com.rb +3 -3
  277. data/lib/puppet/util/windows/error.rb +1 -1
  278. data/lib/puppet/util/windows/file.rb +8 -8
  279. data/lib/puppet/util/windows/principal.rb +190 -0
  280. data/lib/puppet/util/windows/process.rb +78 -11
  281. data/lib/puppet/util/windows/registry.rb +22 -16
  282. data/lib/puppet/util/windows/root_certs.rb +5 -5
  283. data/lib/puppet/util/windows/security.rb +33 -35
  284. data/lib/puppet/util/windows/security_descriptor.rb +1 -1
  285. data/lib/puppet/util/windows/sid.rb +84 -15
  286. data/lib/puppet/util/windows/taskscheduler.rb +15 -15
  287. data/lib/puppet/util/windows/user.rb +10 -10
  288. data/lib/puppet/util/windows.rb +4 -0
  289. data/lib/puppet/util.rb +109 -22
  290. data/lib/puppet/vendor/deep_merge/deep_merge.gemspec +1 -1
  291. data/lib/puppet/vendor/pathspec/LICENSE +2 -2
  292. data/lib/puppet/vendor/pathspec/README.md +1 -1
  293. data/lib/puppet/vendor/rgen/README.rdoc +1 -1
  294. data/lib/puppet/vendor/semantic/lib/semantic/dependency/module_release.rb +14 -0
  295. data/lib/puppet/version.rb +1 -1
  296. data/lib/puppet.rb +17 -0
  297. data/lib/semver.rb +17 -1
  298. data/man/man5/puppet.conf.5 +12 -12
  299. data/man/man8/extlookup2hiera.8 +1 -1
  300. data/man/man8/puppet-agent.8 +2 -2
  301. data/man/man8/puppet-apply.8 +2 -2
  302. data/man/man8/puppet-ca.8 +2 -2
  303. data/man/man8/puppet-catalog.8 +2 -2
  304. data/man/man8/puppet-cert.8 +2 -2
  305. data/man/man8/puppet-certificate.8 +2 -2
  306. data/man/man8/puppet-certificate_request.8 +2 -2
  307. data/man/man8/puppet-certificate_revocation_list.8 +2 -2
  308. data/man/man8/puppet-config.8 +3 -3
  309. data/man/man8/puppet-describe.8 +1 -1
  310. data/man/man8/puppet-device.8 +1 -1
  311. data/man/man8/puppet-doc.8 +1 -1
  312. data/man/man8/puppet-epp.8 +2 -2
  313. data/man/man8/puppet-facts.8 +2 -2
  314. data/man/man8/puppet-file.8 +2 -2
  315. data/man/man8/puppet-filebucket.8 +2 -2
  316. data/man/man8/puppet-help.8 +2 -2
  317. data/man/man8/puppet-inspect.8 +2 -2
  318. data/man/man8/puppet-key.8 +2 -2
  319. data/man/man8/puppet-man.8 +2 -2
  320. data/man/man8/puppet-master.8 +2 -2
  321. data/man/man8/puppet-module.8 +9 -9
  322. data/man/man8/puppet-node.8 +2 -2
  323. data/man/man8/puppet-parser.8 +2 -2
  324. data/man/man8/puppet-plugin.8 +2 -2
  325. data/man/man8/puppet-report.8 +2 -2
  326. data/man/man8/puppet-resource.8 +2 -2
  327. data/man/man8/puppet-resource_type.8 +2 -2
  328. data/man/man8/puppet-status.8 +3 -3
  329. data/man/man8/puppet.8 +1 -1
  330. data/spec/fixtures/module.tar.gz +0 -0
  331. data/spec/fixtures/unit/application/environments/production/data/common.yaml +4 -0
  332. data/spec/fixtures/unit/application/environments/production/manifests/site.pp +1 -0
  333. data/spec/fixtures/unit/application/environments/puppet_func_provider/environment.conf +1 -0
  334. data/spec/fixtures/unit/application/environments/puppet_func_provider/functions/data.pp +10 -0
  335. data/spec/fixtures/unit/application/environments/puppet_func_provider/manifests/site.pp +1 -0
  336. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/common.yaml +4 -0
  337. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/specific.yaml +4 -0
  338. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/hiera.yaml +7 -0
  339. data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/common.yaml +4 -0
  340. data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/specific.yaml +4 -0
  341. data/spec/fixtures/unit/data_providers/environments/hiera_modules/environment.conf +2 -0
  342. data/spec/fixtures/unit/data_providers/environments/hiera_modules/hiera.yaml +7 -0
  343. data/spec/fixtures/unit/data_providers/environments/hiera_modules/manifests/site.pp +1 -0
  344. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/data/common.yaml +6 -0
  345. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/hiera.yaml +5 -0
  346. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/manifests/init.pp +2 -0
  347. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/metadata.json +9 -0
  348. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/data/common.yaml +4 -0
  349. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/hiera.yaml +5 -0
  350. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/manifests/init.pp +3 -0
  351. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/metadata.json +9 -0
  352. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bad_data/lib/puppet/functions/bad_data/data.rb +1 -0
  353. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bad_data/manifests/init.pp +0 -1
  354. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/data/empty.json +0 -0
  355. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/hiera.yaml +5 -0
  356. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/manifests/init.pp +2 -0
  357. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/metadata.json +9 -0
  358. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/data/empty.yaml +1 -0
  359. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/hiera.yaml +5 -0
  360. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/manifests/init.pp +2 -0
  361. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/metadata.json +9 -0
  362. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/data/first.json +2 -1
  363. data/spec/fixtures/unit/module/trailing-comma.json +1 -1
  364. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/functions/usee_puppet.pp +3 -0
  365. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/functions/usee/usee_ruby.rb +6 -0
  366. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/manifests/init.pp +8 -0
  367. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/types/zero.pp +1 -0
  368. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee2/lib/puppet/functions/usee2/callee.rb +5 -0
  369. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet.pp +5 -0
  370. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet_init.pp +5 -0
  371. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_ruby.pp +5 -0
  372. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/caller2.rb +5 -0
  373. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet.rb +5 -0
  374. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet_init.rb +5 -0
  375. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_ruby.rb +5 -0
  376. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +81 -0
  377. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/metadata.json +2 -1
  378. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/types/withuseeone.pp +1 -0
  379. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/types/withuseezero.pp +1 -0
  380. data/spec/fixtures/unit/provider/package/yum/yum-check-update-broken-notices.txt +187 -0
  381. data/spec/fixtures/unit/provider/sshkey/parsed/sample_with_blank_lines +8 -0
  382. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_fetch_if_not_on_the_local_disk.yml +205 -0
  383. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_not_update_if_content_on_disk_is_up-to-date.yml +213 -0
  384. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_update_if_content_differs_on_disk.yml +213 -0
  385. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_mtime_is_older_on_disk.yml +205 -0
  386. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_no_header_specified.yml +197 -0
  387. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_not_on_the_local_disk.yml +205 -0
  388. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_not_update_if_mtime_is_newer_on_disk.yml +205 -0
  389. data/spec/integration/defaults_spec.rb +14 -2
  390. data/spec/integration/file_system/uniquefile_spec.rb +29 -0
  391. data/spec/integration/module_tool/tar/mini_spec.rb +28 -0
  392. data/spec/integration/node/environment_spec.rb +13 -0
  393. data/spec/integration/parser/collection_spec.rb +8 -0
  394. data/spec/integration/parser/dynamic_scoping_spec.rb +67 -0
  395. data/spec/integration/parser/parameter_defaults_spec.rb +336 -0
  396. data/spec/integration/parser/undef_param_spec.rb +8 -0
  397. data/spec/integration/provider/yumrepo_spec.rb +1 -1
  398. data/spec/integration/test/test_helper_spec.rb +28 -0
  399. data/spec/integration/transaction/report_spec.rb +16 -0
  400. data/spec/integration/transaction_spec.rb +11 -0
  401. data/spec/integration/type/file_spec.rb +194 -4
  402. data/spec/integration/type/package_spec.rb +5 -1
  403. data/spec/integration/type/tidy_spec.rb +21 -9
  404. data/spec/integration/util/execution_spec.rb +22 -0
  405. data/spec/integration/util/windows/principal_spec.rb +201 -0
  406. data/spec/integration/util/windows/process_spec.rb +31 -0
  407. data/spec/{unit → integration}/util/windows/registry_spec.rb +91 -1
  408. data/spec/integration/util/windows/security_spec.rb +8 -8
  409. data/spec/integration/util/windows/user_spec.rb +1 -1
  410. data/spec/integration/util_spec.rb +49 -27
  411. data/spec/lib/puppet_spec/compiler.rb +17 -0
  412. data/spec/lib/puppet_spec/files.rb +2 -2
  413. data/spec/lib/puppet_spec/pops.rb +13 -0
  414. data/spec/shared_behaviours/iterative_functions.rb +1 -1
  415. data/spec/shared_contexts/types_setup.rb +96 -0
  416. data/spec/unit/agent_spec.rb +1 -0
  417. data/spec/unit/application/agent_spec.rb +10 -0
  418. data/spec/unit/application/apply_spec.rb +9 -0
  419. data/spec/unit/application/lookup_spec.rb +138 -28
  420. data/spec/unit/configurer/downloader_spec.rb +5 -5
  421. data/spec/unit/configurer_spec.rb +271 -39
  422. data/spec/unit/data_providers/hiera_data_provider_spec.rb +182 -5
  423. data/spec/unit/data_providers/hiera_interpolation_spec.rb +57 -0
  424. data/spec/unit/defaults_spec.rb +15 -0
  425. data/spec/unit/environments_spec.rb +24 -4
  426. data/spec/unit/face/epp_face_spec.rb +2 -2
  427. data/spec/unit/face/parser_spec.rb +43 -2
  428. data/spec/unit/file_serving/http_metadata_spec.rb +85 -0
  429. data/spec/unit/file_serving/metadata_spec.rb +50 -0
  430. data/spec/unit/file_serving/terminus_selector_spec.rb +12 -2
  431. data/spec/unit/file_system_spec.rb +26 -0
  432. data/spec/unit/functions/assert_type_spec.rb +36 -2
  433. data/spec/unit/functions/defined_spec.rb +2 -2
  434. data/spec/unit/functions/epp_spec.rb +17 -9
  435. data/spec/unit/functions/inline_epp_spec.rb +4 -4
  436. data/spec/unit/functions/lookup_spec.rb +88 -16
  437. data/spec/unit/functions/regsubst_spec.rb +1 -1
  438. data/spec/unit/functions/reverse_each_spec.rb +108 -0
  439. data/spec/unit/functions/step_spec.rb +113 -0
  440. data/spec/unit/functions/type_spec.rb +35 -0
  441. data/spec/unit/functions4_spec.rb +62 -6
  442. data/spec/unit/hiera/scope_spec.rb +5 -2
  443. data/spec/unit/indirector/catalog/compiler_spec.rb +705 -4
  444. data/spec/unit/indirector/file_bucket_file/file_spec.rb +1 -1
  445. data/spec/unit/indirector/indirection_spec.rb +1 -1
  446. data/spec/unit/indirector/json_spec.rb +1 -1
  447. data/spec/unit/info_service_spec.rb +94 -32
  448. data/spec/unit/module_spec.rb +14 -0
  449. data/spec/unit/module_tool/applications/builder_spec.rb +4 -4
  450. data/spec/unit/network/authstore_spec.rb +1 -1
  451. data/spec/unit/network/http/connection_spec.rb +1 -0
  452. data/spec/unit/network/http/pool_spec.rb +30 -0
  453. data/spec/unit/node_spec.rb +8 -0
  454. data/spec/unit/parser/compiler_spec.rb +16 -18
  455. data/spec/unit/parser/scope_spec.rb +28 -11
  456. data/spec/unit/pops/evaluator/access_ops_spec.rb +7 -7
  457. data/spec/unit/pops/evaluator/comparison_ops_spec.rb +3 -0
  458. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +8 -2
  459. data/spec/unit/pops/evaluator/evaluator_rspec_helper.rb +4 -4
  460. data/spec/unit/pops/evaluator/json_strict_literal_evaluator_spec.rb +63 -0
  461. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +6 -0
  462. data/spec/unit/pops/loaders/dependency_loader_spec.rb +53 -0
  463. data/spec/unit/pops/loaders/loaders_spec.rb +127 -2
  464. data/spec/unit/pops/parser/lexer2_spec.rb +118 -3
  465. data/spec/unit/pops/parser/parse_calls_spec.rb +8 -0
  466. data/spec/unit/pops/parser/parser_rspec_helper.rb +5 -0
  467. data/spec/unit/pops/parser/parser_spec.rb +10 -0
  468. data/spec/unit/pops/parser/source_pos_adapter_spec.rb +26 -0
  469. data/spec/unit/pops/types/iterable_spec.rb +262 -0
  470. data/spec/unit/pops/types/recursion_guard_spec.rb +91 -0
  471. data/spec/unit/pops/types/type_acceptor_spec.rb +105 -0
  472. data/spec/unit/pops/types/type_asserter_spec.rb +43 -0
  473. data/spec/unit/pops/types/type_calculator_spec.rb +275 -390
  474. data/spec/unit/pops/types/type_formatter_spec.rb +280 -0
  475. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +152 -0
  476. data/spec/unit/pops/types/type_parser_spec.rb +58 -13
  477. data/spec/unit/pops/types/types_spec.rb +241 -0
  478. data/spec/unit/pops/validator/validator_spec.rb +159 -15
  479. data/spec/unit/provider/cron/parsed_spec.rb +1 -0
  480. data/spec/unit/provider/group/windows_adsi_spec.rb +8 -8
  481. data/spec/unit/provider/macauthorization_spec.rb +5 -2
  482. data/spec/unit/provider/nameservice/directoryservice_spec.rb +14 -19
  483. data/spec/unit/provider/package/appdmg_spec.rb +3 -3
  484. data/spec/unit/provider/package/dnf_spec.rb +16 -0
  485. data/spec/unit/provider/package/pip3_spec.rb +60 -42
  486. data/spec/unit/provider/package/pip_spec.rb +88 -47
  487. data/spec/unit/provider/package/pkgdmg_spec.rb +18 -9
  488. data/spec/unit/provider/package/pkgng_spec.rb +4 -2
  489. data/spec/unit/provider/package/rpm_spec.rb +2 -25
  490. data/spec/unit/provider/package/yum_spec.rb +12 -1
  491. data/spec/unit/provider/package/zypper_spec.rb +14 -0
  492. data/spec/unit/provider/service/debian_spec.rb +6 -24
  493. data/spec/unit/provider/service/init_spec.rb +11 -1
  494. data/spec/unit/provider/service/launchd_spec.rb +18 -25
  495. data/spec/unit/provider/service/systemd_spec.rb +25 -12
  496. data/spec/unit/provider/service/upstart_spec.rb +57 -0
  497. data/spec/unit/provider/sshkey/parsed_spec.rb +20 -19
  498. data/spec/unit/provider/user/directoryservice_spec.rb +40 -59
  499. data/spec/unit/provider/user/windows_adsi_spec.rb +5 -5
  500. data/spec/unit/provider/yumrepo/inifile_spec.rb +16 -0
  501. data/spec/unit/resource/capability_finder_spec.rb +28 -15
  502. data/spec/unit/resource/catalog_spec.rb +33 -1
  503. data/spec/unit/resource/type_spec.rb +149 -7
  504. data/spec/unit/resource_spec.rb +99 -50
  505. data/spec/unit/settings/environment_conf_spec.rb +18 -1
  506. data/spec/unit/ssl/certificate_revocation_list_spec.rb +3 -3
  507. data/spec/unit/transaction/report_spec.rb +27 -0
  508. data/spec/unit/transaction/resource_harness_spec.rb +0 -47
  509. data/spec/unit/transaction_spec.rb +5 -0
  510. data/spec/unit/type/file/checksum_spec.rb +6 -0
  511. data/spec/unit/type/file/checksum_value_spec.rb +286 -0
  512. data/spec/unit/type/file/content_spec.rb +12 -193
  513. data/spec/unit/type/file/source_spec.rb +211 -119
  514. data/spec/unit/type/file_spec.rb +133 -34
  515. data/spec/unit/type/interface_spec.rb +32 -0
  516. data/spec/unit/type/macauthorization_spec.rb +4 -1
  517. data/spec/unit/type/yumrepo_spec.rb +2 -2
  518. data/spec/unit/util/filetype_spec.rb +1 -1
  519. data/spec/unit/util/http_proxy_spec.rb +2 -2
  520. data/spec/unit/util/log/destinations_spec.rb +0 -2
  521. data/spec/unit/util/logging_spec.rb +69 -0
  522. data/spec/unit/util/multi_match_spec.rb +39 -0
  523. data/spec/unit/util/network_device/cisco/device_spec.rb +253 -216
  524. data/spec/unit/util/network_device/transport/telnet_spec.rb +60 -58
  525. data/spec/unit/util/plist_spec.rb +110 -0
  526. data/spec/unit/util/resource_template_spec.rb +2 -2
  527. data/spec/unit/util/run_mode_spec.rb +27 -3
  528. data/spec/unit/util/windows/adsi_spec.rb +46 -38
  529. data/spec/unit/util/windows/api_types_spec.rb +42 -0
  530. data/spec/unit/util/windows/security_descriptor_spec.rb +3 -3
  531. data/spec/unit/util/windows/sid_spec.rb +48 -11
  532. data/spec/unit/util_spec.rb +123 -13
  533. data/tasks/cfpropertylist.rake +15 -0
  534. metadata +3342 -3195
  535. data/lib/puppet/vendor/load_plist.rb +0 -1
  536. data/lib/puppet/vendor/plist/CHANGELOG +0 -82
  537. data/lib/puppet/vendor/plist/MIT-LICENSE +0 -21
  538. data/lib/puppet/vendor/plist/PUPPET_README.md +0 -6
  539. data/lib/puppet/vendor/plist/README +0 -36
  540. data/lib/puppet/vendor/plist/Rakefile +0 -144
  541. data/lib/puppet/vendor/plist/docs/USAGE +0 -104
  542. data/lib/puppet/vendor/plist/docs/jamis-template.rb +0 -591
  543. data/lib/puppet/vendor/plist/lib/plist/generator.rb +0 -224
  544. data/lib/puppet/vendor/plist/lib/plist/parser.rb +0 -225
  545. data/lib/puppet/vendor/plist/lib/plist.rb +0 -22
  546. data/lib/puppet/vendor/plist/test/assets/AlbumData.xml +0 -203
  547. data/lib/puppet/vendor/plist/test/assets/Cookies.plist +0 -104
  548. data/lib/puppet/vendor/plist/test/assets/commented.plist +0 -9
  549. data/lib/puppet/vendor/plist/test/assets/example_data.bin +0 -0
  550. data/lib/puppet/vendor/plist/test/assets/example_data.jpg +0 -0
  551. data/lib/puppet/vendor/plist/test/assets/example_data.plist +0 -259
  552. data/lib/puppet/vendor/plist/test/assets/test_data_elements.plist +0 -24
  553. data/lib/puppet/vendor/plist/test/assets/test_empty_key.plist +0 -13
  554. data/lib/puppet/vendor/plist/test/test_data_elements.rb +0 -115
  555. data/lib/puppet/vendor/plist/test/test_generator.rb +0 -59
  556. data/lib/puppet/vendor/plist/test/test_generator_basic_types.rb +0 -58
  557. data/lib/puppet/vendor/plist/test/test_generator_collections.rb +0 -82
  558. data/lib/puppet/vendor/plist/test/test_parser.rb +0 -90
  559. /data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{usee → modules/usee}/lib/puppet/functions/usee/callee.rb +0 -0
  560. /data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/lib/puppet/functions/user/caller.rb +0 -0
@@ -6,7 +6,7 @@
6
6
  #
7
7
  # This function takes two mandatory arguments, in this order:
8
8
  #
9
- # 1. An array or hash the function will iterate over.
9
+ # 1. An array, hash, or other iterable object that the function will iterate over.
10
10
  # 2. A lambda, which the function calls for each element in the first argument. It takes
11
11
  # two mandatory parameters:
12
12
  # 1. A memo value that is overwritten after each iteration with the iteration's result.
@@ -99,31 +99,23 @@
99
99
  Puppet::Functions.create_function(:reduce) do
100
100
 
101
101
  dispatch :reduce_without_memo do
102
- param 'Any', :enumerable
102
+ param 'Iterable', :enumerable
103
103
  block_param 'Callable[2,2]', :block
104
104
  end
105
105
 
106
106
  dispatch :reduce_with_memo do
107
- param 'Any', :enumerable
107
+ param 'Iterable', :enumerable
108
108
  param 'Any', :memo
109
109
  block_param 'Callable[2,2]', :block
110
110
  end
111
111
 
112
112
  def reduce_without_memo(enumerable)
113
- enum = asserted_enumerable(enumerable)
113
+ enum = Puppet::Pops::Types::Iterable.asserted_iterable(self, enumerable)
114
114
  enum.reduce {|memo, x| yield(memo, x) }
115
115
  end
116
116
 
117
117
  def reduce_with_memo(enumerable, given_memo)
118
- enum = asserted_enumerable(enumerable)
118
+ enum = Puppet::Pops::Types::Iterable.asserted_iterable(self, enumerable)
119
119
  enum.reduce(given_memo) {|memo, x| yield(memo, x) }
120
120
  end
121
-
122
- def asserted_enumerable(obj)
123
- unless enum = Puppet::Pops::Types::Enumeration.enumerator(obj)
124
- raise ArgumentError, ("#{self.class.name}(): wrong argument type (#{obj.class}; must be something enumerable.")
125
- end
126
- enum
127
- end
128
-
129
121
  end
@@ -0,0 +1,82 @@
1
+ # Reverses the order of the elements of something that is iterable and optionally runs a
2
+ # [lambda](http://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html) for each
3
+ # element.
4
+ #
5
+ # This function takes one to two arguments.
6
+ #
7
+ # 1. An `Iterable` that the function will iterate over.
8
+ # 2. An optional lambda, which the function calls for each element in the first argument. It must
9
+ # request one parameter.
10
+ #
11
+ # @example Using the `reverse_each` function
12
+ #
13
+ # `$data.reverse_each |$parameter| { <PUPPET CODE BLOCK> }`
14
+ #
15
+ # or
16
+ #
17
+ # `$reverse_data = $data.reverse_each`
18
+ #
19
+ # or
20
+ #
21
+ # `reverse_each($data) |$parameter| { <PUPPET CODE BLOCK> }`
22
+ #
23
+ # or
24
+ #
25
+ # `$reverse_data = reverse_each($data)`
26
+ #
27
+ # When no second argument is present, Puppet returns an `Iterable` that represents the reverse
28
+ # order of its first argument. This allows methods on `Iterable` to be chained.
29
+ #
30
+ # When a lamdba is given as the second argument, Puppet iterates the first argument in reverse
31
+ # order and passes each value in turn to the lambda, then returns `undef`.
32
+ #
33
+ # @example Using the `reverse_each` function with an array and a one-parameter lambda
34
+ #
35
+ # ~~~ puppet
36
+ # # Puppet will log a notice for each of the three items in $data in reverse order.
37
+ # $data = [1,2,3]
38
+ # $data.reverse_each |$item| { notice($item) }
39
+ #
40
+ # ~~~
41
+ #
42
+ # When no second argument is present, Puppet returns a new `Iterable` which allows it to
43
+ # be directly chained into another function that takes an `Iterable` as an argument.
44
+ #
45
+ # @example Using the `reverse_each` function chained with a `map` function.
46
+ #
47
+ # # For the array $data, return an array containing each value multiplied by 10 in reverse order
48
+ # $data = [1,2,3]
49
+ # $transformed_data = $data.reverse_each.map |$item| { $item * 10 }
50
+ # # $transformed_data is set to [30,20,10]
51
+ # ~~~
52
+ #
53
+ # @example The same example using `reverse_each` function chained with a `map` in alternative syntax
54
+ #
55
+ # # For the array $data, return an array containing each value multiplied by 10 in reverse order
56
+ # $data = [1,2,3]
57
+ # $transformed_data = map(reverse_each($data)) |$item| { $item * 10 }
58
+ # # $transformed_data is set to [30,20,10]
59
+ # ~~~
60
+ #
61
+ # @since 4.4.0
62
+ #
63
+ Puppet::Functions.create_function(:reverse_each) do
64
+ dispatch :reverse_each do
65
+ param 'Iterable', :iterable
66
+ end
67
+
68
+ dispatch :reverse_each_block do
69
+ param 'Iterable', :iterable
70
+ block_param 'Callable[1,1]', :block
71
+ end
72
+
73
+ def reverse_each(iterable)
74
+ # produces an Iterable
75
+ Puppet::Pops::Types::Iterable.asserted_iterable(self, iterable).reverse_each
76
+ end
77
+
78
+ def reverse_each_block(iterable, &block)
79
+ Puppet::Pops::Types::Iterable.asserted_iterable(self, iterable).reverse_each(&block)
80
+ nil
81
+ end
82
+ end
@@ -1,23 +1,16 @@
1
- # Scans a string and returns an array of one or more converted values as directed by a given format string.args
2
- # See the documenation of Ruby's String::scanf method for details about the supported formats (which
3
- # are similar but not identical to the formats used in Puppet's `sprintf` function.
4
- #
5
- # This function takes two mandatory arguments: the first is the String to convert, and the second
6
- # the format String. A parameterized block may optionally be given, which is called with the result
7
- # that is produced by scanf if no block is present, the result of the block is then returned by
8
- # the function.
9
- #
10
- # The result of the scan is an Array, with each sucessfully scanned and transformed value.args The scanning
11
- # stops if a scan is unsuccesful and the scanned result up to that point is returned. If there was no
12
- # succesful scan at all, the result is an empty Array. The optional code block is typically used to
13
- # assert that the scan was succesful, and either produce the same input, or perform unwrapping of
14
- # the result
15
- #
16
- # @example scanning an integer in string form (result is an array with
17
- # integer, or empty if unsuccessful)
1
+ # Scans a string and returns an array of one or more converted values based on the given format string.
2
+ # See the documenation of Ruby's String#scanf method for details about the supported formats (which
3
+ # are similar but not identical to the formats used in Puppet's `sprintf` function.)
4
+ #
5
+ # This function takes two mandatory arguments: the first is the string to convert, and the second is
6
+ # the format string. The result of the scan is an array, with each sucessfully scanned and transformed value.
7
+ # The scanning stops if a scan is unsuccesful, and the scanned result up to that point is returned. If there
8
+ # was no succesful scan, the result is an empty array.
9
+ #
18
10
  # "42".scanf("%i")
19
11
  #
20
- # @example scanning and processing resulting array to assert result and unwrap
12
+ # You can also optionally pass a lambda to scanf, to do additional validation or processing.
13
+ #
21
14
  #
22
15
  # "42".scanf("%i") |$x| {
23
16
  # unless $x[0] =~ Integer {
@@ -26,6 +19,10 @@
26
19
  # $x[0]
27
20
  # }
28
21
  #
22
+ #
23
+ #
24
+ #
25
+ #
29
26
  # @since 4.0.0
30
27
  #
31
28
  Puppet::Functions.create_function(:scanf) do
@@ -1,51 +1,45 @@
1
- # Applies a parameterized block to each _slice_ of elements in a sequence of selected entries from the first
2
- # argument and returns the first argument, or if no block is given returns a new array with a concatenation of
3
- # the slices.
1
+ # This function takes two mandatory arguments: the first should be an array or hash, and the second specifies
2
+ # the number of elements to include in each slice.
4
3
  #
5
- # This function takes two mandatory arguments: the first, `$a`, should be an Array, Hash, or something of
6
- # enumerable type (integer, Integer range, or String), and the second, `$n`, the number of elements to include
7
- # in each slice. The optional third argument should be a a parameterized block as produced by the puppet syntax:
8
- #
9
- # $a.slice($n) |$x| { ... }
10
- # slice($a) |$x| { ... }
11
- #
12
- # The parameterized block should have either one parameter (receiving an array with the slice), or the same number
13
- # of parameters as specified by the slice size (each parameter receiving its part of the slice).
14
- # In case there are fewer remaining elements than the slice size for the last slice it will contain the remaining
15
- # elements. When the block has multiple parameters, excess parameters are set to undef for an array or
16
- # enumerable type, and to empty arrays for a Hash.
17
- #
18
- # $a.slice(2) |$first, $second| { ... }
19
- #
20
- # When the first argument is a Hash, each `key,value` entry is counted as one, e.g, a slice size of 2 will produce
4
+ # When the first argument is a hash, each key value pair is counted as one. For example, a slice size of 2 will produce
21
5
  # an array of two arrays with key, and value.
22
6
  #
23
- # @example Using slice with Hash
24
- #
25
7
  # $a.slice(2) |$entry| { notice "first ${$entry[0]}, second ${$entry[1]}" }
26
8
  # $a.slice(2) |$first, $second| { notice "first ${first}, second ${second}" }
27
9
  #
28
- # When called without a block, the function produces a concatenated result of the slices.
29
- #
30
- # @example Using slice without a block
10
+ # The function produces a concatenated result of the slices.
31
11
  #
32
12
  # slice([1,2,3,4,5,6], 2) # produces [[1,2], [3,4], [5,6]]
33
13
  # slice(Integer[1,6], 2) # produces [[1,2], [3,4], [5,6]]
34
14
  # slice(4,2) # produces [[0,1], [2,3]]
35
15
  # slice('hello',2) # produces [[h, e], [l, l], [o]]
36
16
  #
17
+ #
18
+ # You can also optionally pass a lambda to slice.
19
+ #
20
+ # $a.slice($n) |$x| { ... }
21
+ # slice($a) |$x| { ... }
22
+ #
23
+ # The lambda should have either one parameter (receiving an array with the slice), or the same number
24
+ # of parameters as specified by the slice size (each parameter receiving its part of the slice).
25
+ # If there are fewer remaining elements than the slice size for the last slice, it will contain the remaining
26
+ # elements. If the lambda has multiple parameters, excess parameters are set to undef for an array, or
27
+ # to empty arrays for a hash.
28
+ #
29
+ # $a.slice(2) |$first, $second| { ... }
30
+ #
37
31
  # @since 4.0.0
38
32
  #
39
33
  Puppet::Functions.create_function(:slice) do
40
34
  dispatch :slice_Hash do
41
35
  param 'Hash[Any, Any]', :hash
42
- param 'Integer[1, default]', :slize_size
36
+ param 'Integer[1, default]', :slice_size
43
37
  optional_block_param
44
38
  end
45
39
 
46
40
  dispatch :slice_Enumerable do
47
- param 'Any', :enumerable
48
- param 'Integer[1, default]', :slize_size
41
+ param 'Iterable', :enumerable
42
+ param 'Integer[1, default]', :slice_size
49
43
  optional_block_param
50
44
  end
51
45
 
@@ -55,7 +49,7 @@ Puppet::Functions.create_function(:slice) do
55
49
  end
56
50
 
57
51
  def slice_Enumerable(enumerable, slice_size, &pblock)
58
- enum = asserted_enumerable(enumerable)
52
+ enum = Puppet::Pops::Types::Iterable.asserted_iterable(self, enumerable)
59
53
  result = slice_Common(enum, slice_size, nil, block_given? ? pblock : nil)
60
54
  block_given? ? enumerable : result
61
55
  end
@@ -114,12 +108,4 @@ Puppet::Functions.create_function(:slice) do
114
108
  end
115
109
  serving_size
116
110
  end
117
-
118
- def asserted_enumerable(obj)
119
- unless enum = Puppet::Pops::Types::Enumeration.enumerator(obj)
120
- raise ArgumentError, ("#{self.class.name}(): wrong argument type (#{obj.class}; must be something enumerable.")
121
- end
122
- enum
123
- end
124
-
125
111
  end
@@ -6,7 +6,7 @@
6
6
  # $string = 'v1.v2:v3.v4'
7
7
  # $array_var1 = split($string, /:/)
8
8
  # $array_var2 = split($string, '[.]')
9
- # $array_var3 = split($string, Regexp('[.:]'))
9
+ # $array_var3 = split($string, Regexp['[.:]'])
10
10
  #
11
11
  # `$array_var1` now holds the result `['v1.v2', 'v3.v4']`,
12
12
  # while `$array_var2` holds `['v1', 'v2:v3', 'v4']`, and
@@ -15,7 +15,7 @@
15
15
  # Note that in the second example, we split on a literal string that contains
16
16
  # a regexp meta-character (.), which must be escaped. A simple
17
17
  # way to do that for a single character is to enclose it in square
18
- # brackets; a backslash will also escape a single character.") do |args|
18
+ # brackets; a backslash will also escape a single character.
19
19
  #
20
20
  Puppet::Functions.create_function(:split) do
21
21
  dispatch :split_String do
@@ -0,0 +1,88 @@
1
+ # Provides stepping with given interval over elements in an iterable and optionally runs a
2
+ # [lambda](http://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html) for each
3
+ # element.
4
+ #
5
+ # This function takes two to three arguments.
6
+ #
7
+ # 1. An 'Iterable' that the function will iterate over.
8
+ # 2. An `Integer` step factor. This must be a positive integer.
9
+ # 3. An optional lambda, which the function calls for each element in the interval. It must
10
+ # request one parameter.
11
+ #
12
+ # @example Using the `step` function
13
+ #
14
+ # `$data.step(<n>) |$parameter| { <PUPPET CODE BLOCK> }`
15
+ #
16
+ # or
17
+ #
18
+ # `$stepped_data = $data.step(<n>)`
19
+ #
20
+ # or
21
+ #
22
+ # `step($data, <n>) |$parameter| { <PUPPET CODE BLOCK> }`
23
+ #
24
+ # or
25
+ #
26
+ # `$stepped_data = step($data, <n>)`
27
+ #
28
+ # When no block is given, Puppet returns an `Iterable` that yields the first element and every nth successor
29
+ # element, from its first argument. This allows functions on iterables to be chained.
30
+ #
31
+ # When a block is given, Puppet iterates and calls the block with the first element and then with
32
+ # every nth successor element. It then returns `undef`.
33
+ #
34
+ # @example Using the `step` function with an array, a step factor, and a one-parameter block
35
+ #
36
+ # ~~~ puppet
37
+ # # For the array $data, call a block with the first element and then with each 3rd successor element
38
+ # $data = [1,2,3,4,5,6,7,8]
39
+ # $data.step(3) |$item| {
40
+ # notice($item)
41
+ # }
42
+ # # Puppet notices the values '1', '4', '7'.
43
+ # ~~~
44
+ #
45
+ # When no block is given, Puppet returns a new `Iterable` which allows it to be directly chained into
46
+ # another function that takes an `Iterable` as an argument.
47
+ #
48
+ # @example Using the `step` function chained with a `map` function.
49
+ #
50
+ # # For the array $data, return an array, set to the first element and each 5th successor element, in reverse
51
+ # # order multiplied by 10
52
+ # $data = Integer[0,20]
53
+ # $transformed_data = $data.step(5).map |$item| { $item * 10 }
54
+ # # $transformed_data contains [0,50,100,150,200]
55
+ # ~~~
56
+ #
57
+ # @example The same example using `step` function chained with a `map` in alternative syntax
58
+ #
59
+ # # For the array $data, return an array, set to the first and each 5th successor, in reverse order, multiplied by 10
60
+ # $data = Integer[0,20]
61
+ # $transformed_data = map(step($data, 5)) |$item| { $item * 10 }
62
+ # # $transformed_data contains [0,50,100,150,200]
63
+ # ~~~
64
+ #
65
+ # @since 4.4.0
66
+ #
67
+ Puppet::Functions.create_function(:step) do
68
+ dispatch :step do
69
+ param 'Iterable', :iterable
70
+ param 'Integer[1]', :step
71
+ end
72
+
73
+ dispatch :step_block do
74
+ param 'Iterable', :iterable
75
+ param 'Integer[1]', :step
76
+ block_param 'Callable[1,1]', :block
77
+ end
78
+
79
+ def step(iterable, step)
80
+ # produces an Iterable
81
+ Puppet::Pops::Types::Iterable.asserted_iterable(self, iterable).step(step)
82
+ end
83
+
84
+ def step_block(iterable, step, &block)
85
+ Puppet::Pops::Types::Iterable.asserted_iterable(self, iterable).step(step, &block)
86
+ nil
87
+ end
88
+ end
@@ -0,0 +1,70 @@
1
+ # Returns the data type of a given value with a given degree of generality.
2
+ #
3
+ # @example Using `type()`
4
+ #
5
+ # ~~~ puppet
6
+ # notice type(42) =~ Type[Integer]
7
+ # ~~~
8
+ #
9
+ # Would notice true
10
+ #
11
+ # By default, the best possible inference is made where all details are retained.
12
+ # This is good when the type is used for futher type calculations but is overwhelmingly
13
+ # rich i information if it is used in a error message.
14
+ #
15
+ # The optional argument `inference_method` may be given as (from lowest to highest fidelity):
16
+ #
17
+ # * ´generalized` - reduces to common type and drops size constraints
18
+ # * `reduced` - reduces to common type in collections
19
+ # * `detailed` - (defaut) all details about inferred types is retained
20
+ #
21
+ # @example Using `type()` with different qualities:
22
+ #
23
+ # ~~~ puppet
24
+ # notice type([3.14, 42], generalized)
25
+ # notice type([3.14, 42], reduced)
26
+ # notice type([3.14, 42], detailed)
27
+ # notice type([3.14, 42])
28
+ # ~~~
29
+ #
30
+ # Would notice the four values:
31
+ #
32
+ # 1. 'Array[Numeric]'
33
+ # 2. 'Array[Numeric, 2, 2]'
34
+ # 3. 'Tuple[Float[3.14], Integer[42,42]]]'
35
+ # 4. 'Tuple[Float[3.14], Integer[42,42]]]'
36
+ #
37
+ # @param value [Any] - the value for which data type is returned
38
+ # @param inference_type[Enum[generalized, reduced, detailed]] inference_type
39
+ # @returns [Type] - the inferred type
40
+ #
41
+ # @since 4.4.0
42
+ #
43
+ Puppet::Functions.create_function(:type) do
44
+ dispatch :type_detailed do
45
+ param 'Any', :value
46
+ optional_param 'Enum[detailed]', :inference_method
47
+ end
48
+
49
+ dispatch :type_parameterized do
50
+ param 'Any', :value
51
+ param 'Enum[reduced]', :inference_method
52
+ end
53
+
54
+ dispatch :type_generalized do
55
+ param 'Any', :value
56
+ param 'Enum[generalized]', :inference_method
57
+ end
58
+
59
+ def type_detailed(value, _ = nil)
60
+ Puppet::Pops::Types::TypeCalculator.infer_set(value)
61
+ end
62
+
63
+ def type_parameterized(value, _)
64
+ Puppet::Pops::Types::TypeCalculator.infer(value)
65
+ end
66
+
67
+ def type_generalized(value, _)
68
+ Puppet::Pops::Types::TypeCalculator.infer(value).generalize
69
+ end
70
+ end
@@ -153,6 +153,28 @@ module Puppet::Functions
153
153
  #
154
154
  # @api public
155
155
  def self.create_function(func_name, function_base = Function, &block)
156
+ # Ruby < 2.1.0 does not have method on Binding, can only do eval
157
+ # and it will fail unless protected with an if defined? if the local
158
+ # variable does not exist in the block's binder.
159
+ #
160
+ loader = block.binding.eval('loader_injected_arg if defined?(loader_injected_arg)')
161
+ create_loaded_function(func_name, loader, function_base, &block)
162
+ end
163
+
164
+ # Creates a function in, or in a local loader under the given loader.
165
+ # This method should only be used when manually creating functions
166
+ # for the sake of testing. Functions that are autoloaded should
167
+ # always use the `create_function` method and the autoloader will supply
168
+ # the correct loader.
169
+ #
170
+ # @param func_name [String, Symbol] a simple or qualified function name
171
+ # @param loader [Puppet::Pops::Loaders::Loader] the loader loading the function
172
+ # @param block [Proc] the block that defines the methods and dispatch of the
173
+ # Function to create
174
+ # @return [Class<Function>] the newly created Function class
175
+ #
176
+ # @api public
177
+ def self.create_loaded_function(func_name, loader, function_base = Function, &block)
156
178
  if function_base.ancestors.none? { |s| s == Puppet::Pops::Functions::Function }
157
179
  raise ArgumentError, "Functions must be based on Puppet::Pops::Functions::Function. Got #{function_base}"
158
180
  end
@@ -162,7 +184,12 @@ module Puppet::Functions
162
184
  # The idea being that it is garbage collected when there are no more
163
185
  # references to it.
164
186
  #
165
- the_class = Class.new(function_base, &block)
187
+ # (Do not give the class the block here, as instance variables should be set first)
188
+ the_class = Class.new(function_base)
189
+
190
+ unless loader.nil?
191
+ the_class.instance_variable_set(:'@loader', loader.private_loader)
192
+ end
166
193
 
167
194
  # Make the anonymous class appear to have the class-name <func_name>
168
195
  # Even if this class is not bound to such a symbol in a global ruby scope and
@@ -175,11 +202,20 @@ module Puppet::Functions
175
202
  #
176
203
  the_class.instance_eval do
177
204
  @func_name = func_name
205
+
178
206
  def name
179
207
  @func_name
180
208
  end
209
+
210
+ def loader
211
+ @loader
212
+ end
181
213
  end
182
214
 
215
+ # The given block can now be evaluated and have access to name and loader
216
+ #
217
+ the_class.class_eval(&block)
218
+
183
219
  # Automatically create an object dispatcher based on introspection if the
184
220
  # loaded user code did not define any dispatchers. Fail if function name
185
221
  # does not match a given method name in user code.
@@ -238,7 +274,7 @@ module Puppet::Functions
238
274
  def self.builder
239
275
  @type_parser ||= Puppet::Pops::Types::TypeParser.new
240
276
  @all_callables ||= Puppet::Pops::Types::TypeFactory.all_callables
241
- DispatcherBuilder.new(dispatcher, @type_parser, @all_callables)
277
+ DispatcherBuilder.new(dispatcher, @type_parser, @all_callables, loader)
242
278
  end
243
279
 
244
280
  # Dispatch any calls that match the signature to the provided method name.
@@ -269,11 +305,14 @@ module Puppet::Functions
269
305
  #
270
306
  # @api public
271
307
  class DispatcherBuilder
308
+ attr_reader :loader
309
+
272
310
  # @api private
273
- def initialize(dispatcher, type_parser, all_callables)
311
+ def initialize(dispatcher, type_parser, all_callables, loader)
274
312
  @type_parser = type_parser
275
313
  @all_callables = all_callables
276
314
  @dispatcher = dispatcher
315
+ @loader = loader
277
316
  end
278
317
 
279
318
  # Defines a required positional parameter with _type_ and _name_.
@@ -356,7 +395,7 @@ module Puppet::Functions
356
395
  name = type_and_name[0]
357
396
  when 2
358
397
  type_string, name = type_and_name
359
- type = @type_parser.parse(type_string)
398
+ type = @type_parser.parse(type_string, loader)
360
399
  else
361
400
  raise ArgumentError, "block_param accepts max 2 arguments (type, name), got #{type_and_name.size}."
362
401
  end
@@ -441,7 +480,7 @@ module Puppet::Functions
441
480
  # @api private
442
481
  def create_callable(types, block_type, from, to)
443
482
  mapped_types = types.map do |t|
444
- @type_parser.parse(t)
483
+ @type_parser.parse(t, loader)
445
484
  end
446
485
 
447
486
  if from != to
@@ -496,7 +535,7 @@ module Puppet::Functions
496
535
  def self.builder
497
536
  @type_parser ||= Puppet::Pops::Types::TypeParser.new
498
537
  @all_callables ||= Puppet::Pops::Types::TypeFactory.all_callables
499
- InternalDispatchBuilder.new(dispatcher, @type_parser, @all_callables)
538
+ InternalDispatchBuilder.new(dispatcher, @type_parser, @all_callables, loader)
500
539
  end
501
540
 
502
541
  # Defines class level injected attribute with reader method
@@ -26,7 +26,7 @@
26
26
  # iterated over in order. This is useful for many datasets.
27
27
  #
28
28
  # The implementation is adapted from Robert Sedgewick's Left Leaning Red-Black Tree implementation,
29
- # which can be found at http://www.cs.princeton.edu/~rs/talks/LLRB/Java/RedBlackBST.java
29
+ # which can be found at https://www.cs.princeton.edu/~rs/talks/LLRB/Java/RedBlackBST.java
30
30
  #
31
31
  # Most methods have O(log n) complexity.
32
32