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
@@ -1,3 +1,5 @@
1
+ module Puppet::Pops
2
+ module Types
1
3
  # The TypeCalculator can answer questions about puppet types.
2
4
  #
3
5
  # The Puppet type system is primarily based on sub-classing. When asking the type calculator to infer types from Ruby in general, it
@@ -41,8 +43,8 @@
41
43
  #
42
44
  # Creation of Type instances
43
45
  # --------------------------
44
- # Instance of the classes in the {Puppet::Pops::Types type model} are used to denote a specific type. It is most convenient
45
- # to use the {Puppet::Pops::Types::TypeFactory TypeFactory} when creating instances.
46
+ # Instance of the classes in the {Types type model} are used to denote a specific type. It is most convenient
47
+ # to use the {TypeFactory} when creating instances.
46
48
  #
47
49
  # @note
48
50
  # In general, new instances of the wanted type should be created as they are assigned to models using containment, and a
@@ -82,9 +84,9 @@
82
84
  # no instances present in the first place. If however the classes are not present, the type
83
85
  # calculator will fall back and state that the two types at least have Any in common.
84
86
  #
85
- # @see Puppet::Pops::Types::TypeFactory TypeFactory for how to create instances of types
86
- # @see Puppet::Pops::Types::TypeParser TypeParser how to construct a type instance from a String
87
- # @see Puppet::Pops::Types Types for details about the type model
87
+ # @see TypeFactory for how to create instances of types
88
+ # @see TypeParser how to construct a type instance from a String
89
+ # @see Types for details about the type model
88
90
  #
89
91
  # Using the Type Calculator
90
92
  # -----
@@ -96,9 +98,7 @@
96
98
  #
97
99
  # @api public
98
100
  #
99
- class Puppet::Pops::Types::TypeCalculator
100
-
101
- Types = Puppet::Pops::Types
101
+ class TypeCalculator
102
102
 
103
103
  # @api public
104
104
  def self.assignable?(t1, t2)
@@ -106,8 +106,8 @@ class Puppet::Pops::Types::TypeCalculator
106
106
  end
107
107
 
108
108
  # Answers, does the given callable accept the arguments given in args (an array or a tuple)
109
- # @param callable [Puppet::Pops::Types::PCallableType] - the callable
110
- # @param args [Puppet::Pops::Types::PArrayType, Puppet::Pops::Types::PTupleType] args optionally including a lambda callable at the end
109
+ # @param callable [PCallableType] - the callable
110
+ # @param args [PArrayType, PTupleType] args optionally including a lambda callable at the end
111
111
  # @return [Boolan] true if the callable accepts the arguments
112
112
  #
113
113
  # @api public
@@ -116,13 +116,14 @@ class Puppet::Pops::Types::TypeCalculator
116
116
  end
117
117
 
118
118
  # Produces a String representation of the given type.
119
- # @param t [Puppet::Pops::Types::PAnyType] the type to produce a string form
119
+ # @param t [PAnyType] the type to produce a string form
120
120
  # @return [String] the type in string form
121
121
  #
122
122
  # @api public
123
123
  #
124
124
  def self.string(t)
125
- singleton.string(t)
125
+ Puppet.deprecation_warning('TypeCalculator.string is deprecated. Use TypeFormatter')
126
+ TypeFormatter.string(t)
126
127
  end
127
128
 
128
129
  # @api public
@@ -142,12 +143,19 @@ class Puppet::Pops::Types::TypeCalculator
142
143
 
143
144
  # @api public
144
145
  def self.debug_string(t)
145
- singleton.debug_string(t)
146
+ Puppet.deprecation_warning('TypeCalculator.debug_string is deprecated. Use TypeFormatter')
147
+ TypeFormatter.debug_string(t)
146
148
  end
147
149
 
148
150
  # @api public
149
151
  def self.enumerable(t)
150
- singleton.enumerable(t)
152
+ Puppet.deprecation_warning('TypeCalculator.enumerable is deprecated. Use iterable')
153
+ singleton.iterable(t)
154
+ end
155
+
156
+ # @api public
157
+ def self.iterable(t)
158
+ singleton.iterable(t)
151
159
  end
152
160
 
153
161
  # @return [TypeCalculator] the singleton instance
@@ -160,10 +168,8 @@ class Puppet::Pops::Types::TypeCalculator
160
168
  # @api public
161
169
  #
162
170
  def initialize
163
- @@infer_visitor ||= Puppet::Pops::Visitor.new(nil, 'infer',0,0)
164
- @@string_visitor ||= Puppet::Pops::Visitor.new(nil, 'string',0,0)
165
- @@inspect_visitor ||= Puppet::Pops::Visitor.new(nil, 'debug_string',0,0)
166
- @@extract_visitor ||= Puppet::Pops::Visitor.new(nil, 'extract',0,0)
171
+ @@infer_visitor ||= Visitor.new(nil, 'infer',0,0)
172
+ @@extract_visitor ||= Visitor.new(nil, 'extract',0,0)
167
173
  end
168
174
 
169
175
  # Answers the question 'is it possible to inject an instance of the given class'
@@ -176,12 +182,12 @@ class Puppet::Pops::Types::TypeCalculator
176
182
  #
177
183
  def injectable_class(klazz)
178
184
  # Handle case when we get a PType instead of a class
179
- if klazz.is_a?(Types::PRuntimeType)
180
- klazz = Puppet::Pops::Types::ClassLoader.provide(klazz)
185
+ if klazz.is_a?(PRuntimeType)
186
+ klazz = ClassLoader.provide(klazz)
181
187
  end
182
188
 
183
189
  # data types can not be injected (check again, it is not safe to assume that given RubyRuntime klazz arg was ok)
184
- return false unless type(klazz).is_a?(Types::PRuntimeType)
190
+ return false unless type(klazz).is_a?(PRuntimeType)
185
191
  if (klazz.respond_to?(:inject) && klazz.method(:inject).arity == -4) || klazz.instance_method(:initialize).arity == 0
186
192
  klazz
187
193
  else
@@ -198,24 +204,30 @@ class Puppet::Pops::Types::TypeCalculator
198
204
  if t.is_a?(Module)
199
205
  t = type(t)
200
206
  end
201
- t.is_a?(Types::PAnyType) ? t.assignable?(t2) : false
207
+ t.is_a?(PAnyType) ? t.assignable?(t2) : false
202
208
  end
203
209
 
204
- # Returns an enumerable if the t represents something that can be iterated
210
+ # Returns an iterable if the t represents something that can be iterated
205
211
  def enumerable(t)
206
- # Only PIntegerTypes are enumerable and only if not representing an infinite range
207
- t.is_a?(Types::PIntegerType) && t.size < Float::INFINITY ? t : nil
212
+ Puppet.deprecation_warning('TypeCalculator.enumerable is deprecated. Use iterable')
213
+ iterable(t)
214
+ end
215
+
216
+ # Returns an iterable if the t represents something that can be iterated
217
+ def iterable(t)
218
+ # Create an iterable on the type if possible
219
+ Iterable.on(t)
208
220
  end
209
221
 
210
222
  # Answers, does the given callable accept the arguments given in args (an array or a tuple)
211
223
  #
212
224
  def callable?(callable, args)
213
- callable.is_a?(Types::PAnyType) && callable.callable?(args)
225
+ callable.is_a?(PAnyType) && callable.callable?(args)
214
226
  end
215
227
 
216
228
  # Answers if the two given types describe the same type
217
229
  def equals(left, right)
218
- return false unless left.is_a?(Types::PAnyType) && right.is_a?(Types::PAnyType)
230
+ return false unless left.is_a?(PAnyType) && right.is_a?(PAnyType)
219
231
  # Types compare per class only - an extra test must be made if the are mutually assignable
220
232
  # to find all types that represent the same type of instance
221
233
  #
@@ -232,29 +244,29 @@ class Puppet::Pops::Types::TypeCalculator
232
244
  # Can't use a visitor here since we don't have an instance of the class
233
245
  case
234
246
  when c <= Integer
235
- type = Types::PIntegerType::DEFAULT
247
+ type = PIntegerType::DEFAULT
236
248
  when c == Float
237
- type = Types::PFloatType::DEFAULT
249
+ type = PFloatType::DEFAULT
238
250
  when c == Numeric
239
- type = Types::PNumericType::DEFAULT
251
+ type = PNumericType::DEFAULT
240
252
  when c == String
241
- type = Types::PStringType::DEFAULT
253
+ type = PStringType::DEFAULT
242
254
  when c == Regexp
243
- type = Types::PRegexpType::DEFAULT
255
+ type = PRegexpType::DEFAULT
244
256
  when c == NilClass
245
- type = Types::PUndefType::DEFAULT
257
+ type = PUndefType::DEFAULT
246
258
  when c == FalseClass, c == TrueClass
247
- type = Types::PBooleanType::DEFAULT
259
+ type = PBooleanType::DEFAULT
248
260
  when c == Class
249
- type = Types::PType::DEFAULT
261
+ type = PType::DEFAULT
250
262
  when c == Array
251
263
  # Assume array of data values
252
- type = Types::PArrayType::DATA
264
+ type = PArrayType::DATA
253
265
  when c == Hash
254
266
  # Assume hash with scalar keys and data values
255
- type = Types::PHashType::DATA
267
+ type = PHashType::DATA
256
268
  else
257
- type = Types::PRuntimeType.new(:ruby, c.name)
269
+ type = PRuntimeType.new(:ruby, c.name)
258
270
  end
259
271
  type
260
272
  end
@@ -262,7 +274,7 @@ class Puppet::Pops::Types::TypeCalculator
262
274
  # Generalizes value specific types. The generalized type is returned.
263
275
  # @api public
264
276
  def generalize(o)
265
- o.is_a?(Types::PAnyType) ? o.generalize : o
277
+ o.is_a?(PAnyType) ? o.generalize : o
266
278
  end
267
279
 
268
280
  # Answers 'what is the single common Puppet Type describing o', or if o is an Array or Hash, what is the
@@ -280,7 +292,7 @@ class Puppet::Pops::Types::TypeCalculator
280
292
  infer_Array(o)
281
293
  when Hash
282
294
  infer_Hash(o)
283
- when Puppet::Pops::Evaluator::PuppetProc
295
+ when Evaluator::PuppetProc
284
296
  infer_PuppetProc(o)
285
297
  else
286
298
  @@infer_visitor.visit_this_0(self, o)
@@ -319,21 +331,21 @@ class Puppet::Pops::Types::TypeCalculator
319
331
  if t.is_a?(Module)
320
332
  t = type(t)
321
333
  end
322
- t.is_a?(Types::PAnyType) ? t.instance?(o) : false
334
+ t.is_a?(PAnyType) ? t.instance?(o) : false
323
335
  end
324
336
 
325
337
  # Answers if t is a puppet type
326
338
  # @api public
327
339
  #
328
340
  def is_ptype?(t)
329
- t.is_a?(Types::PAnyType)
341
+ t.is_a?(PAnyType)
330
342
  end
331
343
 
332
344
  # Answers if t represents the puppet type PUndefType
333
345
  # @api public
334
346
  #
335
347
  def is_pnil?(t)
336
- t.nil? || t.is_a?(Types::PUndefType)
348
+ t.nil? || t.is_a?(PUndefType)
337
349
  end
338
350
 
339
351
  # Answers, 'What is the common type of t1 and t2?'
@@ -354,9 +366,9 @@ class Puppet::Pops::Types::TypeCalculator
354
366
  end
355
367
 
356
368
  # If either side is Unit, it is the other type
357
- if t1.is_a?(Types::PUnitType)
369
+ if t1.is_a?(PUnitType)
358
370
  return t2
359
- elsif t2.is_a?(Types::PUnitType)
371
+ elsif t2.is_a?(PUnitType)
360
372
  return t1
361
373
  end
362
374
 
@@ -368,103 +380,103 @@ class Puppet::Pops::Types::TypeCalculator
368
380
  end
369
381
 
370
382
  # when both are arrays, return an array with common element type
371
- if t1.is_a?(Types::PArrayType) && t2.is_a?(Types::PArrayType)
372
- return Types::PArrayType.new(common_type(t1.element_type, t2.element_type))
383
+ if t1.is_a?(PArrayType) && t2.is_a?(PArrayType)
384
+ return PArrayType.new(common_type(t1.element_type, t2.element_type))
373
385
  end
374
386
 
375
387
  # when both are hashes, return a hash with common key- and element type
376
- if t1.is_a?(Types::PHashType) && t2.is_a?(Types::PHashType)
388
+ if t1.is_a?(PHashType) && t2.is_a?(PHashType)
377
389
  key_type = common_type(t1.key_type, t2.key_type)
378
390
  element_type = common_type(t1.element_type, t2.element_type)
379
- return Types::PHashType.new(key_type, element_type)
391
+ return PHashType.new(key_type, element_type)
380
392
  end
381
393
 
382
394
  # when both are host-classes, reduce to PHostClass[] (since one was not assignable to the other)
383
- if t1.is_a?(Types::PHostClassType) && t2.is_a?(Types::PHostClassType)
384
- return Types::PHostClassType::DEFAULT
395
+ if t1.is_a?(PHostClassType) && t2.is_a?(PHostClassType)
396
+ return PHostClassType::DEFAULT
385
397
  end
386
398
 
387
399
  # when both are resources, reduce to Resource[T] or Resource[] (since one was not assignable to the other)
388
- if t1.is_a?(Types::PResourceType) && t2.is_a?(Types::PResourceType)
400
+ if t1.is_a?(PResourceType) && t2.is_a?(PResourceType)
389
401
  # only Resource[] unless the type name is the same
390
- return t1.type_name == t2.type_name ? Types::PResourceType.new(t1.type_name, nil) : Types::PResourceType::DEFAULT
402
+ return t1.type_name == t2.type_name ? PResourceType.new(t1.type_name, nil) : PResourceType::DEFAULT
391
403
  end
392
404
 
393
405
  # Integers have range, expand the range to the common range
394
- if t1.is_a?(Types::PIntegerType) && t2.is_a?(Types::PIntegerType)
395
- return Types::PIntegerType.new([t1.numeric_from, t2.numeric_from].min, [t1.numeric_to, t2.numeric_to].max)
406
+ if t1.is_a?(PIntegerType) && t2.is_a?(PIntegerType)
407
+ return PIntegerType.new([t1.numeric_from, t2.numeric_from].min, [t1.numeric_to, t2.numeric_to].max)
396
408
  end
397
409
 
398
410
  # Floats have range, expand the range to the common range
399
- if t1.is_a?(Types::PFloatType) && t2.is_a?(Types::PFloatType)
400
- return Types::PFloatType.new([t1.numeric_from, t2.numeric_from].min, [t1.numeric_to, t2.numeric_to].max)
411
+ if t1.is_a?(PFloatType) && t2.is_a?(PFloatType)
412
+ return PFloatType.new([t1.numeric_from, t2.numeric_from].min, [t1.numeric_to, t2.numeric_to].max)
401
413
  end
402
414
 
403
- if t1.is_a?(Types::PStringType) && t2.is_a?(Types::PStringType)
415
+ if t1.is_a?(PStringType) && t2.is_a?(PStringType)
404
416
  common_size_type = common_type(t1.size_type, t2.size_type) unless t1.size_type.nil? || t2.size_type.nil?
405
417
  common_strings = t1.values.empty? || t2.values.empty? ? [] : t1.values | t2.values
406
- return Types::PStringType.new(common_size_type, common_strings)
418
+ return PStringType.new(common_size_type, common_strings)
407
419
  end
408
420
 
409
- if t1.is_a?(Types::PPatternType) && t2.is_a?(Types::PPatternType)
410
- return Types::PPatternType.new(t1.patterns | t2.patterns)
421
+ if t1.is_a?(PPatternType) && t2.is_a?(PPatternType)
422
+ return PPatternType.new(t1.patterns | t2.patterns)
411
423
  end
412
424
 
413
- if t1.is_a?(Types::PEnumType) && t2.is_a?(Types::PEnumType)
425
+ if t1.is_a?(PEnumType) && t2.is_a?(PEnumType)
414
426
  # The common type is one that complies with either set
415
- return Types::PEnumType.new(t1.values | t2.values)
427
+ return PEnumType.new(t1.values | t2.values)
416
428
  end
417
429
 
418
- if t1.is_a?(Types::PVariantType) && t2.is_a?(Types::PVariantType)
430
+ if t1.is_a?(PVariantType) && t2.is_a?(PVariantType)
419
431
  # The common type is one that complies with either set
420
- return Types::PVariantType.new(t1.types | t2.types)
432
+ return PVariantType.new(t1.types | t2.types)
421
433
  end
422
434
 
423
- if t1.is_a?(Types::PRegexpType) && t2.is_a?(Types::PRegexpType)
435
+ if t1.is_a?(PRegexpType) && t2.is_a?(PRegexpType)
424
436
  # if they were identical, the general rule would return a parameterized regexp
425
437
  # since they were not, the result is a generic regexp type
426
- return Types::PPatternType::DEFAULT
438
+ return PPatternType::DEFAULT
427
439
  end
428
440
 
429
- if t1.is_a?(Types::PCallableType) && t2.is_a?(Types::PCallableType)
441
+ if t1.is_a?(PCallableType) && t2.is_a?(PCallableType)
430
442
  # They do not have the same signature, and one is not assignable to the other,
431
443
  # what remains is the most general form of Callable
432
- return Types::PCallableType::DEFAULT
444
+ return PCallableType::DEFAULT
433
445
  end
434
446
 
435
447
  # Common abstract types, from most specific to most general
436
448
  if common_numeric?(t1, t2)
437
- return Types::PNumericType::DEFAULT
449
+ return PNumericType::DEFAULT
438
450
  end
439
451
 
440
452
  if common_scalar?(t1, t2)
441
- return Types::PScalarType::DEFAULT
453
+ return PScalarType::DEFAULT
442
454
  end
443
455
 
444
456
  if common_data?(t1,t2)
445
- return Types::PDataType::DEFAULT
457
+ return PDataType::DEFAULT
446
458
  end
447
459
 
448
460
  # Meta types Type[Integer] + Type[String] => Type[Data]
449
- if t1.is_a?(Types::PType) && t2.is_a?(Types::PType)
450
- return Types::PType.new(common_type(t1.type, t2.type))
461
+ if t1.is_a?(PType) && t2.is_a?(PType)
462
+ return PType.new(common_type(t1.type, t2.type))
451
463
  end
452
464
 
453
465
  # If both are Runtime types
454
- if t1.is_a?(Types::PRuntimeType) && t2.is_a?(Types::PRuntimeType)
466
+ if t1.is_a?(PRuntimeType) && t2.is_a?(PRuntimeType)
455
467
  if t1.runtime == t2.runtime && t1.runtime_type_name == t2.runtime_type_name
456
468
  return t1
457
469
  end
458
470
  # finding the common super class requires that names are resolved to class
459
471
  # NOTE: This only supports runtime type of :ruby
460
- c1 = Types::ClassLoader.provide_from_type(t1)
461
- c2 = Types::ClassLoader.provide_from_type(t2)
472
+ c1 = ClassLoader.provide_from_type(t1)
473
+ c2 = ClassLoader.provide_from_type(t2)
462
474
  if c1 && c2
463
475
  c2_superclasses = superclasses(c2)
464
476
  superclasses(c1).each do|c1_super|
465
477
  c2_superclasses.each do |c2_super|
466
478
  if c1_super == c2_super
467
- return Types::PRuntimeType.new(:ruby, c1_super.name)
479
+ return PRuntimeType.new(:ruby, c1_super.name)
468
480
  end
469
481
  end
470
482
  end
@@ -472,7 +484,7 @@ class Puppet::Pops::Types::TypeCalculator
472
484
  end
473
485
 
474
486
  # They better both be Any type, or the wrong thing was asked and nil is returned
475
- t1.is_a?(Types::PAnyType) && t2.is_a?(Types::PAnyType) ? Types::PAnyType::DEFAULT : nil
487
+ t1.is_a?(PAnyType) && t2.is_a?(PAnyType) ? PAnyType::DEFAULT : nil
476
488
  end
477
489
 
478
490
  # Produces the superclasses of the given class, including the class
@@ -489,20 +501,16 @@ class Puppet::Pops::Types::TypeCalculator
489
501
  # @api public
490
502
  #
491
503
  def string(t)
492
- if t.is_a?(Module)
493
- t = type(t)
494
- end
495
- @@string_visitor.visit_this_0(self, t)
504
+ Puppet.deprecation_warning('TypeCalculator.string is deprecated. Use TypeFormatter')
505
+ TypeFormatter.singleton.string(t)
496
506
  end
497
507
 
498
508
  # Produces a debug string representing the type (possibly with more information that the regular string format)
499
509
  # @api public
500
510
  #
501
511
  def debug_string(t)
502
- if t.is_a?(Module)
503
- t = type(t)
504
- end
505
- @@inspect_visitor.visit_this_0(self, t)
512
+ Puppet.deprecation_warning('TypeCalculator.debug_string is deprecated. Use TypeFormatter')
513
+ TypeFormatter.singleton.debug_string(t)
506
514
  end
507
515
 
508
516
 
@@ -524,7 +532,7 @@ class Puppet::Pops::Types::TypeCalculator
524
532
  # @api private
525
533
  #
526
534
  def infer_Module(o)
527
- Types::PType::new(Types::PRuntimeType.new(:ruby, o.name))
535
+ PType::new(PRuntimeType.new(:ruby, o.name))
528
536
  end
529
537
 
530
538
  # @api private
@@ -532,6 +540,11 @@ class Puppet::Pops::Types::TypeCalculator
532
540
  o.type
533
541
  end
534
542
 
543
+ # @api private
544
+ def infer_Iterator(o)
545
+ PIteratorType.new(o.element_type)
546
+ end
547
+
535
548
  # @api private
536
549
  def infer_Function(o)
537
550
  o.class.dispatcher.to_type
@@ -539,14 +552,14 @@ class Puppet::Pops::Types::TypeCalculator
539
552
 
540
553
  # @api private
541
554
  def infer_Object(o)
542
- Types::PRuntimeType.new(:ruby, o.class.name)
555
+ PRuntimeType.new(:ruby, o.class.name)
543
556
  end
544
557
 
545
558
  # The type of all types is PType
546
559
  # @api private
547
560
  #
548
561
  def infer_PAnyType(o)
549
- Types::PType.new(o)
562
+ PType.new(o)
550
563
  end
551
564
 
552
565
  # The type of all types is PType
@@ -554,32 +567,32 @@ class Puppet::Pops::Types::TypeCalculator
554
567
  # @api private
555
568
  #
556
569
  def infer_PType(o)
557
- Types::PType.new(o)
570
+ PType.new(o)
558
571
  end
559
572
 
560
573
  # @api private
561
574
  def infer_String(o)
562
- Types::PStringType.new(size_as_type(o), [o])
575
+ PStringType.new(size_as_type(o), [o])
563
576
  end
564
577
 
565
578
  # @api private
566
579
  def infer_Float(o)
567
- Types::PFloatType.new(o, o)
580
+ PFloatType.new(o, o)
568
581
  end
569
582
 
570
583
  # @api private
571
584
  def infer_Integer(o)
572
- Types::PIntegerType.new(o, o)
585
+ PIntegerType.new(o, o)
573
586
  end
574
587
 
575
588
  # @api private
576
589
  def infer_Regexp(o)
577
- Types::PRegexpType.new(o.source)
590
+ PRegexpType.new(o.source)
578
591
  end
579
592
 
580
593
  # @api private
581
594
  def infer_NilClass(o)
582
- Types::PUndefType::DEFAULT
595
+ PUndefType::DEFAULT
583
596
  end
584
597
 
585
598
  # @api private
@@ -591,16 +604,16 @@ class Puppet::Pops::Types::TypeCalculator
591
604
  case p[0]
592
605
  when :rest
593
606
  max = :default
594
- break Types::PAnyType::DEFAULT
607
+ break PAnyType::DEFAULT
595
608
  when :req
596
609
  min += 1
597
610
  end
598
611
  max += 1
599
- Types::PAnyType::DEFAULT
612
+ PAnyType::DEFAULT
600
613
  end
601
614
  mapped_types << min
602
615
  mapped_types << max
603
- Types::TypeFactory.callable(*mapped_types)
616
+ TypeFactory.callable(*mapped_types)
604
617
  end
605
618
 
606
619
  # @api private
@@ -613,7 +626,9 @@ class Puppet::Pops::Types::TypeCalculator
613
626
  def infer_Symbol(o)
614
627
  case o
615
628
  when :default
616
- Types::PDefaultType::DEFAULT
629
+ PDefaultType::DEFAULT
630
+ when :undef
631
+ PUndefType::DEFAULT
617
632
  else
618
633
  infer_Object(o)
619
634
  end
@@ -621,12 +636,12 @@ class Puppet::Pops::Types::TypeCalculator
621
636
 
622
637
  # @api private
623
638
  def infer_TrueClass(o)
624
- Types::PBooleanType::DEFAULT
639
+ PBooleanType::DEFAULT
625
640
  end
626
641
 
627
642
  # @api private
628
643
  def infer_FalseClass(o)
629
- Types::PBooleanType::DEFAULT
644
+ PBooleanType::DEFAULT
630
645
  end
631
646
 
632
647
  # @api private
@@ -637,32 +652,32 @@ class Puppet::Pops::Types::TypeCalculator
637
652
  # A mapping must be made to empty string. A nil value will result in an error later
638
653
  title = o.title
639
654
  title = '' if :undef == title
640
- Types::PType.new(Types::PResourceType.new(o.type.to_s.downcase, title))
655
+ PType.new(PResourceType.new(o.type.to_s.downcase, title))
641
656
  end
642
657
 
643
658
  # @api private
644
659
  def infer_Array(o)
645
660
  if o.empty?
646
- Types::PArrayType::EMPTY
661
+ PArrayType::EMPTY
647
662
  else
648
- Types::PArrayType.new(infer_and_reduce_type(o), size_as_type(o))
663
+ PArrayType.new(infer_and_reduce_type(o), size_as_type(o))
649
664
  end
650
665
  end
651
666
 
652
667
  # @api private
653
668
  def infer_Hash(o)
654
669
  if o.empty?
655
- Types::PHashType::EMPTY
670
+ PHashType::EMPTY
656
671
  else
657
672
  ktype = infer_and_reduce_type(o.keys)
658
673
  etype = infer_and_reduce_type(o.values)
659
- Types::PHashType.new(ktype, etype, size_as_type(o))
674
+ PHashType.new(ktype, etype, size_as_type(o))
660
675
  end
661
676
  end
662
677
 
663
678
  def size_as_type(collection)
664
679
  size = collection.size
665
- Types::PIntegerType.new(size, size)
680
+ PIntegerType.new(size, size)
666
681
  end
667
682
 
668
683
  # Common case for everything that intrinsically only has a single type
@@ -672,26 +687,26 @@ class Puppet::Pops::Types::TypeCalculator
672
687
 
673
688
  def infer_set_Array(o)
674
689
  if o.empty?
675
- Types::PArrayType::EMPTY
690
+ PArrayType::EMPTY
676
691
  else
677
- Types::PTupleType.new(o.map {|x| infer_set(x) })
692
+ PTupleType.new(o.map {|x| infer_set(x) })
678
693
  end
679
694
  end
680
695
 
681
696
  def infer_set_Hash(o)
682
697
  if o.empty?
683
- Types::PHashType::EMPTY
684
- elsif o.keys.all? {|k| Types::PStringType::NON_EMPTY.instance?(k) }
685
- Types::PStructType.new(o.each_pair.map { |k,v| Types::PStructElement.new(Types::PStringType.new(nil, [k]), infer_set(v)) })
698
+ PHashType::EMPTY
699
+ elsif o.keys.all? {|k| PStringType::NON_EMPTY.instance?(k) }
700
+ PStructType.new(o.each_pair.map { |k,v| PStructElement.new(PStringType.new(nil, [k]), infer_set(v)) })
686
701
  else
687
- ktype = Types::PVariantType.new(o.keys.map {|k| infer_set(k) })
688
- etype = Types::PVariantType.new(o.values.map {|e| infer_set(e) })
689
- Types::PHashType.new(unwrap_single_variant(ktype), unwrap_single_variant(etype), size_as_type(o))
702
+ ktype = PVariantType.new(o.keys.map {|k| infer_set(k) })
703
+ etype = PVariantType.new(o.values.map {|e| infer_set(e) })
704
+ PHashType.new(unwrap_single_variant(ktype), unwrap_single_variant(etype), size_as_type(o))
690
705
  end
691
706
  end
692
707
 
693
708
  def unwrap_single_variant(possible_variant)
694
- if possible_variant.is_a?(Types::PVariantType) && possible_variant.types.size == 1
709
+ if possible_variant.is_a?(PVariantType) && possible_variant.types.size == 1
695
710
  possible_variant.types[0]
696
711
  else
697
712
  possible_variant
@@ -708,17 +723,13 @@ class Puppet::Pops::Types::TypeCalculator
708
723
  from = range.from
709
724
  to = range.to
710
725
  x = from.nil? ? 1 : from
711
- y = to.nil? ? Float::INFINITY : to
712
- if x < y
713
- [x, y]
714
- else
715
- [y, x]
716
- end
726
+ y = to.nil? ? TheInfinity : to
727
+ [x, y]
717
728
  end
718
729
 
719
730
  # @api private
720
731
  def self.is_kind_of_callable?(t, optional = true)
721
- t.is_a?(Types::PAnyType) && t.kind_of_callable?(optional)
732
+ t.is_a?(PAnyType) && t.kind_of_callable?(optional)
722
733
  end
723
734
 
724
735
  def max(a,b)
@@ -748,260 +759,6 @@ class Puppet::Pops::Types::TypeCalculator
748
759
  end
749
760
  end
750
761
 
751
- # @api private
752
- def debug_string_Object(t)
753
- string(t)
754
- end
755
-
756
- # @api private
757
- def string_PType(t)
758
- if t.type.nil?
759
- 'Type'
760
- else
761
- "Type[#{string(t.type)}]"
762
- end
763
- end
764
-
765
- # @api private
766
- def string_NilClass(t) ; '?' ; end
767
-
768
- # @api private
769
- def string_String(t) ; t ; end
770
-
771
- # @api private
772
- def string_Symbol(t) ; t.to_s ; end
773
-
774
- def string_PAnyType(t) ; 'Any'; end
775
-
776
- # @api private
777
- def string_PUndefType(t) ; 'Undef' ; end
778
-
779
- # @api private
780
- def string_PDefaultType(t) ; 'Default' ; end
781
-
782
- # @api private
783
- def string_PBooleanType(t) ; 'Boolean'; end
784
-
785
- # @api private
786
- def string_PScalarType(t) ; 'Scalar'; end
787
-
788
- # @api private
789
- def string_PDataType(t) ; 'Data'; end
790
-
791
- # @api private
792
- def string_PNumericType(t) ; 'Numeric'; end
793
-
794
- # @api private
795
- def string_PIntegerType(t)
796
- range = range_array_part(t)
797
- if range.empty?
798
- 'Integer'
799
- else
800
- "Integer[#{range.join(', ')}]"
801
- end
802
- end
803
-
804
- # Produces a string from an Integer range type that is used inside other type strings
805
- # @api private
806
- def range_array_part(t)
807
- return [] if t.nil? || t.unbounded?
808
- [t.from.nil? ? 'default' : t.from , t.to.nil? ? 'default' : t.to ]
809
- end
810
-
811
- # @api private
812
- def string_PFloatType(t)
813
- range = range_array_part(t)
814
- if range.empty?
815
- 'Float'
816
- else
817
- "Float[#{range.join(', ')}]"
818
- end
819
- end
820
-
821
- # @api private
822
- def string_PRegexpType(t)
823
- t.pattern.nil? ? 'Regexp' : "Regexp[#{t.regexp.inspect}]"
824
- end
825
-
826
- # @api private
827
- def string_PStringType(t)
828
- # skip values in regular output - see debug_string
829
- range = range_array_part(t.size_type)
830
- if range.empty?
831
- 'String'
832
- else
833
- "String[#{range.join(', ')}]"
834
- end
835
- end
836
-
837
- # @api private
838
- def debug_string_PStringType(t)
839
- range = range_array_part(t.size_type)
840
- range_part = range.empty? ? '' : '[' << range.join(' ,') << '], '
841
- 'String[' << range_part << (t.values.map {|s| "'#{s}'" }).join(', ') << ']'
842
- end
843
-
844
- # @api private
845
- def string_PEnumType(t)
846
- return 'Enum' if t.values.empty?
847
- 'Enum[' << t.values.map {|s| "'#{s}'" }.join(', ') << ']'
848
- end
849
-
850
- # @api private
851
- def string_PVariantType(t)
852
- return 'Variant' if t.types.empty?
853
- 'Variant[' << t.types.map {|t2| string(t2) }.join(', ') << ']'
854
- end
855
-
856
- # @api private
857
- def string_PTupleType(t)
858
- range = range_array_part(t.size_type)
859
- return 'Tuple' if t.types.empty?
860
- s = 'Tuple[' << t.types.map {|t2| string(t2) }.join(', ')
861
- unless range.empty?
862
- s << ', ' << range.join(', ')
863
- end
864
- s << ']'
865
- s
866
- end
867
-
868
- # @api private
869
- def string_PCallableType(t)
870
- # generic
871
- return 'Callable' if t.param_types.nil?
872
-
873
- if t.param_types.types.empty?
874
- range = [0, 0]
875
- else
876
- range = range_array_part(t.param_types.size_type)
877
- end
878
- # translate to string, and skip Unit types
879
- types = t.param_types.types.map {|t2| string(t2) unless t2.class == Types::PUnitType }.compact
880
-
881
- s = 'Callable[' << types.join(', ')
882
- unless range.empty?
883
- (s << ', ') unless types.empty?
884
- s << range.join(', ')
885
- end
886
- # Add block T last (after min, max) if present)
887
- #
888
- unless t.block_type.nil?
889
- (s << ', ') unless types.empty? && range.empty?
890
- s << string(t.block_type)
891
- end
892
- s << ']'
893
- s
894
- end
895
-
896
- # @api private
897
- def string_PStructType(t)
898
- return 'Struct' if t.elements.empty?
899
- 'Struct[{' << t.elements.map {|element| string(element) }.join(', ') << '}]'
900
- end
901
-
902
- def string_PStructElement(t)
903
- k = t.key_type
904
- value_optional = t.value_type.assignable?(Types::PUndefType::DEFAULT)
905
- key_string =
906
- if k.is_a?(Types::POptionalType)
907
- # Output as literal String
908
- value_optional ? "'#{t.name}'" : string(k)
909
- else
910
- value_optional ? "NotUndef['#{t.name}']" : "'#{t.name}'"
911
- end
912
- "#{key_string}=>#{string(t.value_type)}"
913
- end
914
-
915
- # @api private
916
- def string_PPatternType(t)
917
- return 'Pattern' if t.patterns.empty?
918
- 'Pattern[' << t.patterns.map {|s| "#{s.regexp.inspect}" }.join(', ') << ']'
919
- end
920
-
921
- # @api private
922
- def string_PCollectionType(t)
923
- range = range_array_part(t.size_type)
924
- if range.empty?
925
- 'Collection'
926
- else
927
- "Collection[#{range.join(', ')}]"
928
- end
929
- end
930
-
931
- # @api private
932
- def string_PUnitType(t)
933
- 'Unit'
934
- end
935
-
936
- # @api private
937
- def string_PRuntimeType(t) ; "Runtime[#{string(t.runtime)}, #{string(t.runtime_type_name)}]" ; end
938
-
939
- # @api private
940
- def string_PArrayType(t)
941
- parts = [string(t.element_type)] + range_array_part(t.size_type)
942
- "Array[#{parts.join(', ')}]"
943
- end
944
-
945
- # @api private
946
- def string_PHashType(t)
947
- parts = [string(t.key_type), string(t.element_type)] + range_array_part(t.size_type)
948
- "Hash[#{parts.join(', ')}]"
949
- end
950
-
951
- # @api private
952
- def string_PCatalogEntryType(t)
953
- 'CatalogEntry'
954
- end
955
-
956
- # @api private
957
- def string_PHostClassType(t)
958
- if t.class_name
959
- "Class[#{t.class_name}]"
960
- else
961
- 'Class'
962
- end
963
- end
964
-
965
- # @api private
966
- def string_PResourceType(t)
967
- if t.type_name
968
- if t.title
969
- "#{capitalize_segments(t.type_name)}['#{t.title}']"
970
- else
971
- capitalize_segments(t.type_name)
972
- end
973
- else
974
- 'Resource'
975
- end
976
- end
977
-
978
- # @api private
979
- def string_PNotUndefType(t)
980
- contained_type = t.type
981
- if contained_type.nil? || contained_type.class == Puppet::Pops::Types::PAnyType
982
- 'NotUndef'
983
- else
984
- if contained_type.is_a?(Puppet::Pops::Types::PStringType) && contained_type.values.size == 1
985
- "NotUndef['#{contained_type.values[0]}']"
986
- else
987
- "NotUndef[#{string(contained_type)}]"
988
- end
989
- end
990
- end
991
-
992
- def string_POptionalType(t)
993
- optional_type = t.optional_type
994
- if optional_type.nil?
995
- 'Optional'
996
- else
997
- if optional_type.is_a?(Puppet::Pops::Types::PStringType) && optional_type.values.size == 1
998
- "Optional['#{optional_type.values[0]}']"
999
- else
1000
- "Optional[#{string(optional_type)}]"
1001
- end
1002
- end
1003
- end
1004
-
1005
762
  # Debugging to_s to reduce the amount of output
1006
763
  def to_s
1007
764
  '[a TypeCalculator]'
@@ -1009,22 +766,18 @@ class Puppet::Pops::Types::TypeCalculator
1009
766
 
1010
767
  private
1011
768
 
1012
- NAME_SEGMENT_SEPARATOR = '::'.freeze
1013
-
1014
- def capitalize_segments(s)
1015
- s.split(NAME_SEGMENT_SEPARATOR).map(&:capitalize).join(NAME_SEGMENT_SEPARATOR)
1016
- end
1017
-
1018
769
  def common_data?(t1, t2)
1019
- Types::PDataType::DEFAULT.assignable?(t1) && Types::PDataType::DEFAULT.assignable?(t2)
770
+ PDataType::DEFAULT.assignable?(t1) && PDataType::DEFAULT.assignable?(t2)
1020
771
  end
1021
772
 
1022
773
  def common_scalar?(t1, t2)
1023
- Types::PScalarType::DEFAULT.assignable?(t1) && Types::PScalarType::DEFAULT.assignable?(t2)
774
+ PScalarType::DEFAULT.assignable?(t1) && PScalarType::DEFAULT.assignable?(t2)
1024
775
  end
1025
776
 
1026
777
  def common_numeric?(t1, t2)
1027
- Types::PNumericType::DEFAULT.assignable?(t1) && Types::PNumericType::DEFAULT.assignable?(t2)
778
+ PNumericType::DEFAULT.assignable?(t1) && PNumericType::DEFAULT.assignable?(t2)
1028
779
  end
1029
780
 
1030
781
  end
782
+ end
783
+ end