puppet 4.3.2-x86-mingw32 → 4.4.0-x86-mingw32

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

Potentially problematic release.


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

Files changed (487) hide show
  1. checksums.yaml +4 -4
  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/debian/README.source +1 -1
  9. data/ext/debian/control +1 -1
  10. data/ext/debian/copyright +4 -4
  11. data/ext/debian/puppetmaster.README.debian +11 -9
  12. data/ext/emacs/puppet-mode.el +1 -1
  13. data/ext/envpuppet +2 -2
  14. data/ext/ips/puppetagent.xml +1 -1
  15. data/ext/ips/puppetmaster.xml +1 -1
  16. data/ext/project_data.yaml +8 -0
  17. data/ext/puppet-test +3 -3
  18. data/ext/rack/example-passenger-vhost.conf +1 -1
  19. data/ext/redhat/puppet.spec.erb +2 -2
  20. data/ext/regexp_nodes/regexp_nodes.rb +1 -1
  21. data/ext/solaris/pkginfo +1 -1
  22. data/ext/solaris/smf/puppet.xml +1 -1
  23. data/ext/suse/puppet.spec +2 -2
  24. data/ext/upload_facts.rb +1 -1
  25. data/ext/windows/puppet_interactive.bat +6 -0
  26. data/ext/windows/puppet_shell.bat +9 -0
  27. data/ext/windows/run_puppet_interactive.bat +9 -0
  28. data/ext/yaml_nodes.rb +1 -1
  29. data/install.rb +30 -20
  30. data/lib/puppet/agent.rb +1 -1
  31. data/lib/puppet/application/agent.rb +4 -2
  32. data/lib/puppet/application/apply.rb +7 -4
  33. data/lib/puppet/application/cert.rb +1 -1
  34. data/lib/puppet/application/device.rb +1 -1
  35. data/lib/puppet/application/filebucket.rb +1 -1
  36. data/lib/puppet/application/inspect.rb +1 -1
  37. data/lib/puppet/application/lookup.rb +4 -4
  38. data/lib/puppet/application/master.rb +2 -2
  39. data/lib/puppet/application/resource.rb +1 -1
  40. data/lib/puppet/configurer.rb +100 -22
  41. data/lib/puppet/data_providers/hiera_config.rb +28 -3
  42. data/lib/puppet/data_providers/hiera_interpolate.rb +30 -15
  43. data/lib/puppet/data_providers/hiera_support.rb +1 -1
  44. data/lib/puppet/data_providers/json_data_provider_factory.rb +2 -2
  45. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -2
  46. data/lib/puppet/defaults.rb +65 -19
  47. data/lib/puppet/environments.rb +3 -1
  48. data/lib/puppet/face/config.rb +1 -1
  49. data/lib/puppet/face/epp.rb +1 -1
  50. data/lib/puppet/face/help/man.erb +1 -1
  51. data/lib/puppet/face/module/install.rb +6 -6
  52. data/lib/puppet/face/parser.rb +12 -9
  53. data/lib/puppet/face/status.rb +2 -1
  54. data/lib/puppet/feature/cfpropertylist.rb +3 -0
  55. data/lib/puppet/feature/telnet.rb +9 -0
  56. data/lib/puppet/file_serving/http_metadata.rb +46 -0
  57. data/lib/puppet/file_serving/metadata.rb +18 -2
  58. data/lib/puppet/file_serving/terminus_selector.rb +2 -0
  59. data/lib/puppet/file_system.rb +2 -2
  60. data/lib/puppet/file_system/file_impl.rb +2 -2
  61. data/lib/puppet/file_system/memory_impl.rb +1 -1
  62. data/lib/puppet/file_system/uniquefile.rb +1 -1
  63. data/lib/puppet/forge.rb +1 -1
  64. data/lib/puppet/forge/repository.rb +1 -31
  65. data/lib/puppet/functions.rb +45 -6
  66. data/lib/puppet/functions/assert_type.rb +9 -9
  67. data/lib/puppet/functions/each.rb +5 -13
  68. data/lib/puppet/functions/filter.rb +5 -14
  69. data/lib/puppet/functions/map.rb +6 -14
  70. data/lib/puppet/functions/reduce.rb +5 -13
  71. data/lib/puppet/functions/reverse_each.rb +82 -0
  72. data/lib/puppet/functions/scanf.rb +15 -18
  73. data/lib/puppet/functions/slice.rb +22 -36
  74. data/lib/puppet/functions/split.rb +2 -2
  75. data/lib/puppet/functions/step.rb +88 -0
  76. data/lib/puppet/functions/type.rb +70 -0
  77. data/lib/puppet/graph/rb_tree_map.rb +1 -1
  78. data/lib/puppet/indirector/catalog/compiler.rb +188 -5
  79. data/lib/puppet/indirector/file_content/http.rb +15 -0
  80. data/lib/puppet/indirector/file_metadata/http.rb +27 -0
  81. data/lib/puppet/indirector/generic_http.rb +16 -0
  82. data/lib/puppet/indirector/node/exec.rb +1 -1
  83. data/lib/puppet/indirector/node/ldap.rb +1 -1
  84. data/lib/puppet/indirector/rest.rb +2 -1
  85. data/lib/puppet/info_service/class_information_service.rb +13 -12
  86. data/lib/puppet/loaders.rb +1 -0
  87. data/lib/puppet/module.rb +3 -0
  88. data/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +9 -2
  89. data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +1 -1
  90. data/lib/puppet/module_tool/skeleton/templates/generator/tests/init.pp.erb +2 -2
  91. data/lib/puppet/module_tool/tar/mini.rb +3 -3
  92. data/lib/puppet/network/http/pool.rb +9 -0
  93. data/lib/puppet/node.rb +1 -1
  94. data/lib/puppet/node/environment.rb +11 -2
  95. data/lib/puppet/parser/ast/pops_bridge.rb +19 -22
  96. data/lib/puppet/parser/compiler.rb +3 -3
  97. data/lib/puppet/parser/environment_compiler.rb +0 -1
  98. data/lib/puppet/parser/functions.rb +28 -16
  99. data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
  100. data/lib/puppet/parser/functions/inline_template.rb +1 -1
  101. data/lib/puppet/parser/functions/map.rb +1 -1
  102. data/lib/puppet/parser/functions/scanf.rb +15 -26
  103. data/lib/puppet/parser/functions/slice.rb +17 -24
  104. data/lib/puppet/parser/functions/split.rb +1 -1
  105. data/lib/puppet/parser/resource.rb +19 -17
  106. data/lib/puppet/parser/scope.rb +176 -5
  107. data/lib/puppet/plugins/data_providers/data_provider.rb +54 -13
  108. data/lib/puppet/pops.rb +0 -8
  109. data/lib/puppet/pops/adaptable.rb +4 -1
  110. data/lib/puppet/pops/adapters.rb +38 -13
  111. data/lib/puppet/pops/binder/binder.rb +21 -17
  112. data/lib/puppet/pops/binder/binder_issues.rb +8 -6
  113. data/lib/puppet/pops/binder/bindings_checker.rb +12 -8
  114. data/lib/puppet/pops/binder/bindings_composer.rb +16 -12
  115. data/lib/puppet/pops/binder/bindings_factory.rb +108 -104
  116. data/lib/puppet/pops/binder/bindings_model.rb +49 -47
  117. data/lib/puppet/pops/binder/config/diagnostic_producer.rb +10 -6
  118. data/lib/puppet/pops/binder/injector.rb +53 -48
  119. data/lib/puppet/pops/binder/key_factory.rb +10 -6
  120. data/lib/puppet/pops/binder/producers.rb +67 -62
  121. data/lib/puppet/pops/evaluator/access_operator.rb +95 -93
  122. data/lib/puppet/pops/evaluator/closure.rb +84 -68
  123. data/lib/puppet/pops/evaluator/collector_transformer.rb +18 -14
  124. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +0 -1
  125. data/lib/puppet/pops/evaluator/compare_operator.rb +13 -9
  126. data/lib/puppet/pops/evaluator/epp_evaluator.rb +9 -8
  127. data/lib/puppet/pops/evaluator/evaluator_impl.rb +78 -76
  128. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +85 -0
  129. data/lib/puppet/pops/evaluator/relationship_operator.rb +13 -11
  130. data/lib/puppet/pops/evaluator/runtime3_converter.rb +5 -0
  131. data/lib/puppet/pops/evaluator/runtime3_support.rb +41 -45
  132. data/lib/puppet/pops/issue_reporter.rb +6 -4
  133. data/lib/puppet/pops/issues.rb +34 -11
  134. data/lib/puppet/pops/loader/base_loader.rb +1 -1
  135. data/lib/puppet/pops/loader/loader.rb +1 -1
  136. data/lib/puppet/pops/loader/loader_paths.rb +15 -0
  137. data/lib/puppet/pops/loader/module_loaders.rb +17 -13
  138. data/lib/puppet/pops/loader/puppet_function_instantiator.rb +16 -12
  139. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +16 -3
  140. data/lib/puppet/pops/loader/type_definition_instantiator.rb +55 -0
  141. data/lib/puppet/pops/loaders.rb +51 -9
  142. data/lib/puppet/pops/lookup.rb +14 -12
  143. data/lib/puppet/pops/merge_strategy.rb +16 -19
  144. data/lib/puppet/pops/model/factory.rb +26 -2
  145. data/lib/puppet/pops/model/model.rb +8 -8
  146. data/lib/puppet/pops/model/model_label_provider.rb +13 -7
  147. data/lib/puppet/pops/model/model_meta.rb +17 -0
  148. data/lib/puppet/pops/model/model_tree_dumper.rb +8 -0
  149. data/lib/puppet/pops/parser/egrammar.ra +38 -14
  150. data/lib/puppet/pops/parser/eparser.rb +1353 -1276
  151. data/lib/puppet/pops/parser/epp_support.rb +11 -7
  152. data/lib/puppet/pops/parser/evaluating_parser.rb +14 -10
  153. data/lib/puppet/pops/parser/heredoc_support.rb +15 -11
  154. data/lib/puppet/pops/parser/lexer2.rb +26 -19
  155. data/lib/puppet/pops/parser/lexer_support.rb +85 -7
  156. data/lib/puppet/pops/parser/locator.rb +21 -0
  157. data/lib/puppet/pops/parser/parser_support.rb +19 -16
  158. data/lib/puppet/pops/parser/slurp_support.rb +11 -7
  159. data/lib/puppet/pops/types/class_loader.rb +23 -19
  160. data/lib/puppet/pops/types/enumeration.rb +9 -26
  161. data/lib/puppet/pops/types/iterable.rb +308 -0
  162. data/lib/puppet/pops/types/recursion_guard.rb +82 -0
  163. data/lib/puppet/pops/types/type_acceptor.rb +25 -0
  164. data/lib/puppet/pops/types/type_asserter.rb +10 -9
  165. data/lib/puppet/pops/types/type_calculator.rb +138 -381
  166. data/lib/puppet/pops/types/type_factory.rb +91 -57
  167. data/lib/puppet/pops/types/type_formatter.rb +334 -0
  168. data/lib/puppet/pops/types/type_mismatch_describer.rb +226 -59
  169. data/lib/puppet/pops/types/type_parser.rb +159 -112
  170. data/lib/puppet/pops/types/types.rb +2057 -1247
  171. data/lib/puppet/pops/utils.rb +11 -10
  172. data/lib/puppet/pops/validation.rb +11 -9
  173. data/lib/puppet/pops/validation/checker4_0.rb +83 -55
  174. data/lib/puppet/pops/validation/validator_factory_4_0.rb +8 -4
  175. data/lib/puppet/provider/aixobject.rb +1 -1
  176. data/lib/puppet/provider/augeas/augeas.rb +1 -1
  177. data/lib/puppet/provider/cron/crontab.rb +1 -1
  178. data/lib/puppet/provider/exec/windows.rb +1 -1
  179. data/lib/puppet/provider/macauthorization/macauthorization.rb +10 -9
  180. data/lib/puppet/provider/nameservice/directoryservice.rb +35 -50
  181. data/lib/puppet/provider/package/appdmg.rb +3 -2
  182. data/lib/puppet/provider/package/dnf.rb +1 -1
  183. data/lib/puppet/provider/package/pip.rb +5 -8
  184. data/lib/puppet/provider/package/pip3.rb +1 -1
  185. data/lib/puppet/provider/package/pkg.rb +1 -1
  186. data/lib/puppet/provider/package/pkgdmg.rb +3 -2
  187. data/lib/puppet/provider/package/pkgng.rb +13 -4
  188. data/lib/puppet/provider/package/windows.rb +1 -1
  189. data/lib/puppet/provider/package/yum.rb +1 -1
  190. data/lib/puppet/provider/package/zypper.rb +19 -0
  191. data/lib/puppet/provider/service/debian.rb +2 -2
  192. data/lib/puppet/provider/service/launchd.rb +6 -18
  193. data/lib/puppet/provider/service/systemd.rb +9 -2
  194. data/lib/puppet/provider/sshkey/parsed.rb +1 -1
  195. data/lib/puppet/provider/user/aix.rb +1 -1
  196. data/lib/puppet/provider/user/directoryservice.rb +33 -58
  197. data/lib/puppet/provider/zfs/zfs.rb +1 -1
  198. data/lib/puppet/provider/zpool/zpool.rb +1 -1
  199. data/lib/puppet/reference/configuration.rb +1 -1
  200. data/lib/puppet/reference/providers.rb +1 -1
  201. data/lib/puppet/resource.rb +15 -12
  202. data/lib/puppet/resource/capability_finder.rb +20 -13
  203. data/lib/puppet/resource/catalog.rb +60 -3
  204. data/lib/puppet/resource/status.rb +11 -2
  205. data/lib/puppet/resource/type.rb +28 -38
  206. data/lib/puppet/settings.rb +1 -1
  207. data/lib/puppet/settings/config_file.rb +1 -1
  208. data/lib/puppet/settings/environment_conf.rb +13 -5
  209. data/lib/puppet/ssl/certificate_factory.rb +3 -3
  210. data/lib/puppet/ssl/certificate_request.rb +4 -4
  211. data/lib/puppet/ssl/certificate_signer.rb +1 -1
  212. data/lib/puppet/ssl/validator/default_validator.rb +1 -1
  213. data/lib/puppet/test/test_helper.rb +16 -4
  214. data/lib/puppet/transaction.rb +15 -2
  215. data/lib/puppet/transaction/additional_resource_generator.rb +6 -2
  216. data/lib/puppet/transaction/report.rb +31 -1
  217. data/lib/puppet/transaction/resource_harness.rb +0 -25
  218. data/lib/puppet/type.rb +11 -11
  219. data/lib/puppet/type/augeas.rb +1 -1
  220. data/lib/puppet/type/cron.rb +12 -12
  221. data/lib/puppet/type/file.rb +91 -39
  222. data/lib/puppet/type/file/checksum_value.rb +53 -0
  223. data/lib/puppet/type/file/content.rb +26 -111
  224. data/lib/puppet/type/file/data_sync.rb +84 -0
  225. data/lib/puppet/type/file/ensure.rb +17 -14
  226. data/lib/puppet/type/file/selcontext.rb +1 -1
  227. data/lib/puppet/type/file/source.rb +103 -18
  228. data/lib/puppet/type/filebucket.rb +1 -1
  229. data/lib/puppet/type/interface.rb +8 -3
  230. data/lib/puppet/type/macauthorization.rb +1 -1
  231. data/lib/puppet/type/package.rb +6 -0
  232. data/lib/puppet/type/schedule.rb +1 -1
  233. data/lib/puppet/type/stage.rb +1 -1
  234. data/lib/puppet/type/user.rb +19 -17
  235. data/lib/puppet/type/yumrepo.rb +20 -0
  236. data/lib/puppet/util.rb +109 -22
  237. data/lib/puppet/util/autoload.rb +16 -11
  238. data/lib/puppet/util/checksums.rb +74 -31
  239. data/lib/puppet/util/execution.rb +1 -1
  240. data/lib/puppet/util/http_proxy.rb +72 -0
  241. data/lib/puppet/util/log.rb +2 -0
  242. data/lib/puppet/util/logging.rb +43 -1
  243. data/lib/puppet/util/monkey_patches.rb +2 -2
  244. data/lib/puppet/util/multi_match.rb +51 -0
  245. data/lib/puppet/util/network_device/cisco/device.rb +10 -2
  246. data/lib/puppet/util/network_device/cisco/interface.rb +21 -8
  247. data/lib/puppet/util/network_device/transport/ssh.rb +7 -3
  248. data/lib/puppet/util/network_device/transport/telnet.rb +39 -36
  249. data/lib/puppet/util/plist.rb +130 -0
  250. data/lib/puppet/util/resource_template.rb +1 -1
  251. data/lib/puppet/util/run_mode.rb +2 -2
  252. data/lib/puppet/util/skip_tags.rb +9 -0
  253. data/lib/puppet/util/windows/access_control_entry.rb +1 -1
  254. data/lib/puppet/util/windows/access_control_list.rb +3 -3
  255. data/lib/puppet/util/windows/adsi.rb +4 -4
  256. data/lib/puppet/util/windows/api_types.rb +24 -18
  257. data/lib/puppet/util/windows/com.rb +3 -3
  258. data/lib/puppet/util/windows/error.rb +1 -1
  259. data/lib/puppet/util/windows/file.rb +8 -8
  260. data/lib/puppet/util/windows/principal.rb +23 -14
  261. data/lib/puppet/util/windows/process.rb +78 -11
  262. data/lib/puppet/util/windows/registry.rb +1 -1
  263. data/lib/puppet/util/windows/root_certs.rb +5 -5
  264. data/lib/puppet/util/windows/security.rb +33 -35
  265. data/lib/puppet/util/windows/security_descriptor.rb +1 -1
  266. data/lib/puppet/util/windows/sid.rb +42 -4
  267. data/lib/puppet/util/windows/taskscheduler.rb +15 -15
  268. data/lib/puppet/util/windows/user.rb +10 -10
  269. data/lib/puppet/vendor/deep_merge/deep_merge.gemspec +1 -1
  270. data/lib/puppet/vendor/pathspec/LICENSE +2 -2
  271. data/lib/puppet/vendor/pathspec/README.md +1 -1
  272. data/lib/puppet/vendor/rgen/README.rdoc +1 -1
  273. data/lib/puppet/vendor/semantic/lib/semantic/dependency/module_release.rb +14 -0
  274. data/lib/puppet/version.rb +1 -1
  275. data/lib/semver.rb +17 -1
  276. data/man/man5/puppet.conf.5 +12 -12
  277. data/man/man8/extlookup2hiera.8 +1 -1
  278. data/man/man8/puppet-agent.8 +2 -2
  279. data/man/man8/puppet-apply.8 +2 -2
  280. data/man/man8/puppet-ca.8 +2 -2
  281. data/man/man8/puppet-catalog.8 +2 -2
  282. data/man/man8/puppet-cert.8 +2 -2
  283. data/man/man8/puppet-certificate.8 +2 -2
  284. data/man/man8/puppet-certificate_request.8 +2 -2
  285. data/man/man8/puppet-certificate_revocation_list.8 +2 -2
  286. data/man/man8/puppet-config.8 +3 -3
  287. data/man/man8/puppet-describe.8 +1 -1
  288. data/man/man8/puppet-device.8 +1 -1
  289. data/man/man8/puppet-doc.8 +1 -1
  290. data/man/man8/puppet-epp.8 +2 -2
  291. data/man/man8/puppet-facts.8 +2 -2
  292. data/man/man8/puppet-file.8 +2 -2
  293. data/man/man8/puppet-filebucket.8 +2 -2
  294. data/man/man8/puppet-help.8 +2 -2
  295. data/man/man8/puppet-inspect.8 +2 -2
  296. data/man/man8/puppet-key.8 +2 -2
  297. data/man/man8/puppet-man.8 +2 -2
  298. data/man/man8/puppet-master.8 +2 -2
  299. data/man/man8/puppet-module.8 +9 -9
  300. data/man/man8/puppet-node.8 +2 -2
  301. data/man/man8/puppet-parser.8 +2 -2
  302. data/man/man8/puppet-plugin.8 +2 -2
  303. data/man/man8/puppet-report.8 +2 -2
  304. data/man/man8/puppet-resource.8 +2 -2
  305. data/man/man8/puppet-resource_type.8 +2 -2
  306. data/man/man8/puppet-status.8 +3 -3
  307. data/man/man8/puppet.8 +1 -1
  308. data/spec/fixtures/module.tar.gz +0 -0
  309. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bad_data/lib/puppet/functions/bad_data/data.rb +1 -0
  310. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bad_data/manifests/init.pp +0 -1
  311. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/data/empty.json +0 -0
  312. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/hiera.yaml +5 -0
  313. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/manifests/init.pp +2 -0
  314. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/metadata.json +9 -0
  315. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/data/empty.yaml +1 -0
  316. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/hiera.yaml +5 -0
  317. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/manifests/init.pp +2 -0
  318. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/metadata.json +9 -0
  319. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/data/first.json +2 -1
  320. data/spec/fixtures/unit/module/trailing-comma.json +1 -1
  321. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/manifests/init.pp +3 -1
  322. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/types/zero.pp +1 -0
  323. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/types/withuseeone.pp +1 -0
  324. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/types/withuseezero.pp +1 -0
  325. data/spec/fixtures/unit/provider/package/yum/yum-check-update-broken-notices.txt +187 -0
  326. data/spec/fixtures/unit/provider/sshkey/parsed/sample_with_blank_lines +8 -0
  327. 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
  328. 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
  329. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_update_if_content_differs_on_disk.yml +213 -0
  330. 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
  331. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_no_header_specified.yml +197 -0
  332. 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
  333. 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
  334. data/spec/integration/defaults_spec.rb +14 -2
  335. data/spec/integration/file_system/uniquefile_spec.rb +29 -0
  336. data/spec/integration/module_tool/tar/mini_spec.rb +28 -0
  337. data/spec/integration/node/environment_spec.rb +13 -0
  338. data/spec/integration/parser/dynamic_scoping_spec.rb +67 -0
  339. data/spec/integration/parser/parameter_defaults_spec.rb +336 -0
  340. data/spec/integration/parser/undef_param_spec.rb +8 -0
  341. data/spec/integration/provider/yumrepo_spec.rb +1 -1
  342. data/spec/integration/test/test_helper_spec.rb +28 -0
  343. data/spec/integration/transaction/report_spec.rb +16 -0
  344. data/spec/integration/transaction_spec.rb +11 -0
  345. data/spec/integration/type/file_spec.rb +194 -4
  346. data/spec/integration/type/package_spec.rb +5 -1
  347. data/spec/integration/type/tidy_spec.rb +21 -9
  348. data/spec/integration/util/execution_spec.rb +22 -0
  349. data/spec/integration/util/windows/principal_spec.rb +90 -4
  350. data/spec/integration/util/windows/process_spec.rb +31 -0
  351. data/spec/integration/util/windows/security_spec.rb +6 -6
  352. data/spec/integration/util/windows/user_spec.rb +1 -1
  353. data/spec/integration/util_spec.rb +49 -27
  354. data/spec/lib/puppet_spec/compiler.rb +17 -0
  355. data/spec/lib/puppet_spec/files.rb +2 -2
  356. data/spec/lib/puppet_spec/pops.rb +13 -0
  357. data/spec/shared_behaviours/iterative_functions.rb +1 -1
  358. data/spec/shared_contexts/types_setup.rb +96 -0
  359. data/spec/unit/agent_spec.rb +1 -0
  360. data/spec/unit/application/agent_spec.rb +10 -0
  361. data/spec/unit/application/apply_spec.rb +9 -0
  362. data/spec/unit/configurer/downloader_spec.rb +5 -5
  363. data/spec/unit/configurer_spec.rb +271 -39
  364. data/spec/unit/data_providers/hiera_interpolation_spec.rb +57 -0
  365. data/spec/unit/defaults_spec.rb +15 -0
  366. data/spec/unit/environments_spec.rb +24 -4
  367. data/spec/unit/face/parser_spec.rb +43 -2
  368. data/spec/unit/file_serving/http_metadata_spec.rb +85 -0
  369. data/spec/unit/file_serving/metadata_spec.rb +50 -0
  370. data/spec/unit/file_serving/terminus_selector_spec.rb +12 -2
  371. data/spec/unit/file_system_spec.rb +26 -0
  372. data/spec/unit/functions/assert_type_spec.rb +36 -2
  373. data/spec/unit/functions/defined_spec.rb +2 -2
  374. data/spec/unit/functions/epp_spec.rb +11 -3
  375. data/spec/unit/functions/lookup_spec.rb +58 -13
  376. data/spec/unit/functions/regsubst_spec.rb +1 -1
  377. data/spec/unit/functions/reverse_each_spec.rb +108 -0
  378. data/spec/unit/functions/step_spec.rb +113 -0
  379. data/spec/unit/functions/type_spec.rb +35 -0
  380. data/spec/unit/functions4_spec.rb +61 -5
  381. data/spec/unit/indirector/catalog/compiler_spec.rb +705 -4
  382. data/spec/unit/indirector/file_bucket_file/file_spec.rb +1 -1
  383. data/spec/unit/indirector/indirection_spec.rb +1 -1
  384. data/spec/unit/info_service_spec.rb +94 -32
  385. data/spec/unit/module_spec.rb +14 -0
  386. data/spec/unit/module_tool/applications/builder_spec.rb +4 -4
  387. data/spec/unit/network/authstore_spec.rb +1 -1
  388. data/spec/unit/network/http/connection_spec.rb +1 -0
  389. data/spec/unit/network/http/pool_spec.rb +30 -0
  390. data/spec/unit/node_spec.rb +1 -1
  391. data/spec/unit/parser/compiler_spec.rb +16 -0
  392. data/spec/unit/parser/scope_spec.rb +28 -11
  393. data/spec/unit/pops/evaluator/access_ops_spec.rb +3 -3
  394. data/spec/unit/pops/evaluator/comparison_ops_spec.rb +3 -0
  395. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +7 -1
  396. data/spec/unit/pops/evaluator/evaluator_rspec_helper.rb +4 -4
  397. data/spec/unit/pops/evaluator/json_strict_literal_evaluator_spec.rb +63 -0
  398. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +6 -0
  399. data/spec/unit/pops/loaders/dependency_loader_spec.rb +53 -0
  400. data/spec/unit/pops/loaders/loaders_spec.rb +44 -1
  401. data/spec/unit/pops/parser/lexer2_spec.rb +112 -3
  402. data/spec/unit/pops/parser/parse_calls_spec.rb +8 -0
  403. data/spec/unit/pops/parser/parser_spec.rb +10 -0
  404. data/spec/unit/pops/parser/source_pos_adapter_spec.rb +26 -0
  405. data/spec/unit/pops/types/iterable_spec.rb +262 -0
  406. data/spec/unit/pops/types/recursion_guard_spec.rb +91 -0
  407. data/spec/unit/pops/types/type_acceptor_spec.rb +105 -0
  408. data/spec/unit/pops/types/type_asserter_spec.rb +43 -0
  409. data/spec/unit/pops/types/type_calculator_spec.rb +275 -373
  410. data/spec/unit/pops/types/type_formatter_spec.rb +280 -0
  411. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +152 -0
  412. data/spec/unit/pops/types/type_parser_spec.rb +58 -13
  413. data/spec/unit/pops/types/types_spec.rb +241 -0
  414. data/spec/unit/pops/validator/validator_spec.rb +100 -43
  415. data/spec/unit/provider/cron/parsed_spec.rb +1 -0
  416. data/spec/unit/provider/macauthorization_spec.rb +5 -2
  417. data/spec/unit/provider/nameservice/directoryservice_spec.rb +14 -19
  418. data/spec/unit/provider/package/appdmg_spec.rb +3 -3
  419. data/spec/unit/provider/package/dnf_spec.rb +16 -0
  420. data/spec/unit/provider/package/pip3_spec.rb +60 -42
  421. data/spec/unit/provider/package/pip_spec.rb +47 -34
  422. data/spec/unit/provider/package/pkgdmg_spec.rb +18 -9
  423. data/spec/unit/provider/package/pkgng_spec.rb +4 -2
  424. data/spec/unit/provider/package/yum_spec.rb +11 -0
  425. data/spec/unit/provider/package/zypper_spec.rb +14 -0
  426. data/spec/unit/provider/service/launchd_spec.rb +17 -35
  427. data/spec/unit/provider/service/systemd_spec.rb +7 -0
  428. data/spec/unit/provider/sshkey/parsed_spec.rb +20 -19
  429. data/spec/unit/provider/user/directoryservice_spec.rb +40 -59
  430. data/spec/unit/resource/capability_finder_spec.rb +28 -15
  431. data/spec/unit/resource/catalog_spec.rb +33 -1
  432. data/spec/unit/resource/type_spec.rb +149 -7
  433. data/spec/unit/resource_spec.rb +96 -57
  434. data/spec/unit/settings/environment_conf_spec.rb +18 -1
  435. data/spec/unit/ssl/certificate_revocation_list_spec.rb +3 -3
  436. data/spec/unit/transaction/report_spec.rb +27 -0
  437. data/spec/unit/transaction/resource_harness_spec.rb +0 -47
  438. data/spec/unit/transaction_spec.rb +5 -0
  439. data/spec/unit/type/file/checksum_spec.rb +6 -0
  440. data/spec/unit/type/file/checksum_value_spec.rb +286 -0
  441. data/spec/unit/type/file/content_spec.rb +12 -193
  442. data/spec/unit/type/file/source_spec.rb +211 -119
  443. data/spec/unit/type/file_spec.rb +133 -34
  444. data/spec/unit/type/interface_spec.rb +32 -0
  445. data/spec/unit/type/macauthorization_spec.rb +4 -1
  446. data/spec/unit/type/yumrepo_spec.rb +2 -2
  447. data/spec/unit/util/filetype_spec.rb +1 -1
  448. data/spec/unit/util/http_proxy_spec.rb +2 -2
  449. data/spec/unit/util/log/destinations_spec.rb +0 -2
  450. data/spec/unit/util/logging_spec.rb +69 -0
  451. data/spec/unit/util/multi_match_spec.rb +39 -0
  452. data/spec/unit/util/network_device/cisco/device_spec.rb +253 -216
  453. data/spec/unit/util/network_device/transport/telnet_spec.rb +60 -58
  454. data/spec/unit/util/plist_spec.rb +110 -0
  455. data/spec/unit/util/resource_template_spec.rb +2 -2
  456. data/spec/unit/util/run_mode_spec.rb +27 -3
  457. data/spec/unit/util/windows/adsi_spec.rb +4 -4
  458. data/spec/unit/util/windows/api_types_spec.rb +42 -0
  459. data/spec/unit/util/windows/security_descriptor_spec.rb +3 -3
  460. data/spec/unit/util/windows/sid_spec.rb +1 -1
  461. data/spec/unit/util_spec.rb +123 -13
  462. data/tasks/cfpropertylist.rake +15 -0
  463. metadata +114 -26
  464. data/lib/puppet/vendor/load_plist.rb +0 -1
  465. data/lib/puppet/vendor/plist/CHANGELOG +0 -82
  466. data/lib/puppet/vendor/plist/MIT-LICENSE +0 -21
  467. data/lib/puppet/vendor/plist/PUPPET_README.md +0 -6
  468. data/lib/puppet/vendor/plist/README +0 -36
  469. data/lib/puppet/vendor/plist/Rakefile +0 -144
  470. data/lib/puppet/vendor/plist/docs/USAGE +0 -104
  471. data/lib/puppet/vendor/plist/docs/jamis-template.rb +0 -591
  472. data/lib/puppet/vendor/plist/lib/plist.rb +0 -22
  473. data/lib/puppet/vendor/plist/lib/plist/generator.rb +0 -224
  474. data/lib/puppet/vendor/plist/lib/plist/parser.rb +0 -225
  475. data/lib/puppet/vendor/plist/test/assets/AlbumData.xml +0 -203
  476. data/lib/puppet/vendor/plist/test/assets/Cookies.plist +0 -104
  477. data/lib/puppet/vendor/plist/test/assets/commented.plist +0 -9
  478. data/lib/puppet/vendor/plist/test/assets/example_data.bin +0 -0
  479. data/lib/puppet/vendor/plist/test/assets/example_data.jpg +0 -0
  480. data/lib/puppet/vendor/plist/test/assets/example_data.plist +0 -259
  481. data/lib/puppet/vendor/plist/test/assets/test_data_elements.plist +0 -24
  482. data/lib/puppet/vendor/plist/test/assets/test_empty_key.plist +0 -13
  483. data/lib/puppet/vendor/plist/test/test_data_elements.rb +0 -115
  484. data/lib/puppet/vendor/plist/test/test_generator.rb +0 -59
  485. data/lib/puppet/vendor/plist/test/test_generator_basic_types.rb +0 -58
  486. data/lib/puppet/vendor/plist/test/test_generator_collections.rb +0 -82
  487. data/lib/puppet/vendor/plist/test/test_parser.rb +0 -90
@@ -0,0 +1,82 @@
1
+ module Puppet::Pops
2
+ module Types
3
+ # Keeps track of self recursion of conceptual 'this' and 'that' instances using two separate maps and
4
+ # a state. The class is used when tracking self recursion in two objects ('this' and 'that') simultaneously.
5
+ # A typical example of when this is needed is when testing if 'that' Puppet Type is assignable to 'this'
6
+ # Puppet Type since both types may contain self references.
7
+ #
8
+ # All comparisons are made using the `object_id` of the instance rather than the instance itself.
9
+ #
10
+ # @api private
11
+ class RecursionGuard
12
+ attr_reader :state
13
+
14
+ NO_SELF_RECURSION = 0
15
+ SELF_RECURSION_IN_THIS = 1
16
+ SELF_RECURSION_IN_THAT = 2
17
+ SELF_RECURSION_IN_BOTH = 3
18
+
19
+ def initialize
20
+ @state = NO_SELF_RECURSION
21
+ end
22
+
23
+ # Checks if recursion was detected for the given argument in the 'this' context
24
+ # @param instance [Object] the instance to check
25
+ # @return [Integer] the resulting state
26
+ def recursive_this?(instance)
27
+ this_map[instance.object_id] == true
28
+ end
29
+
30
+ # Checks if recursion was detected for the given argument in the 'that' context
31
+ # @param instance [Object] the instance to check
32
+ # @return [Integer] the resulting state
33
+ def recursive_that?(instance)
34
+ that_map[instance.object_id] == true
35
+ end
36
+
37
+ # Add the given argument as 'this' and return the resulting state
38
+ # @param instance [Object] the instance to add
39
+ # @return [Integer] the resulting state
40
+ def add_this(instance)
41
+ if (@state & SELF_RECURSION_IN_THIS) == 0
42
+ @state = @state | SELF_RECURSION_IN_THIS if map_put(this_map, instance)
43
+ end
44
+ @state
45
+ end
46
+
47
+ # Add the given argument as 'that' and return the resulting state
48
+ # @param instance [Object] the instance to add
49
+ # @return [Integer] the resulting state
50
+ def add_that(instance)
51
+ if (@state & SELF_RECURSION_IN_THAT) == 0
52
+ @state = @state | SELF_RECURSION_IN_THAT if map_put(that_map, instance)
53
+ end
54
+ @state
55
+ end
56
+
57
+ private
58
+
59
+ def map_put(map, o)
60
+ id = o.object_id
61
+ case map[id]
62
+ when true
63
+ true # Recursion already detected
64
+ when false
65
+ map[id] = true
66
+ true # Recursion occured. This was the second time this entry was added
67
+ else
68
+ map[id] = false
69
+ false # First time add. No recursion
70
+ end
71
+ end
72
+
73
+ def this_map
74
+ @this_map ||= {}
75
+ end
76
+
77
+ def that_map
78
+ @that_map ||= {}
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,25 @@
1
+ module Puppet::Pops
2
+ module Types
3
+ # Implements a standard visitor patter for the Puppet Type system.
4
+
5
+ #
6
+ # An instance of this module is passed as an argument to the {PAnyType#accept}
7
+ # method of a Type instance. That type will then use the {TypeAcceptor#visit} callback
8
+ # on the acceptor and then pass the acceptor to the `accept` method of all contained
9
+ # type instances so that the it gets a visit from each one recursively.
10
+ #
11
+ module TypeAcceptor
12
+ # @param type [PAnyType] the type that we accept a visit from
13
+ # @param quard [RecursionGuard] the guard against self recursion
14
+ def visit(type, guard)
15
+ end
16
+ end
17
+
18
+ # An acceptor that does nothing
19
+ class NoopTypeAcceptor
20
+ include TypeAcceptor
21
+
22
+ INSTANCE = NoopTypeAcceptor.new
23
+ end
24
+ end
25
+ end
@@ -5,13 +5,14 @@ module TypeAsserter
5
5
  # Asserts that a type_to_check is assignable to required_type and raises
6
6
  # a {Puppet::ParseError} if that's not the case
7
7
  #
8
- # @param subject [String] String to be prepended to the exception message
8
+ # @param subject [String,Array] String to be prepended to the exception message or Array where the first element is
9
+ # a format string and the rest are arguments to that format string
9
10
  # @param expected_type [PAnyType] Expected type
10
11
  # @param type_to_check [PAnyType] Type to check against the required type
11
12
  # @return The type_to_check argument
12
13
  #
13
14
  # @api public
14
- def self.assert_assignable(subject, expected_type, type_to_check)
15
+ def self.assert_assignable(subject, expected_type, type_to_check, &block)
15
16
  report_type_mismatch(subject, expected_type, type_to_check) unless expected_type.assignable?(type_to_check)
16
17
  type_to_check
17
18
  end
@@ -19,26 +20,26 @@ module TypeAsserter
19
20
  # Asserts that a value is an instance of a given type and raises
20
21
  # a {Puppet::ParseError} if that's not the case
21
22
  #
22
- # @param subject [String] String to be prepended to the exception message
23
+ # @param subject [String,Array] String to be prepended to the exception message or Array where the first element is
24
+ # a format string and the rest are arguments to that format string
23
25
  # @param expected_type [PAnyType] Expected type for the value
24
26
  # @param value [Object] Value to check
25
27
  # @param nil_ok [Boolean] Can be true to allow nil value. Optional and defaults to false
26
28
  # @return The value argument
27
29
  #
28
30
  # @api public
29
- def self.assert_instance_of(subject, expected_type, value, nil_ok = false)
31
+ def self.assert_instance_of(subject, expected_type, value, nil_ok = false, &block)
30
32
  unless value.nil? && nil_ok
31
- report_type_mismatch(subject, expected_type, TypeCalculator.singleton.infer_set(value).generalize) unless expected_type.instance?(value)
33
+ report_type_mismatch(subject, expected_type, TypeCalculator.singleton.infer_set(value).generalize, &block) unless expected_type.instance?(value)
32
34
  end
33
35
  value
34
36
  end
35
37
 
36
38
  def self.report_type_mismatch(subject, expected_type, actual_type)
37
- # Do not give all the details for inferred types - i.e. format as Integer, instead of Integer[n, n] for exact
38
- # value, which is just confusing. (OTOH: may need to revisit, or provide a better "type diff" output).
39
- #
39
+ subject = yield(subject) if block_given?
40
+ subject = subject[0] % subject[1..-1] if subject.is_a?(Array)
40
41
  raise TypeAssertionError.new(
41
- "#{subject} value has wrong type, expected #{expected_type}, actual #{actual_type}", expected_type, actual_type)
42
+ TypeMismatchDescriber.singleton.describe_mismatch("#{subject} has wrong type,", expected_type, actual_type), expected_type, actual_type)
42
43
  end
43
44
  private_class_method :report_type_mismatch
44
45
  end
@@ -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
@@ -714,7 +729,7 @@ class Puppet::Pops::Types::TypeCalculator
714
729
 
715
730
  # @api private
716
731
  def self.is_kind_of_callable?(t, optional = true)
717
- t.is_a?(Types::PAnyType) && t.kind_of_callable?(optional)
732
+ t.is_a?(PAnyType) && t.kind_of_callable?(optional)
718
733
  end
719
734
 
720
735
  def max(a,b)
@@ -744,260 +759,6 @@ class Puppet::Pops::Types::TypeCalculator
744
759
  end
745
760
  end
746
761
 
747
- # @api private
748
- def debug_string_Object(t)
749
- string(t)
750
- end
751
-
752
- # @api private
753
- def string_PType(t)
754
- if t.type.nil?
755
- 'Type'
756
- else
757
- "Type[#{string(t.type)}]"
758
- end
759
- end
760
-
761
- # @api private
762
- def string_NilClass(t) ; '?' ; end
763
-
764
- # @api private
765
- def string_String(t) ; t ; end
766
-
767
- # @api private
768
- def string_Symbol(t) ; t.to_s ; end
769
-
770
- def string_PAnyType(t) ; 'Any'; end
771
-
772
- # @api private
773
- def string_PUndefType(t) ; 'Undef' ; end
774
-
775
- # @api private
776
- def string_PDefaultType(t) ; 'Default' ; end
777
-
778
- # @api private
779
- def string_PBooleanType(t) ; 'Boolean'; end
780
-
781
- # @api private
782
- def string_PScalarType(t) ; 'Scalar'; end
783
-
784
- # @api private
785
- def string_PDataType(t) ; 'Data'; end
786
-
787
- # @api private
788
- def string_PNumericType(t) ; 'Numeric'; end
789
-
790
- # @api private
791
- def string_PIntegerType(t)
792
- range = range_array_part(t)
793
- if range.empty?
794
- 'Integer'
795
- else
796
- "Integer[#{range.join(', ')}]"
797
- end
798
- end
799
-
800
- # Produces a string from an Integer range type that is used inside other type strings
801
- # @api private
802
- def range_array_part(t)
803
- return [] if t.nil? || t.unbounded?
804
- [t.from.nil? ? 'default' : t.from , t.to.nil? ? 'default' : t.to ]
805
- end
806
-
807
- # @api private
808
- def string_PFloatType(t)
809
- range = range_array_part(t)
810
- if range.empty?
811
- 'Float'
812
- else
813
- "Float[#{range.join(', ')}]"
814
- end
815
- end
816
-
817
- # @api private
818
- def string_PRegexpType(t)
819
- t.pattern.nil? ? 'Regexp' : "Regexp[#{t.regexp.inspect}]"
820
- end
821
-
822
- # @api private
823
- def string_PStringType(t)
824
- # skip values in regular output - see debug_string
825
- range = range_array_part(t.size_type)
826
- if range.empty?
827
- 'String'
828
- else
829
- "String[#{range.join(', ')}]"
830
- end
831
- end
832
-
833
- # @api private
834
- def debug_string_PStringType(t)
835
- range = range_array_part(t.size_type)
836
- range_part = range.empty? ? '' : '[' << range.join(' ,') << '], '
837
- 'String[' << range_part << (t.values.map {|s| "'#{s}'" }).join(', ') << ']'
838
- end
839
-
840
- # @api private
841
- def string_PEnumType(t)
842
- return 'Enum' if t.values.empty?
843
- 'Enum[' << t.values.map {|s| "'#{s}'" }.join(', ') << ']'
844
- end
845
-
846
- # @api private
847
- def string_PVariantType(t)
848
- return 'Variant' if t.types.empty?
849
- 'Variant[' << t.types.map {|t2| string(t2) }.join(', ') << ']'
850
- end
851
-
852
- # @api private
853
- def string_PTupleType(t)
854
- range = range_array_part(t.size_type)
855
- return 'Tuple' if t.types.empty?
856
- s = 'Tuple[' << t.types.map {|t2| string(t2) }.join(', ')
857
- unless range.empty?
858
- s << ', ' << range.join(', ')
859
- end
860
- s << ']'
861
- s
862
- end
863
-
864
- # @api private
865
- def string_PCallableType(t)
866
- # generic
867
- return 'Callable' if t.param_types.nil?
868
-
869
- if t.param_types.types.empty?
870
- range = [0, 0]
871
- else
872
- range = range_array_part(t.param_types.size_type)
873
- end
874
- # translate to string, and skip Unit types
875
- types = t.param_types.types.map {|t2| string(t2) unless t2.class == Types::PUnitType }.compact
876
-
877
- s = 'Callable[' << types.join(', ')
878
- unless range.empty?
879
- (s << ', ') unless types.empty?
880
- s << range.join(', ')
881
- end
882
- # Add block T last (after min, max) if present)
883
- #
884
- unless t.block_type.nil?
885
- (s << ', ') unless types.empty? && range.empty?
886
- s << string(t.block_type)
887
- end
888
- s << ']'
889
- s
890
- end
891
-
892
- # @api private
893
- def string_PStructType(t)
894
- return 'Struct' if t.elements.empty?
895
- 'Struct[{' << t.elements.map {|element| string(element) }.join(', ') << '}]'
896
- end
897
-
898
- def string_PStructElement(t)
899
- k = t.key_type
900
- value_optional = t.value_type.assignable?(Types::PUndefType::DEFAULT)
901
- key_string =
902
- if k.is_a?(Types::POptionalType)
903
- # Output as literal String
904
- value_optional ? "'#{t.name}'" : string(k)
905
- else
906
- value_optional ? "NotUndef['#{t.name}']" : "'#{t.name}'"
907
- end
908
- "#{key_string}=>#{string(t.value_type)}"
909
- end
910
-
911
- # @api private
912
- def string_PPatternType(t)
913
- return 'Pattern' if t.patterns.empty?
914
- 'Pattern[' << t.patterns.map {|s| "#{s.regexp.inspect}" }.join(', ') << ']'
915
- end
916
-
917
- # @api private
918
- def string_PCollectionType(t)
919
- range = range_array_part(t.size_type)
920
- if range.empty?
921
- 'Collection'
922
- else
923
- "Collection[#{range.join(', ')}]"
924
- end
925
- end
926
-
927
- # @api private
928
- def string_PUnitType(t)
929
- 'Unit'
930
- end
931
-
932
- # @api private
933
- def string_PRuntimeType(t) ; "Runtime[#{string(t.runtime)}, #{string(t.runtime_type_name)}]" ; end
934
-
935
- # @api private
936
- def string_PArrayType(t)
937
- parts = [string(t.element_type)] + range_array_part(t.size_type)
938
- "Array[#{parts.join(', ')}]"
939
- end
940
-
941
- # @api private
942
- def string_PHashType(t)
943
- parts = [string(t.key_type), string(t.element_type)] + range_array_part(t.size_type)
944
- "Hash[#{parts.join(', ')}]"
945
- end
946
-
947
- # @api private
948
- def string_PCatalogEntryType(t)
949
- 'CatalogEntry'
950
- end
951
-
952
- # @api private
953
- def string_PHostClassType(t)
954
- if t.class_name
955
- "Class[#{t.class_name}]"
956
- else
957
- 'Class'
958
- end
959
- end
960
-
961
- # @api private
962
- def string_PResourceType(t)
963
- if t.type_name
964
- if t.title
965
- "#{capitalize_segments(t.type_name)}['#{t.title}']"
966
- else
967
- capitalize_segments(t.type_name)
968
- end
969
- else
970
- 'Resource'
971
- end
972
- end
973
-
974
- # @api private
975
- def string_PNotUndefType(t)
976
- contained_type = t.type
977
- if contained_type.nil? || contained_type.class == Puppet::Pops::Types::PAnyType
978
- 'NotUndef'
979
- else
980
- if contained_type.is_a?(Puppet::Pops::Types::PStringType) && contained_type.values.size == 1
981
- "NotUndef['#{contained_type.values[0]}']"
982
- else
983
- "NotUndef[#{string(contained_type)}]"
984
- end
985
- end
986
- end
987
-
988
- def string_POptionalType(t)
989
- optional_type = t.optional_type
990
- if optional_type.nil?
991
- 'Optional'
992
- else
993
- if optional_type.is_a?(Puppet::Pops::Types::PStringType) && optional_type.values.size == 1
994
- "Optional['#{optional_type.values[0]}']"
995
- else
996
- "Optional[#{string(optional_type)}]"
997
- end
998
- end
999
- end
1000
-
1001
762
  # Debugging to_s to reduce the amount of output
1002
763
  def to_s
1003
764
  '[a TypeCalculator]'
@@ -1005,22 +766,18 @@ class Puppet::Pops::Types::TypeCalculator
1005
766
 
1006
767
  private
1007
768
 
1008
- NAME_SEGMENT_SEPARATOR = '::'.freeze
1009
-
1010
- def capitalize_segments(s)
1011
- s.split(NAME_SEGMENT_SEPARATOR).map(&:capitalize).join(NAME_SEGMENT_SEPARATOR)
1012
- end
1013
-
1014
769
  def common_data?(t1, t2)
1015
- Types::PDataType::DEFAULT.assignable?(t1) && Types::PDataType::DEFAULT.assignable?(t2)
770
+ PDataType::DEFAULT.assignable?(t1) && PDataType::DEFAULT.assignable?(t2)
1016
771
  end
1017
772
 
1018
773
  def common_scalar?(t1, t2)
1019
- Types::PScalarType::DEFAULT.assignable?(t1) && Types::PScalarType::DEFAULT.assignable?(t2)
774
+ PScalarType::DEFAULT.assignable?(t1) && PScalarType::DEFAULT.assignable?(t2)
1020
775
  end
1021
776
 
1022
777
  def common_numeric?(t1, t2)
1023
- Types::PNumericType::DEFAULT.assignable?(t1) && Types::PNumericType::DEFAULT.assignable?(t2)
778
+ PNumericType::DEFAULT.assignable?(t1) && PNumericType::DEFAULT.assignable?(t2)
1024
779
  end
1025
780
 
1026
781
  end
782
+ end
783
+ end