puppet 5.3.7-x64-mingw32 → 5.4.0-x64-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 (454) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +42 -29
  3. data/README.md +8 -6
  4. data/ext/cert_inspector +2 -2
  5. data/ext/envpuppet +1 -1
  6. data/ext/gentoo/init.d/puppetmaster +4 -4
  7. data/ext/ips/puppet-agent +11 -11
  8. data/ext/ips/puppet-master +11 -11
  9. data/ext/puppet-test +1 -2
  10. data/ext/redhat/client.init +2 -2
  11. data/ext/redhat/logrotate +1 -1
  12. data/ext/solaris/smf/puppet +11 -11
  13. data/ext/solaris/smf/svc-puppetd +5 -5
  14. data/ext/solaris/smf/svc-puppetmasterd +5 -5
  15. data/ext/windows/service/daemon.rb +1 -1
  16. data/install.rb +2 -3
  17. data/lib/puppet/agent.rb +1 -1
  18. data/lib/puppet/application/cert.rb +1 -3
  19. data/lib/puppet/application/describe.rb +0 -1
  20. data/lib/puppet/application/device.rb +12 -99
  21. data/lib/puppet/application/filebucket.rb +32 -11
  22. data/lib/puppet/application/lookup.rb +1 -11
  23. data/lib/puppet/application/script.rb +261 -0
  24. data/lib/puppet/configurer.rb +3 -4
  25. data/lib/puppet/configurer/plugin_handler.rb +26 -9
  26. data/lib/puppet/context.rb +1 -1
  27. data/lib/puppet/datatypes.rb +213 -0
  28. data/lib/puppet/datatypes/error.rb +21 -0
  29. data/lib/puppet/datatypes/impl/error.rb +40 -0
  30. data/lib/puppet/defaults.rb +51 -20
  31. data/lib/puppet/environments.rb +17 -0
  32. data/lib/puppet/error.rb +17 -0
  33. data/lib/puppet/etc.rb +2 -2
  34. data/lib/puppet/external/pson/pure/generator.rb +1 -1
  35. data/lib/puppet/external/pson/pure/parser.rb +1 -1
  36. data/lib/puppet/face/config.rb +45 -0
  37. data/lib/puppet/face/epp.rb +3 -3
  38. data/lib/puppet/face/help/action.erb +3 -0
  39. data/lib/puppet/face/module/build.rb +1 -0
  40. data/lib/puppet/face/module/generate.rb +5 -0
  41. data/lib/puppet/face/module/install.rb +1 -0
  42. data/lib/puppet/face/module/search.rb +6 -2
  43. data/lib/puppet/face/module/uninstall.rb +1 -0
  44. data/lib/puppet/face/module/upgrade.rb +1 -0
  45. data/lib/puppet/face/parser.rb +0 -1
  46. data/lib/puppet/face/plugin.rb +1 -3
  47. data/lib/puppet/feature/base.rb +1 -1
  48. data/lib/puppet/feature/bolt.rb +3 -0
  49. data/lib/puppet/file_bucket/dipper.rb +1 -2
  50. data/lib/puppet/file_serving/http_metadata.rb +1 -1
  51. data/lib/puppet/file_system/uniquefile.rb +2 -2
  52. data/lib/puppet/forge.rb +6 -0
  53. data/lib/puppet/functions.rb +70 -88
  54. data/lib/puppet/functions/all.rb +6 -2
  55. data/lib/puppet/functions/annotate.rb +1 -1
  56. data/lib/puppet/functions/any.rb +7 -3
  57. data/lib/puppet/functions/contain.rb +6 -0
  58. data/lib/puppet/functions/convert_to.rb +32 -0
  59. data/lib/puppet/functions/defined.rb +0 -3
  60. data/lib/puppet/functions/each.rb +10 -6
  61. data/lib/puppet/functions/filter.rb +16 -10
  62. data/lib/puppet/functions/find_file.rb +0 -1
  63. data/lib/puppet/functions/include.rb +6 -0
  64. data/lib/puppet/functions/map.rb +12 -9
  65. data/lib/puppet/functions/module_directory.rb +41 -0
  66. data/lib/puppet/functions/new.rb +1 -4
  67. data/lib/puppet/functions/regsubst.rb +1 -1
  68. data/lib/puppet/functions/require.rb +6 -0
  69. data/lib/puppet/generate/type.rb +1 -1
  70. data/lib/puppet/gettext/config.rb +2 -2
  71. data/lib/puppet/gettext/stubs.rb +1 -1
  72. data/lib/puppet/indirector/catalog/compiler.rb +0 -1
  73. data/lib/puppet/indirector/file_bucket_file/file.rb +6 -2
  74. data/lib/puppet/indirector/file_server.rb +1 -1
  75. data/lib/puppet/indirector/node/ldap.rb +19 -3
  76. data/lib/puppet/indirector/request.rb +10 -6
  77. data/lib/puppet/indirector/rest.rb +11 -12
  78. data/lib/puppet/info_service/class_information_service.rb +1 -1
  79. data/lib/puppet/interface/action.rb +11 -0
  80. data/lib/puppet/interface/action_builder.rb +8 -0
  81. data/lib/puppet/interface/option_manager.rb +1 -1
  82. data/lib/puppet/loaders.rb +2 -0
  83. data/lib/puppet/module.rb +6 -2
  84. data/lib/puppet/module_tool/applications/builder.rb +4 -0
  85. data/lib/puppet/module_tool/applications/installer.rb +3 -0
  86. data/lib/puppet/module_tool/applications/uninstaller.rb +3 -0
  87. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  88. data/lib/puppet/module_tool/applications/upgrader.rb +3 -0
  89. data/lib/puppet/module_tool/installed_modules.rb +1 -1
  90. data/lib/puppet/module_tool/metadata.rb +0 -1
  91. data/lib/puppet/network/authstore.rb +1 -1
  92. data/lib/puppet/network/http/api/indirected_routes.rb +1 -1
  93. data/lib/puppet/network/http/connection.rb +1 -9
  94. data/lib/puppet/network/http/factory.rb +0 -3
  95. data/lib/puppet/network/http/webrick.rb +1 -0
  96. data/lib/puppet/network/rights.rb +1 -1
  97. data/lib/puppet/node.rb +53 -0
  98. data/lib/puppet/node/environment.rb +1 -1
  99. data/lib/puppet/parameter/boolean.rb +1 -1
  100. data/lib/puppet/parser.rb +1 -0
  101. data/lib/puppet/parser/abstract_compiler.rb +36 -0
  102. data/lib/puppet/parser/ast/branch.rb +1 -1
  103. data/lib/puppet/parser/ast/pops_bridge.rb +8 -52
  104. data/lib/puppet/parser/compiler.rb +4 -54
  105. data/lib/puppet/parser/functions.rb +0 -1
  106. data/lib/puppet/parser/functions/create_resources.rb +6 -0
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +6 -2
  108. data/lib/puppet/parser/functions/inline_template.rb +6 -0
  109. data/lib/puppet/parser/functions/new.rb +47 -32
  110. data/lib/puppet/parser/functions/realize.rb +6 -0
  111. data/lib/puppet/parser/functions/return.rb +1 -22
  112. data/lib/puppet/parser/functions/reverse_each.rb +1 -1
  113. data/lib/puppet/parser/functions/scanf.rb +1 -1
  114. data/lib/puppet/parser/functions/sha256.rb +5 -0
  115. data/lib/puppet/parser/functions/tag.rb +6 -0
  116. data/lib/puppet/parser/functions/tagged.rb +6 -0
  117. data/lib/puppet/parser/functions/template.rb +5 -0
  118. data/lib/puppet/parser/scope.rb +28 -4
  119. data/lib/puppet/parser/script_compiler.rb +118 -0
  120. data/lib/puppet/parser/type_loader.rb +1 -1
  121. data/lib/puppet/pops.rb +1 -1
  122. data/lib/puppet/pops/evaluator/access_operator.rb +38 -4
  123. data/lib/puppet/pops/evaluator/closure.rb +12 -4
  124. data/lib/puppet/pops/evaluator/compare_operator.rb +4 -4
  125. data/lib/puppet/pops/evaluator/epp_evaluator.rb +13 -0
  126. data/lib/puppet/pops/evaluator/evaluator_impl.rb +38 -10
  127. data/lib/puppet/pops/evaluator/literal_evaluator.rb +1 -1
  128. data/lib/puppet/pops/evaluator/runtime3_converter.rb +1 -1
  129. data/lib/puppet/pops/evaluator/runtime3_support.rb +2 -3
  130. data/lib/puppet/pops/functions/dispatch.rb +6 -5
  131. data/lib/puppet/pops/functions/function.rb +2 -2
  132. data/lib/puppet/pops/issues.rb +34 -2
  133. data/lib/puppet/pops/loader/base_loader.rb +10 -0
  134. data/lib/puppet/pops/loader/dependency_loader.rb +7 -0
  135. data/lib/puppet/pops/loader/loader.rb +21 -2
  136. data/lib/puppet/pops/loader/loader_paths.rb +180 -30
  137. data/lib/puppet/pops/loader/module_loaders.rb +202 -33
  138. data/lib/puppet/pops/loader/puppet_plan_instantiator.rb +84 -0
  139. data/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +9 -9
  140. data/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +40 -0
  141. data/lib/puppet/pops/loader/runtime3_type_loader.rb +6 -1
  142. data/lib/puppet/pops/loader/static_loader.rb +23 -8
  143. data/lib/puppet/pops/loader/task_instantiator.rb +69 -0
  144. data/lib/puppet/pops/loader/type_definition_instantiator.rb +4 -0
  145. data/lib/puppet/pops/loaders.rb +122 -11
  146. data/lib/puppet/pops/lookup/data_dig_function_provider.rb +1 -1
  147. data/lib/puppet/pops/lookup/interpolation.rb +1 -1
  148. data/lib/puppet/pops/lookup/lookup_adapter.rb +0 -1
  149. data/lib/puppet/pops/model/ast.pp +3 -0
  150. data/lib/puppet/pops/model/ast.rb +34 -1
  151. data/lib/puppet/pops/model/factory.rb +30 -3
  152. data/lib/puppet/pops/model/model_label_provider.rb +1 -0
  153. data/lib/puppet/pops/model/model_tree_dumper.rb +12 -1
  154. data/lib/puppet/pops/model/tree_dumper.rb +1 -1
  155. data/lib/puppet/pops/parser/code_merger.rb +2 -2
  156. data/lib/puppet/pops/parser/egrammar.ra +44 -15
  157. data/lib/puppet/pops/parser/eparser.rb +1687 -1571
  158. data/lib/puppet/pops/parser/epp_support.rb +1 -3
  159. data/lib/puppet/pops/parser/evaluating_parser.rb +1 -1
  160. data/lib/puppet/pops/parser/interpolation_support.rb +2 -2
  161. data/lib/puppet/pops/parser/lexer2.rb +4 -4
  162. data/lib/puppet/pops/parser/lexer_support.rb +2 -2
  163. data/lib/puppet/pops/parser/locatable.rb +1 -1
  164. data/lib/puppet/pops/parser/locator.rb +7 -13
  165. data/lib/puppet/pops/parser/parser_support.rb +3 -3
  166. data/lib/puppet/pops/parser/slurp_support.rb +0 -3
  167. data/lib/puppet/pops/pcore.rb +45 -0
  168. data/lib/puppet/pops/resource/param.rb +1 -1
  169. data/lib/puppet/pops/resource/resource_type_impl.rb +1 -1
  170. data/lib/puppet/pops/serialization/abstract_reader.rb +4 -0
  171. data/lib/puppet/pops/serialization/abstract_writer.rb +6 -0
  172. data/lib/puppet/pops/serialization/extension.rb +1 -0
  173. data/lib/puppet/pops/serialization/from_data_converter.rb +64 -10
  174. data/lib/puppet/pops/serialization/json_path.rb +2 -1
  175. data/lib/puppet/pops/serialization/object.rb +3 -4
  176. data/lib/puppet/pops/serialization/serializer.rb +2 -1
  177. data/lib/puppet/pops/serialization/to_data_converter.rb +7 -3
  178. data/lib/puppet/pops/time/timespan.rb +1 -1
  179. data/lib/puppet/pops/types/iterable.rb +38 -9
  180. data/lib/puppet/pops/types/p_init_type.rb +1 -1
  181. data/lib/puppet/pops/types/p_meta_type.rb +4 -0
  182. data/lib/puppet/pops/types/p_object_type.rb +146 -14
  183. data/lib/puppet/pops/types/p_object_type_extension.rb +218 -0
  184. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +0 -1
  185. data/lib/puppet/pops/types/p_sem_ver_type.rb +10 -2
  186. data/lib/puppet/pops/types/p_type_set_type.rb +0 -1
  187. data/lib/puppet/pops/types/p_uri_type.rb +190 -0
  188. data/lib/puppet/pops/types/puppet_object.rb +15 -1
  189. data/lib/puppet/pops/types/ruby_generator.rb +46 -54
  190. data/lib/puppet/pops/types/string_converter.rb +22 -1
  191. data/lib/puppet/pops/types/type_acceptor.rb +1 -1
  192. data/lib/puppet/pops/types/type_calculator.rb +13 -4
  193. data/lib/puppet/pops/types/type_factory.rb +29 -5
  194. data/lib/puppet/pops/types/type_formatter.rb +67 -4
  195. data/lib/puppet/pops/types/type_parser.rb +92 -4
  196. data/lib/puppet/pops/types/type_with_members.rb +43 -0
  197. data/lib/puppet/pops/types/types.rb +212 -80
  198. data/lib/puppet/pops/validation/checker4_0.rb +10 -6
  199. data/lib/puppet/pops/validation/tasks_checker.rb +60 -0
  200. data/lib/puppet/pops/validation/validator_factory_4_0.rb +6 -1
  201. data/lib/puppet/property.rb +1 -1
  202. data/lib/puppet/provider.rb +18 -8
  203. data/lib/puppet/provider/augeas/augeas.rb +3 -4
  204. data/lib/puppet/provider/exec.rb +0 -2
  205. data/lib/puppet/provider/group/groupadd.rb +25 -1
  206. data/lib/puppet/provider/group/windows_adsi.rb +7 -4
  207. data/lib/puppet/provider/mount.rb +25 -8
  208. data/lib/puppet/provider/nameservice.rb +9 -4
  209. data/lib/puppet/provider/nameservice/directoryservice.rb +3 -3
  210. data/lib/puppet/provider/nameservice/objectadd.rb +13 -24
  211. data/lib/puppet/provider/nameservice/pw.rb +14 -14
  212. data/lib/puppet/provider/package/appdmg.rb +0 -1
  213. data/lib/puppet/provider/package/apple.rb +0 -1
  214. data/lib/puppet/provider/package/gem.rb +2 -2
  215. data/lib/puppet/provider/package/macports.rb +2 -2
  216. data/lib/puppet/provider/package/pkg.rb +3 -0
  217. data/lib/puppet/provider/package/pkgdmg.rb +0 -1
  218. data/lib/puppet/provider/package/portage.rb +0 -1
  219. data/lib/puppet/provider/package/yum.rb +23 -8
  220. data/lib/puppet/provider/package/zypper.rb +2 -2
  221. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +2 -2
  222. data/lib/puppet/provider/service/init.rb +1 -0
  223. data/lib/puppet/provider/service/launchd.rb +6 -7
  224. data/lib/puppet/provider/service/redhat.rb +3 -2
  225. data/lib/puppet/provider/service/systemd.rb +2 -2
  226. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
  227. data/lib/puppet/provider/user/aix.rb +3 -2
  228. data/lib/puppet/provider/user/openbsd.rb +1 -1
  229. data/lib/puppet/provider/user/pw.rb +1 -1
  230. data/lib/puppet/provider/user/user_role_add.rb +7 -1
  231. data/lib/puppet/provider/user/useradd.rb +36 -6
  232. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  233. data/lib/puppet/provider/yumrepo/inifile.rb +2 -4
  234. data/lib/puppet/provider/zfs/zfs.rb +23 -3
  235. data/lib/puppet/provider/zpool/zpool.rb +1 -1
  236. data/lib/puppet/reference/configuration.rb +0 -2
  237. data/lib/puppet/reference/type.rb +0 -1
  238. data/lib/puppet/resource.rb +1 -2
  239. data/lib/puppet/resource/catalog.rb +1 -1
  240. data/lib/puppet/resource/status.rb +0 -1
  241. data/lib/puppet/resource/type.rb +4 -4
  242. data/lib/puppet/resource/type_collection.rb +1 -1
  243. data/lib/puppet/settings/base_setting.rb +1 -1
  244. data/lib/puppet/settings/environment_conf.rb +0 -1
  245. data/lib/puppet/settings/ini_file.rb +66 -12
  246. data/lib/puppet/ssl/certificate_authority.rb +1 -1
  247. data/lib/puppet/ssl/certificate_request.rb +2 -2
  248. data/lib/puppet/ssl/certificate_revocation_list.rb +2 -1
  249. data/lib/puppet/ssl/certificate_signer.rb +11 -0
  250. data/lib/puppet/ssl/host.rb +2 -2
  251. data/lib/puppet/syntax_checkers/base64.rb +1 -1
  252. data/lib/puppet/transaction.rb +37 -14
  253. data/lib/puppet/transaction/report.rb +3 -1
  254. data/lib/puppet/type.rb +17 -4
  255. data/lib/puppet/type/cron.rb +1 -1
  256. data/lib/puppet/type/exec.rb +5 -4
  257. data/lib/puppet/type/file.rb +3 -3
  258. data/lib/puppet/type/file/checksum.rb +7 -1
  259. data/lib/puppet/type/file/checksum_value.rb +4 -3
  260. data/lib/puppet/type/group.rb +3 -0
  261. data/lib/puppet/type/k5login.rb +101 -0
  262. data/lib/puppet/type/macauthorization.rb +1 -1
  263. data/lib/puppet/type/mount.rb +6 -2
  264. data/lib/puppet/type/tidy.rb +6 -4
  265. data/lib/puppet/type/user.rb +26 -39
  266. data/lib/puppet/type/yumrepo.rb +9 -0
  267. data/lib/puppet/type/zfs.rb +4 -0
  268. data/lib/puppet/util.rb +8 -15
  269. data/lib/puppet/util/character_encoding.rb +2 -2
  270. data/lib/puppet/util/checksums.rb +82 -1
  271. data/lib/puppet/util/errors.rb +0 -2
  272. data/lib/puppet/util/filetype.rb +2 -2
  273. data/lib/puppet/util/json_lockfile.rb +1 -1
  274. data/lib/puppet/util/log.rb +1 -1
  275. data/lib/puppet/util/log/destinations.rb +10 -1
  276. data/lib/puppet/util/monkey_patches.rb +1 -1
  277. data/lib/puppet/util/network_device/cisco/device.rb +5 -5
  278. data/lib/puppet/util/network_device/config.rb +2 -3
  279. data/lib/puppet/util/platform.rb +13 -0
  280. data/lib/puppet/util/plist.rb +4 -4
  281. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +2 -2
  282. data/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +1 -1
  283. data/lib/puppet/util/reference.rb +8 -1
  284. data/lib/puppet/util/windows/adsi.rb +18 -15
  285. data/lib/puppet/util/windows/principal.rb +6 -7
  286. data/lib/puppet/util/windows/process.rb +1 -1
  287. data/lib/puppet/util/windows/registry.rb +2 -2
  288. data/lib/puppet/util/windows/sid.rb +7 -62
  289. data/lib/puppet/vendor/deep_merge/README.md +2 -2
  290. data/lib/puppet/vendor/pathspec/lib/pathspec/gitignorespec.rb +18 -18
  291. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version.rb +2 -2
  292. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version_range.rb +5 -5
  293. data/lib/puppet/vendor/semantic_puppet/locales/config.yaml +1 -1
  294. data/lib/puppet/version.rb +1 -1
  295. data/lib/puppet_pal.rb +874 -0
  296. data/locales/ja/puppet.po +140 -163
  297. data/locales/puppet.pot +940 -597
  298. data/man/man5/puppet.conf.5 +16 -91
  299. data/man/man8/puppet-agent.8 +2 -6
  300. data/man/man8/puppet-apply.8 +2 -2
  301. data/man/man8/puppet-ca.8 +1 -1
  302. data/man/man8/puppet-catalog.8 +1 -1
  303. data/man/man8/puppet-cert.8 +1 -1
  304. data/man/man8/puppet-certificate.8 +1 -1
  305. data/man/man8/puppet-certificate_request.8 +1 -1
  306. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  307. data/man/man8/puppet-config.8 +1 -1
  308. data/man/man8/puppet-describe.8 +1 -1
  309. data/man/man8/puppet-device.8 +11 -33
  310. data/man/man8/puppet-doc.8 +1 -1
  311. data/man/man8/puppet-epp.8 +1 -1
  312. data/man/man8/puppet-facts.8 +1 -1
  313. data/man/man8/puppet-filebucket.8 +4 -22
  314. data/man/man8/puppet-generate.8 +1 -1
  315. data/man/man8/puppet-help.8 +1 -1
  316. data/man/man8/puppet-key.8 +1 -1
  317. data/man/man8/puppet-lookup.8 +1 -1
  318. data/man/man8/puppet-man.8 +1 -1
  319. data/man/man8/puppet-master.8 +1 -1
  320. data/man/man8/puppet-module.8 +2 -11
  321. data/man/man8/puppet-node.8 +1 -1
  322. data/man/man8/puppet-parser.8 +1 -1
  323. data/man/man8/puppet-plugin.8 +1 -1
  324. data/man/man8/puppet-report.8 +1 -1
  325. data/man/man8/puppet-resource.8 +1 -1
  326. data/man/man8/puppet-status.8 +1 -1
  327. data/man/man8/puppet.8 +2 -2
  328. data/spec/integration/application/lookup_spec.rb +0 -21
  329. data/spec/integration/parser/compiler_spec.rb +18 -0
  330. data/spec/integration/parser/script_compiler_spec.rb +113 -0
  331. data/spec/integration/provider/mount_spec.rb +2 -0
  332. data/spec/integration/type/file_spec.rb +11 -3
  333. data/spec/integration/util/windows/adsi_spec.rb +1 -86
  334. data/spec/integration/util/windows/principal_spec.rb +1 -10
  335. data/spec/shared_contexts/checksum.rb +4 -1
  336. data/spec/shared_contexts/digests.rb +46 -1
  337. data/spec/shared_contexts/types_setup.rb +8 -3
  338. data/spec/unit/agent_spec.rb +2 -2
  339. data/spec/unit/application/cert_spec.rb +5 -17
  340. data/spec/unit/application/device_spec.rb +2 -96
  341. data/spec/unit/application/filebucket_spec.rb +18 -4
  342. data/spec/unit/configurer/plugin_handler_spec.rb +5 -32
  343. data/spec/unit/configurer_spec.rb +3 -3
  344. data/spec/unit/datatypes_spec.rb +304 -0
  345. data/spec/unit/defaults_spec.rb +41 -20
  346. data/spec/unit/face/config_spec.rb +46 -1
  347. data/spec/unit/face/epp_face_spec.rb +7 -3
  348. data/spec/unit/face/module/search_spec.rb +11 -0
  349. data/spec/unit/face/parser_spec.rb +2 -2
  350. data/spec/unit/file_bucket/dipper_spec.rb +12 -1
  351. data/spec/unit/forge/module_release_spec.rb +70 -0
  352. data/spec/unit/functions/break_spec.rb +34 -2
  353. data/spec/unit/functions/contain_spec.rb +1 -0
  354. data/spec/unit/functions/convert_to_spec.rb +22 -0
  355. data/spec/unit/functions/epp_spec.rb +5 -0
  356. data/spec/unit/functions/include_spec.rb +15 -0
  357. data/spec/unit/functions/module_directory_spec.rb +43 -0
  358. data/spec/unit/functions/new_spec.rb +14 -14
  359. data/spec/unit/functions/require_spec.rb +2 -0
  360. data/spec/unit/functions/shared.rb +12 -0
  361. data/spec/unit/functions/step_spec.rb +1 -1
  362. data/spec/unit/functions4_spec.rb +49 -4
  363. data/spec/unit/indirector/catalog/compiler_spec.rb +3 -3
  364. data/spec/unit/indirector/file_bucket_file/file_spec.rb +148 -94
  365. data/spec/unit/indirector/node/ldap_spec.rb +15 -12
  366. data/spec/unit/indirector/rest_spec.rb +0 -43
  367. data/spec/unit/interface/action_spec.rb +33 -0
  368. data/spec/unit/module_tool/applications/builder_spec.rb +7 -0
  369. data/spec/unit/module_tool/applications/installer_spec.rb +8 -0
  370. data/spec/unit/module_tool/applications/uninstaller_spec.rb +8 -0
  371. data/spec/unit/module_tool/applications/upgrader_spec.rb +6 -0
  372. data/spec/unit/network/http/connection_spec.rb +1 -1
  373. data/spec/unit/network/http/factory_spec.rb +28 -35
  374. data/spec/unit/parser/compiler_spec.rb +0 -8
  375. data/spec/unit/parser/environment_compiler_spec.rb +36 -0
  376. data/spec/unit/parser/functions/create_resources_spec.rb +9 -0
  377. data/spec/unit/parser/functions/inline_template_spec.rb +7 -0
  378. data/spec/unit/parser/functions/realize_spec.rb +9 -0
  379. data/spec/unit/parser/functions/tag_spec.rb +7 -0
  380. data/spec/unit/parser/functions/tagged_spec.rb +25 -0
  381. data/spec/unit/parser/functions/template_spec.rb +8 -0
  382. data/spec/unit/parser/scope_spec.rb +19 -0
  383. data/spec/unit/pops/evaluator/conditionals_spec.rb +1 -1
  384. data/spec/unit/pops/loaders/loader_spec.rb +516 -0
  385. data/spec/unit/pops/loaders/loaders_spec.rb +11 -0
  386. data/spec/unit/pops/loaders/module_loaders_spec.rb +43 -0
  387. data/spec/unit/pops/loaders/static_loader_spec.rb +15 -7
  388. data/spec/unit/pops/model/model_spec.rb +5 -0
  389. data/spec/unit/pops/parser/lexer2_spec.rb +15 -0
  390. data/spec/unit/pops/parser/locator_spec.rb +20 -0
  391. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +33 -0
  392. data/spec/unit/pops/parser/parse_calls_spec.rb +28 -0
  393. data/spec/unit/pops/parser/parse_conditionals_spec.rb +12 -0
  394. data/spec/unit/pops/parser/parse_plan_spec.rb +48 -0
  395. data/spec/unit/pops/serialization/packer_spec.rb +8 -0
  396. data/spec/unit/pops/serialization/serialization_spec.rb +30 -0
  397. data/spec/unit/pops/serialization/to_from_hr_spec.rb +31 -0
  398. data/spec/unit/pops/types/error_spec.rb +207 -0
  399. data/spec/unit/pops/types/p_init_type_spec.rb +98 -0
  400. data/spec/unit/pops/types/p_object_type_spec.rb +275 -10
  401. data/spec/unit/pops/types/p_uri_type_spec.rb +191 -0
  402. data/spec/unit/pops/types/ruby_generator_spec.rb +82 -44
  403. data/spec/unit/pops/types/task_spec.rb +353 -0
  404. data/spec/unit/pops/types/type_calculator_spec.rb +76 -5
  405. data/spec/unit/pops/types/type_formatter_spec.rb +31 -13
  406. data/spec/unit/pops/types/type_parser_spec.rb +13 -1
  407. data/spec/unit/pops/types/types_spec.rb +60 -0
  408. data/spec/unit/pops/validator/validator_spec.rb +76 -0
  409. data/spec/unit/provider/group/groupadd_spec.rb +77 -1
  410. data/spec/unit/provider/group/pw_spec.rb +4 -4
  411. data/spec/unit/provider/group/windows_adsi_spec.rb +22 -79
  412. data/spec/unit/provider/mount_spec.rb +18 -5
  413. data/spec/unit/provider/nameservice_spec.rb +5 -5
  414. data/spec/unit/provider/package/dnf_spec.rb +2 -2
  415. data/spec/unit/provider/package/gem_spec.rb +1 -1
  416. data/spec/unit/provider/package/pkg_spec.rb +3 -0
  417. data/spec/unit/provider/package/yum_spec.rb +40 -0
  418. data/spec/unit/provider/service/launchd_spec.rb +2 -1
  419. data/spec/unit/provider/service/redhat_spec.rb +5 -0
  420. data/spec/unit/provider/service/systemd_spec.rb +1 -1
  421. data/spec/unit/provider/user/hpux_spec.rb +2 -2
  422. data/spec/unit/provider/user/openbsd_spec.rb +2 -2
  423. data/spec/unit/provider/user/pw_spec.rb +14 -14
  424. data/spec/unit/provider/user/user_role_add_spec.rb +19 -2
  425. data/spec/unit/provider/user/useradd_spec.rb +188 -22
  426. data/spec/unit/provider/user/windows_adsi_spec.rb +4 -4
  427. data/spec/unit/provider/zfs/zfs_spec.rb +55 -1
  428. data/spec/unit/provider_spec.rb +48 -0
  429. data/spec/unit/puppet_pal_2pec.rb +1005 -0
  430. data/spec/unit/puppet_pal_spec.rb +11 -0
  431. data/spec/unit/settings/ini_file_spec.rb +313 -2
  432. data/spec/unit/ssl/certificate_request_spec.rb +42 -1
  433. data/spec/unit/ssl/certificate_revocation_list_spec.rb +2 -1
  434. data/spec/unit/transaction/report_spec.rb +1 -0
  435. data/spec/unit/transaction_spec.rb +112 -21
  436. data/spec/unit/type/file/checksum_spec.rb +20 -0
  437. data/spec/unit/type/file_spec.rb +8 -0
  438. data/spec/unit/type/group_spec.rb +8 -0
  439. data/spec/unit/type/k5login_spec.rb +22 -1
  440. data/spec/unit/type/scheduled_task_spec.rb +15 -0
  441. data/spec/unit/type/user_spec.rb +11 -1
  442. data/spec/unit/type/yumrepo_spec.rb +5 -0
  443. data/spec/unit/util/checksums_spec.rb +3 -3
  444. data/spec/unit/util/log/destinations_spec.rb +14 -0
  445. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  446. data/spec/unit/util/plist_spec.rb +3 -3
  447. data/spec/unit/util/windows/adsi_spec.rb +27 -31
  448. data/spec/unit/util/windows/sid_spec.rb +15 -86
  449. data/spec/unit/util_spec.rb +17 -3
  450. data/tasks/manpages.rake +1 -1
  451. metadata +220 -182
  452. data/lib/puppet/bindings.rb +0 -148
  453. data/lib/puppet/configurer/downloader_factory.rb +0 -44
  454. data/spec/unit/configurer/downloader_factory_spec.rb +0 -129
@@ -188,17 +188,21 @@ module Serialization
188
188
  end
189
189
 
190
190
  def unknown_key_to_string_with_warning(value)
191
- str = value.to_s
191
+ str = unknown_to_string(value)
192
192
  serialization_issue(Issues::SERIALIZATION_UNKNOWN_KEY_CONVERTED_TO_STRING, :path => path_to_s, :klass => value.class, :value => str)
193
193
  str
194
194
  end
195
195
 
196
196
  def unknown_to_string_with_warning(value)
197
- str = value.to_s
197
+ str = unknown_to_string(value)
198
198
  serialization_issue(Issues::SERIALIZATION_UNKNOWN_CONVERTED_TO_STRING, :path => path_to_s, :klass => value.class, :value => str)
199
199
  str
200
200
  end
201
201
 
202
+ def unknown_to_string(value)
203
+ value.is_a?(Regexp) ? Puppet::Pops::Types::PRegexpType.regexp_to_s_with_delimiters(value) : value.to_s
204
+ end
205
+
202
206
  def non_string_keyed_hash_to_data(hash)
203
207
  if @rich_data
204
208
  to_key_extended_hash(hash)
@@ -252,7 +256,7 @@ module Serialization
252
256
  end
253
257
  else
254
258
  process(value) do
255
- (names, types, required_count) = pcore_type.parameter_info(value.class)
259
+ (names, _, required_count) = pcore_type.parameter_info(value.class)
256
260
  args = names.map { |name| value.send(name) }
257
261
 
258
262
  # Pop optional arguments that are default
@@ -259,7 +259,7 @@ module Time
259
259
  add_unless_zero(result, KEY_NANOSECONDS, n % 1000)
260
260
  n /= 1000
261
261
  add_unless_zero(result, KEY_MICROSECONDS, n % 1000)
262
- add_unless_zero(result, KEY_MILLISECONDS, n /= 1000)
262
+ add_unless_zero(result, KEY_MILLISECONDS, n / 1000)
263
263
  end
264
264
  result[KEY_NEGATIVE] = true if negative?
265
265
  end
@@ -1,4 +1,12 @@
1
1
  module Puppet::Pops::Types
2
+
3
+ # Implemented by classes that can produce an iterator to iterate over their contents
4
+ module IteratorProducer
5
+ def iterator
6
+ raise ArgumentError, 'iterator() is not implemented'
7
+ end
8
+ end
9
+
2
10
  # The runtime Iterable type for an Iterable
3
11
  module Iterable
4
12
  # Produces an `Iterable` for one of the following types with the following characterstics:
@@ -25,7 +33,7 @@ module Puppet::Pops::Types
25
33
  iter
26
34
  end
27
35
 
28
- # Produces an `Iterable` for one of the following types with the following characterstics:
36
+ # Produces an `Iterable` for one of the following types with the following characteristics:
29
37
  #
30
38
  # `String` - yields each character in the string
31
39
  # `Array` - yields each element in the array
@@ -40,11 +48,14 @@ module Puppet::Pops::Types
40
48
  # The value `nil` is returned for all other objects.
41
49
  #
42
50
  # @param o [Object] The object to produce an `Iterable` for
51
+ # @param element_type [PAnyType] the element type for the iterator. Optional (inferred if not provided)
43
52
  # @return [Iterable,nil] The produced `Iterable` or `nil` if it couldn't be produced
44
53
  #
45
54
  # @api public
46
- def self.on(o)
55
+ def self.on(o, element_type = nil)
47
56
  case o
57
+ when IteratorProducer
58
+ o.iterator
48
59
  when Iterable
49
60
  o
50
61
  when String
@@ -53,18 +64,24 @@ module Puppet::Pops::Types
53
64
  if o.empty?
54
65
  Iterator.new(PUnitType::DEFAULT, o.each)
55
66
  else
56
- tc = TypeCalculator.singleton
57
- Iterator.new(PVariantType.maybe_create(o.map {|e| tc.infer_set(e) }), o.each)
67
+ if element_type.nil?
68
+ tc = TypeCalculator.singleton
69
+ element_type = PVariantType.maybe_create(o.map {|e| tc.infer_set(e) })
70
+ end
71
+ Iterator.new(element_type, o.each)
58
72
  end
59
73
  when Hash
60
74
  # Each element is a two element [key, value] tuple.
61
75
  if o.empty?
62
- Iterator.new(PHashType::DEFAULT_KEY_PAIR_TUPLE, o.each)
76
+ HashIterator.new(PHashType::DEFAULT_KEY_PAIR_TUPLE, o.each)
63
77
  else
64
- tc = TypeCalculator.singleton
65
- Iterator.new(PTupleType.new([
66
- PVariantType.maybe_create(o.keys.map {|e| tc.infer_set(e) }),
67
- PVariantType.maybe_create(o.values.map {|e| tc.infer_set(e) })], PHashType::KEY_PAIR_TUPLE_SIZE), o.each_pair)
78
+ if element_type.nil?
79
+ tc = TypeCalculator.singleton
80
+ element_type = PTupleType.new([
81
+ PVariantType.maybe_create(o.keys.map {|e| tc.infer_set(e) }),
82
+ PVariantType.maybe_create(o.values.map {|e| tc.infer_set(e) })], PHashType::KEY_PAIR_TUPLE_SIZE)
83
+ end
84
+ HashIterator.new(element_type, o.each_pair)
68
85
  end
69
86
  when Integer
70
87
  if o == 0
@@ -148,6 +165,10 @@ module Puppet::Pops::Types
148
165
  super
149
166
  end
150
167
 
168
+ def hash_style?
169
+ false
170
+ end
171
+
151
172
  def unbounded?
152
173
  true
153
174
  end
@@ -220,6 +241,14 @@ module Puppet::Pops::Types
220
241
  end
221
242
  end
222
243
 
244
+ # Special iterator used when iterating over hashes. Returns `true` for `#hash_style?` so that
245
+ # it is possible to differentiate between two element arrays and key => value associations
246
+ class HashIterator < Iterator
247
+ def hash_style?
248
+ true
249
+ end
250
+ end
251
+
223
252
  # @api private
224
253
  class StepIterator < Iterator
225
254
  include Enumerable
@@ -156,7 +156,7 @@ class PInitType < PTypeWithContainedType
156
156
  rescue ArgumentError
157
157
  raise ArgumentError, _("Creation of new instance of type '%{type_name}' is not supported") % { type_name: @type.to_s }
158
158
  end
159
- param_tuples = new_func.dispatcher.dispatchers.map { |closure| closure.type.param_types }
159
+ param_tuples = new_func.dispatcher.signatures.map { |closure| closure.type.param_types }
160
160
 
161
161
  # An instance of the contained type is always a match to this type.
162
162
  single_types = [@type]
@@ -78,6 +78,10 @@ class PMetaType < PAnyType
78
78
  end
79
79
  end
80
80
 
81
+ def resolved?
82
+ @init_hash_expression.nil?
83
+ end
84
+
81
85
  # Returns the expanded string the form of the alias, e.g. <alias name> = <resolved type>
82
86
  #
83
87
  # @return [String] the expanded form of this alias
@@ -1,4 +1,5 @@
1
1
  require_relative 'ruby_generator'
2
+ require_relative 'type_with_members'
2
3
 
3
4
  module Puppet::Pops
4
5
  module Types
@@ -13,9 +14,11 @@ KEY_FUNCTIONS = 'functions'.freeze
13
14
  KEY_KIND = 'kind'.freeze
14
15
  KEY_OVERRIDE = 'override'.freeze
15
16
  KEY_PARENT = 'parent'.freeze
17
+ KEY_TYPE_PARAMETERS = 'type_parameters'.freeze
16
18
 
17
19
  # @api public
18
20
  class PObjectType < PMetaType
21
+ include TypeWithMembers
19
22
 
20
23
  ATTRIBUTE_KIND_CONSTANT = 'constant'.freeze
21
24
  ATTRIBUTE_KIND_DERIVED = 'derived'.freeze
@@ -34,8 +37,14 @@ class PObjectType < PMetaType
34
37
  TypeFactory.optional(KEY_ANNOTATIONS) => TYPE_ANNOTATIONS
35
38
  })
36
39
 
40
+ TYPE_PARAMETER = TypeFactory.struct({
41
+ KEY_TYPE => PTypeType::DEFAULT,
42
+ TypeFactory.optional(KEY_ANNOTATIONS) => TYPE_ANNOTATIONS
43
+ })
44
+
37
45
  TYPE_CONSTANTS = TypeFactory.hash_kv(Pcore::TYPE_MEMBER_NAME, PAnyType::DEFAULT)
38
46
  TYPE_ATTRIBUTES = TypeFactory.hash_kv(Pcore::TYPE_MEMBER_NAME, TypeFactory.not_undef)
47
+ TYPE_PARAMETERS = TypeFactory.hash_kv(Pcore::TYPE_MEMBER_NAME, TypeFactory.not_undef)
39
48
  TYPE_ATTRIBUTE_CALLABLE = TypeFactory.callable(0,0)
40
49
 
41
50
  TYPE_FUNCTION_TYPE = PTypeType.new(PCallableType::DEFAULT)
@@ -46,7 +55,7 @@ class PObjectType < PMetaType
46
55
  TypeFactory.optional(KEY_OVERRIDE) => PBooleanType::DEFAULT,
47
56
  TypeFactory.optional(KEY_ANNOTATIONS) => TYPE_ANNOTATIONS
48
57
  })
49
- TYPE_FUNCTIONS = TypeFactory.hash_kv(Pcore::TYPE_MEMBER_NAME, TypeFactory.not_undef)
58
+ TYPE_FUNCTIONS = TypeFactory.hash_kv(PVariantType.new([Pcore::TYPE_MEMBER_NAME, PStringType.new('[]')]), TypeFactory.not_undef)
50
59
 
51
60
  TYPE_EQUALITY = TypeFactory.variant(Pcore::TYPE_MEMBER_NAME, TypeFactory.array_of(Pcore::TYPE_MEMBER_NAME))
52
61
 
@@ -55,6 +64,7 @@ class PObjectType < PMetaType
55
64
  TYPE_OBJECT_I12N = TypeFactory.struct({
56
65
  TypeFactory.optional(KEY_NAME) => TYPE_OBJECT_NAME,
57
66
  TypeFactory.optional(KEY_PARENT) => PTypeType::DEFAULT,
67
+ TypeFactory.optional(KEY_TYPE_PARAMETERS) => TYPE_PARAMETERS,
58
68
  TypeFactory.optional(KEY_ATTRIBUTES) => TYPE_ATTRIBUTES,
59
69
  TypeFactory.optional(KEY_CONSTANTS) => TYPE_CONSTANTS,
60
70
  TypeFactory.optional(KEY_FUNCTIONS) => TYPE_FUNCTIONS,
@@ -81,6 +91,7 @@ class PObjectType < PMetaType
81
91
  # @api public
82
92
  class PAnnotatedMember
83
93
  include Annotatable
94
+ include InvocableMember
84
95
 
85
96
  # @return [PObjectType] the object type containing this member
86
97
  # @api public
@@ -348,6 +359,22 @@ class PObjectType < PMetaType
348
359
  end
349
360
  end
350
361
 
362
+ class PTypeParameter < PAttribute
363
+ # @return [Hash{String=>Object}] the hash
364
+ # @api private
365
+ def _pcore_init_hash
366
+ hash = super
367
+ hash[KEY_TYPE] = hash[KEY_TYPE].type
368
+ hash.delete(KEY_VALUE) if hash.include?(KEY_VALUE) && hash[KEY_VALUE].nil?
369
+ hash
370
+ end
371
+
372
+ # @api private
373
+ def self.feature_type
374
+ 'type_parameter'
375
+ end
376
+ end
377
+
351
378
  # Describes a named Function in an Object type
352
379
  # @api public
353
380
  class PFunction < PAnnotatedMember
@@ -372,8 +399,6 @@ class PObjectType < PMetaType
372
399
 
373
400
  attr_reader :name
374
401
  attr_reader :parent
375
- attr_reader :attributes
376
- attr_reader :functions
377
402
  attr_reader :equality
378
403
  attr_reader :checks
379
404
  attr_reader :annotations
@@ -392,12 +417,15 @@ class PObjectType < PMetaType
392
417
  # @overload initialize(init_hash)
393
418
  # Used when the object is created by the {TypeFactory}. The init_hash must be fully resolved.
394
419
  # @param _pcore_init_hash [Hash{String=>Object}] The hash describing the Object features
420
+ # @param loader [Loaders::Loader,nil] the loader that loaded the type
395
421
  #
396
422
  # @api private
397
423
  def initialize(_pcore_init_hash, init_hash_expression = nil)
398
424
  if _pcore_init_hash.is_a?(Hash)
399
425
  _pcore_init_from_hash(_pcore_init_hash)
426
+ @loader = init_hash_expression unless init_hash_expression.nil?
400
427
  else
428
+ @type_parameters = EMPTY_HASH
401
429
  @attributes = EMPTY_HASH
402
430
  @functions = EMPTY_HASH
403
431
  @name = TypeAsserter.assert_instance_of('object name', TYPE_OBJECT_NAME, _pcore_init_hash)
@@ -442,7 +470,7 @@ class PObjectType < PMetaType
442
470
  # @return [Object] the created instance
443
471
  # @api private
444
472
  def read(value_count, deserializer)
445
- reader.read(implementation_class, value_count, deserializer)
473
+ reader.read(self, implementation_class, value_count, deserializer)
446
474
  end
447
475
 
448
476
  # Write an instance of this type using a serializer
@@ -456,15 +484,11 @@ class PObjectType < PMetaType
456
484
  # @api private
457
485
  def create_new_function
458
486
  impl_class = implementation_class
459
- class_name = impl_class.name || "Anonymous Ruby class for #{name}"
460
487
 
461
488
  (param_names, param_types, required_param_count) = parameter_info(impl_class)
462
489
 
463
490
  # Create the callable with a size that reflects the required and optional parameters
464
- param_types << required_param_count
465
- param_types << param_names.size
466
-
467
- create_type = TypeFactory.callable(*param_types)
491
+ create_type = TypeFactory.callable(*param_types, required_param_count, param_names.size)
468
492
  from_hash_type = TypeFactory.callable(init_hash_type, 1, 1)
469
493
 
470
494
  # Create and return a #new_XXX function where the dispatchers are added programmatically.
@@ -512,6 +536,7 @@ class PObjectType < PMetaType
512
536
  if impl_name.nil?
513
537
  # Use generator to create a default implementation
514
538
  @implementation_class = RubyGenerator.new.create_class(self)
539
+ @implementation_class.class_eval(&@implementation_override) if instance_variable_defined?(:@implementation_override)
515
540
  else
516
541
  # Can the mapping be loaded?
517
542
  class_name = impl_name[0]
@@ -532,10 +557,42 @@ class PObjectType < PMetaType
532
557
  @implementation_class = cls
533
558
  end
534
559
 
560
+ # The block passed to this method will be passed in a call to `#class_eval` on the dynamically generated
561
+ # class for this data type. It's indended use is to complement or redefine the generated methods and
562
+ # attribute readers.
563
+ #
564
+ # The method is normally called with the block passed to `#implementation` when a data type is defined using
565
+ # {Puppet::DataTypes::create_type}.
566
+ #
567
+ # @api private
568
+ def implementation_override=(block)
569
+ if !@implementation_class.nil? || instance_variable_defined?(:@implementation_override)
570
+ raise ArgumentError, "attempt to redefine implementation override for #{label}"
571
+ end
572
+ @implementation_override = block
573
+ end
574
+
575
+ def extract_init_hash(o)
576
+ return o._pcore_init_hash if o.respond_to?(:_pcore_init_hash)
577
+
578
+ result = {}
579
+ pic = parameter_info(o.class)
580
+ attrs = attributes(true)
581
+ pic[0].each do |name|
582
+ v = o.send(name)
583
+ result[name] = v unless attrs[name].default_value?(v)
584
+ end
585
+ result
586
+ end
587
+
535
588
  # @api private
536
589
  # @return [(Array<String>, Array<PAnyType>, Integer)] array of parameter names, array of parameter types, and a count reflecting the required number of parameters
537
590
  def parameter_info(impl_class)
538
591
  # Create a types and a names array where optional entries ends up last
592
+ @parameter_info ||= {}
593
+ pic = @parameter_info[impl_class]
594
+ return pic if pic
595
+
539
596
  opt_types = []
540
597
  opt_names = []
541
598
  non_opt_types = []
@@ -587,7 +644,9 @@ class PObjectType < PMetaType
587
644
  end
588
645
  end
589
646
 
590
- [param_names, param_types, non_opt_types.size]
647
+ pic = [param_names.freeze, param_types.freeze, non_opt_types.size].freeze
648
+ @parameter_info[impl_class] = pic
649
+ pic
591
650
  end
592
651
 
593
652
  # @api private
@@ -606,6 +665,7 @@ class PObjectType < PMetaType
606
665
  # @api private
607
666
  def _pcore_init_from_hash(init_hash)
608
667
  TypeAsserter.assert_instance_of('object initializer', TYPE_OBJECT_I12N, init_hash)
668
+ @type_parameters = EMPTY_HASH
609
669
  @attributes = EMPTY_HASH
610
670
  @functions = EMPTY_HASH
611
671
 
@@ -616,6 +676,7 @@ class PObjectType < PMetaType
616
676
  @parent = init_hash[KEY_PARENT]
617
677
 
618
678
  parent_members = EMPTY_HASH
679
+ parent_type_params = EMPTY_HASH
619
680
  parent_object_type = nil
620
681
  unless @parent.nil?
621
682
  check_self_recursion(self)
@@ -624,11 +685,35 @@ class PObjectType < PMetaType
624
685
  if rp.is_a?(PObjectType)
625
686
  parent_object_type = rp
626
687
  parent_members = rp.members(true)
688
+ parent_type_params = rp.type_parameters(true)
689
+ end
690
+ end
691
+
692
+ type_parameters = init_hash[KEY_TYPE_PARAMETERS]
693
+ unless type_parameters.nil? || type_parameters.empty?
694
+ @type_parameters = {}
695
+ type_parameters.each do |key, param_spec|
696
+ param_value = :undef
697
+ if param_spec.is_a?(Hash)
698
+ param_type = param_spec[KEY_TYPE]
699
+ param_value = param_spec[KEY_VALUE] if param_spec.include?(KEY_VALUE)
700
+ else
701
+ param_type = TypeAsserter.assert_instance_of(nil, PTypeType::DEFAULT, param_spec) { "type_parameter #{label}[#{key}]" }
702
+ end
703
+ param_type = POptionalType.new(param_type) unless param_type.is_a?(POptionalType)
704
+ type_param = PTypeParameter.new(key, self, KEY_TYPE => param_type, KEY_VALUE => param_value).assert_override(parent_type_params)
705
+ @type_parameters[key] = type_param
627
706
  end
628
707
  end
629
708
 
630
709
  constants = init_hash[KEY_CONSTANTS]
631
- attr_specs = init_hash[KEY_ATTRIBUTES] || {}
710
+ attr_specs = init_hash[KEY_ATTRIBUTES]
711
+ if attr_specs.nil?
712
+ attr_specs = {}
713
+ else
714
+ # attr_specs might be frozen
715
+ attr_specs = Hash[attr_specs]
716
+ end
632
717
  unless constants.nil? || constants.empty?
633
718
  constants.each do |key, value|
634
719
  if attr_specs.include?(key)
@@ -641,7 +726,7 @@ class PObjectType < PMetaType
641
726
  KEY_KIND => ATTRIBUTE_KIND_CONSTANT
642
727
  }
643
728
  # Indicate override if parent member exists. Type check etc. will take place later on.
644
- attr_spec[KEY_OVERRIDE] = true if parent_members.include?(key)
729
+ attr_spec[KEY_OVERRIDE] = parent_members.include?(key)
645
730
  attr_specs[key] = attr_spec
646
731
  end
647
732
  end
@@ -728,6 +813,7 @@ class PObjectType < PMetaType
728
813
  guarded_recursion(guard, nil) do |g|
729
814
  super(visitor, g)
730
815
  @parent.accept(visitor, g) unless parent.nil?
816
+ @type_parameters.values.each { |p| p.accept(visitor, g) }
731
817
  @attributes.values.each { |a| a.accept(visitor, g) }
732
818
  @functions.values.each { |f| f.accept(visitor, g) }
733
819
  end
@@ -784,7 +870,21 @@ class PObjectType < PMetaType
784
870
  result = super()
785
871
  result[KEY_NAME] = @name if include_name && !@name.nil?
786
872
  result[KEY_PARENT] = @parent unless @parent.nil?
787
- result[KEY_ATTRIBUTES] = compressed_members_hash(@attributes) unless @attributes.empty?
873
+ result[KEY_TYPE_PARAMETERS] = compressed_members_hash(@type_parameters) unless @type_parameters.empty?
874
+ unless @attributes.empty?
875
+ # Divide attributes into constants and others
876
+ tc = TypeCalculator.singleton
877
+ constants, others = @attributes.partition do |_, a|
878
+ a.kind == ATTRIBUTE_KIND_CONSTANT && a.type == tc.infer(a.value).generalize
879
+ end.map { |ha| Hash[ha] }
880
+
881
+ result[KEY_ATTRIBUTES] = compressed_members_hash(others) unless others.empty?
882
+ unless constants.empty?
883
+ # { kind => 'constant', type => <type of value>, value => <value> } becomes just <value>
884
+ constants.each_pair { |key, a| constants[key] = a.value }
885
+ result[KEY_CONSTANTS] = constants
886
+ end
887
+ end
788
888
  result[KEY_FUNCTIONS] = compressed_members_hash(@functions) unless @functions.empty?
789
889
  result[KEY_EQUALITY] = @equality unless @equality.nil?
790
890
  result[KEY_CHECKS] = @checks unless @checks.nil?
@@ -795,6 +895,7 @@ class PObjectType < PMetaType
795
895
  self.class == o.class &&
796
896
  @name == o.name &&
797
897
  @parent == o.parent &&
898
+ @type_parameters == o.type_parameters &&
798
899
  @attributes == o.attributes &&
799
900
  @functions == o.functions &&
800
901
  @equality == o.equality &&
@@ -802,7 +903,7 @@ class PObjectType < PMetaType
802
903
  end
803
904
 
804
905
  def hash
805
- @name.nil? ? [@parent, @attributes, @functions].hash : @name.hash
906
+ @name.nil? ? [@parent, @type_parameters, @attributes, @functions].hash : @name.hash
806
907
  end
807
908
 
808
909
  def kind_of_callable?(optional=true, guard = nil)
@@ -817,6 +918,14 @@ class PObjectType < PMetaType
817
918
  @parent.nil? ? false : @parent.iterable_type(guard)
818
919
  end
819
920
 
921
+ def parameterized?
922
+ if @type_parameters.empty?
923
+ @parent.is_a?(PObjectType) ? @parent.parameterized? : false
924
+ else
925
+ true
926
+ end
927
+ end
928
+
820
929
  # Returns the members (attributes and functions) of this `Object` type. If _include_parent_ is `true`, then all
821
930
  # inherited members will be included in the returned `Hash`.
822
931
  #
@@ -891,6 +1000,18 @@ class PObjectType < PMetaType
891
1000
  label.split(DOUBLE_COLON).last
892
1001
  end
893
1002
 
1003
+ # Returns the type_parameters of this `Object` type. If _include_parent_ is `true`, then all
1004
+ # inherited type_parameters will be included in the returned `Hash`.
1005
+ #
1006
+ # @param include_parent [Boolean] `true` if inherited type_parameters should be included
1007
+ # @return [Hash{String=>PTypeParameter}] a hash with the type_parameters
1008
+ # @api public
1009
+ def type_parameters(include_parent = false)
1010
+ all = {}
1011
+ collect_type_parameters(all, include_parent)
1012
+ all
1013
+ end
1014
+
894
1015
  protected
895
1016
 
896
1017
  # An Object type is only assignable from another Object type. The other type
@@ -903,6 +1024,8 @@ class PObjectType < PMetaType
903
1024
  op = o.parent
904
1025
  op.nil? ? false : assignable?(op, guard)
905
1026
  end
1027
+ elsif o.is_a?(PObjectTypeExtension)
1028
+ assignable?(o.base_type, guard)
906
1029
  else
907
1030
  false
908
1031
  end
@@ -936,6 +1059,15 @@ class PObjectType < PMetaType
936
1059
  nil
937
1060
  end
938
1061
 
1062
+ def collect_type_parameters(collector, include_parent)
1063
+ if include_parent
1064
+ parent = resolved_parent
1065
+ parent.collect_type_parameters(collector, include_parent) if parent.is_a?(PObjectType)
1066
+ end
1067
+ collector.merge!(@type_parameters)
1068
+ nil
1069
+ end
1070
+
939
1071
  private
940
1072
 
941
1073
  def compressed_members_hash(features)