puppet 4.5.3-universal-darwin → 4.6.1-universal-darwin

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 (422) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +10 -1
  3. data/ext/debian/control +2 -4
  4. data/ext/project_data.yaml +4 -4
  5. data/install.rb +6 -2
  6. data/lib/puppet.rb +3 -1
  7. data/lib/puppet/agent/locker.rb +1 -1
  8. data/lib/puppet/application.rb +6 -4
  9. data/lib/puppet/application/agent.rb +2 -1
  10. data/lib/puppet/application/cert.rb +35 -2
  11. data/lib/puppet/application/device.rb +1 -1
  12. data/lib/puppet/application/generate.rb +5 -0
  13. data/lib/puppet/application/lookup.rb +3 -3
  14. data/lib/puppet/application_support.rb +1 -1
  15. data/lib/puppet/compilable_resource_type.rb +15 -0
  16. data/lib/puppet/configurer.rb +67 -10
  17. data/lib/puppet/configurer/plugin_handler.rb +2 -4
  18. data/lib/puppet/data_providers/hiera_config.rb +1 -1
  19. data/lib/puppet/defaults.rb +34 -7
  20. data/lib/puppet/environments.rb +4 -2
  21. data/lib/puppet/error.rb +1 -1
  22. data/lib/puppet/external/dot.rb +1 -1
  23. data/lib/puppet/face/ca.rb +4 -1
  24. data/lib/puppet/face/certificate.rb +7 -1
  25. data/lib/puppet/face/epp.rb +5 -5
  26. data/lib/puppet/face/generate.rb +64 -0
  27. data/lib/puppet/face/help.rb +19 -13
  28. data/lib/puppet/face/man.rb +1 -1
  29. data/lib/puppet/feature/external_facts.rb +1 -1
  30. data/lib/puppet/file_system.rb +16 -0
  31. data/lib/puppet/file_system/file_impl.rb +5 -0
  32. data/lib/puppet/file_system/memory_impl.rb +4 -0
  33. data/lib/puppet/file_system/path_pattern.rb +1 -0
  34. data/lib/puppet/file_system/windows.rb +19 -0
  35. data/lib/puppet/functions.rb +3 -5
  36. data/lib/puppet/functions/assert_type.rb +1 -1
  37. data/lib/puppet/functions/defined.rb +7 -5
  38. data/lib/puppet/functions/dig.rb +2 -18
  39. data/lib/puppet/functions/hiera.rb +1 -1
  40. data/lib/puppet/functions/lest.rb +1 -37
  41. data/lib/puppet/functions/new.rb +2 -473
  42. data/lib/puppet/functions/reverse_each.rb +2 -59
  43. data/lib/puppet/functions/scanf.rb +4 -4
  44. data/lib/puppet/functions/step.rb +1 -63
  45. data/lib/puppet/functions/then.rb +1 -61
  46. data/lib/puppet/functions/type.rb +1 -40
  47. data/lib/puppet/functions/unwrap.rb +40 -0
  48. data/lib/puppet/generate/models/type/property.rb +70 -0
  49. data/lib/puppet/generate/models/type/type.rb +57 -0
  50. data/lib/puppet/generate/templates/type/pcore.erb +41 -0
  51. data/lib/puppet/generate/type.rb +239 -0
  52. data/lib/puppet/graph/simple_graph.rb +2 -6
  53. data/lib/puppet/indirector/catalog/static_compiler.rb +5 -2
  54. data/lib/puppet/indirector/facts/facter.rb +1 -1
  55. data/lib/puppet/indirector/key/ca.rb +2 -2
  56. data/lib/puppet/indirector/request.rb +25 -4
  57. data/lib/puppet/indirector/rest.rb +73 -3
  58. data/lib/puppet/info_service/class_information_service.rb +1 -2
  59. data/lib/puppet/interface/documentation.rb +1 -1
  60. data/lib/puppet/loaders.rb +2 -0
  61. data/lib/puppet/metatype/manager.rb +6 -6
  62. data/lib/puppet/module.rb +8 -1
  63. data/lib/puppet/module_tool.rb +2 -2
  64. data/lib/puppet/module_tool/checksums.rb +1 -1
  65. data/lib/puppet/module_tool/errors/installer.rb +2 -2
  66. data/lib/puppet/module_tool/metadata.rb +1 -1
  67. data/lib/puppet/network/http/api/indirected_routes.rb +23 -32
  68. data/lib/puppet/network/http/rack/rest.rb +15 -1
  69. data/lib/puppet/network/rights.rb +1 -11
  70. data/lib/puppet/node/environment.rb +7 -3
  71. data/lib/puppet/node/facts.rb +1 -1
  72. data/lib/puppet/parameter.rb +23 -3
  73. data/lib/puppet/parameter/boolean.rb +1 -1
  74. data/lib/puppet/parameter/value.rb +1 -1
  75. data/lib/puppet/parser.rb +0 -1
  76. data/lib/puppet/parser/ast/pops_bridge.rb +1 -1
  77. data/lib/puppet/parser/ast/resource.rb +5 -0
  78. data/lib/puppet/parser/ast/resource_instance.rb +5 -1
  79. data/lib/puppet/parser/ast/resourceparam.rb +5 -0
  80. data/lib/puppet/parser/compiler.rb +14 -17
  81. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +1 -1
  82. data/lib/puppet/parser/environment_compiler.rb +10 -0
  83. data/lib/puppet/parser/functions/create_resources.rb +39 -24
  84. data/lib/puppet/parser/functions/defined.rb +2 -26
  85. data/lib/puppet/parser/functions/dig.rb +29 -0
  86. data/lib/puppet/parser/functions/lest.rb +49 -0
  87. data/lib/puppet/parser/functions/new.rb +530 -0
  88. data/lib/puppet/parser/functions/require.rb +1 -1
  89. data/lib/puppet/parser/functions/reverse_each.rb +83 -0
  90. data/lib/puppet/parser/functions/scanf.rb +4 -4
  91. data/lib/puppet/parser/functions/step.rb +84 -0
  92. data/lib/puppet/parser/functions/then.rb +73 -0
  93. data/lib/puppet/parser/functions/type.rb +53 -0
  94. data/lib/puppet/parser/resource.rb +16 -7
  95. data/lib/puppet/parser/scope.rb +36 -28
  96. data/lib/puppet/parser/type_loader.rb +1 -1
  97. data/lib/puppet/plugins/data_providers/data_provider.rb +1 -1
  98. data/lib/puppet/pops.rb +13 -0
  99. data/lib/puppet/pops/adapters.rb +49 -49
  100. data/lib/puppet/pops/binder/scheme_handler/confdir_scheme.rb +1 -1
  101. data/lib/puppet/pops/evaluator/access_operator.rb +39 -2
  102. data/lib/puppet/pops/evaluator/closure.rb +39 -13
  103. data/lib/puppet/pops/evaluator/collector_transformer.rb +10 -1
  104. data/lib/puppet/pops/evaluator/evaluator_impl.rb +16 -11
  105. data/lib/puppet/pops/evaluator/external_syntax_support.rb +1 -1
  106. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +0 -1
  107. data/lib/puppet/pops/evaluator/literal_evaluator.rb +0 -1
  108. data/lib/puppet/pops/evaluator/relationship_operator.rb +1 -2
  109. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +119 -0
  110. data/lib/puppet/pops/evaluator/runtime3_support.rb +19 -45
  111. data/lib/puppet/pops/functions/function.rb +5 -0
  112. data/lib/puppet/pops/issues.rb +1 -1
  113. data/lib/puppet/pops/label_provider.rb +2 -2
  114. data/lib/puppet/pops/loader/base_loader.rb +12 -15
  115. data/lib/puppet/pops/loader/loader.rb +15 -50
  116. data/lib/puppet/pops/loader/loader_paths.rb +28 -2
  117. data/lib/puppet/pops/loader/module_loaders.rb +16 -1
  118. data/lib/puppet/pops/loader/null_loader.rb +17 -1
  119. data/lib/puppet/pops/loader/puppet_function_instantiator.rb +12 -11
  120. data/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +80 -0
  121. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +2 -3
  122. data/lib/puppet/pops/loader/runtime3_type_loader.rb +52 -13
  123. data/lib/puppet/pops/loader/static_loader.rb +55 -0
  124. data/lib/puppet/pops/loader/type_definition_instantiator.rb +30 -14
  125. data/lib/puppet/pops/loader/typed_name.rb +50 -0
  126. data/lib/puppet/pops/loaders.rb +64 -19
  127. data/lib/puppet/pops/merge_strategy.rb +7 -7
  128. data/lib/puppet/pops/migration/migration_checker.rb +4 -0
  129. data/lib/puppet/pops/model/model_label_provider.rb +2 -0
  130. data/lib/puppet/pops/parser/egrammar.ra +8 -5
  131. data/lib/puppet/pops/parser/eparser.rb +1550 -1498
  132. data/lib/puppet/pops/parser/evaluating_parser.rb +1 -1
  133. data/lib/puppet/pops/parser/interpolation_support.rb +7 -0
  134. data/lib/puppet/pops/parser/lexer2.rb +14 -1
  135. data/lib/puppet/pops/parser/locator.rb +30 -1
  136. data/lib/puppet/pops/parser/parser_support.rb +0 -3
  137. data/lib/puppet/pops/parser/slurp_support.rb +3 -3
  138. data/lib/puppet/pops/patterns.rb +9 -1
  139. data/lib/puppet/pops/pcore.rb +67 -11
  140. data/lib/puppet/pops/puppet_stack.rb +43 -0
  141. data/lib/puppet/pops/resource/param.rb +51 -0
  142. data/lib/puppet/pops/resource/resource_type_impl.rb +301 -0
  143. data/lib/puppet/pops/resource/resource_type_set.pcore +21 -0
  144. data/lib/puppet/pops/serialization.rb +17 -0
  145. data/lib/puppet/pops/serialization/abstract_reader.rb +149 -0
  146. data/lib/puppet/pops/serialization/abstract_writer.rb +179 -0
  147. data/lib/puppet/pops/serialization/deserializer.rb +60 -0
  148. data/lib/puppet/pops/serialization/extension.rb +126 -0
  149. data/lib/puppet/pops/serialization/instance_reader.rb +19 -0
  150. data/lib/puppet/pops/serialization/instance_writer.rb +14 -0
  151. data/lib/puppet/pops/serialization/json.rb +247 -0
  152. data/lib/puppet/pops/serialization/object.rb +63 -0
  153. data/lib/puppet/pops/serialization/rgen.rb +151 -0
  154. data/lib/puppet/pops/serialization/serializer.rb +91 -0
  155. data/lib/puppet/pops/serialization/time_factory.rb +66 -0
  156. data/lib/puppet/pops/types/annotatable.rb +36 -0
  157. data/lib/puppet/pops/types/implementation_registry.rb +3 -8
  158. data/lib/puppet/pops/types/p_meta_type.rb +83 -0
  159. data/lib/puppet/pops/types/p_object_type.rb +110 -117
  160. data/lib/puppet/pops/types/p_runtime_type.rb +13 -0
  161. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +23 -0
  162. data/lib/puppet/pops/types/p_sem_ver_type.rb +30 -2
  163. data/lib/puppet/pops/types/p_sensitive_type.rb +69 -0
  164. data/lib/puppet/pops/types/p_type_set_type.rb +361 -0
  165. data/lib/puppet/pops/types/puppet_object.rb +0 -5
  166. data/lib/puppet/pops/types/ruby_generator.rb +9 -2
  167. data/lib/puppet/pops/types/type_calculator.rb +6 -1
  168. data/lib/puppet/pops/types/type_factory.rb +14 -12
  169. data/lib/puppet/pops/types/type_formatter.rb +78 -33
  170. data/lib/puppet/pops/types/type_mismatch_describer.rb +0 -2
  171. data/lib/puppet/pops/types/type_parser.rb +27 -2
  172. data/lib/puppet/pops/types/type_set_reference.rb +59 -0
  173. data/lib/puppet/pops/types/types.rb +366 -13
  174. data/lib/puppet/pops/validation.rb +4 -4
  175. data/lib/puppet/pops/validation/checker4_0.rb +5 -2
  176. data/lib/puppet/pops/visitor.rb +2 -2
  177. data/lib/puppet/property.rb +64 -5
  178. data/lib/puppet/provider.rb +1 -1
  179. data/lib/puppet/provider/aixobject.rb +3 -3
  180. data/lib/puppet/provider/group/aix.rb +4 -4
  181. data/lib/puppet/provider/macauthorization/macauthorization.rb +1 -1
  182. data/lib/puppet/provider/mailalias/aliases.rb +1 -1
  183. data/lib/puppet/provider/mcx/mcxcontent.rb +2 -2
  184. data/lib/puppet/provider/mount/parsed.rb +1 -1
  185. data/lib/puppet/provider/nameservice/directoryservice.rb +5 -5
  186. data/lib/puppet/provider/package/appdmg.rb +3 -3
  187. data/lib/puppet/provider/package/apple.rb +1 -1
  188. data/lib/puppet/provider/package/dnf.rb +5 -0
  189. data/lib/puppet/provider/package/nim.rb +1 -1
  190. data/lib/puppet/provider/package/pacman.rb +2 -2
  191. data/lib/puppet/provider/package/pip.rb +5 -3
  192. data/lib/puppet/provider/package/pip3.rb +1 -1
  193. data/lib/puppet/provider/package/pkg.rb +5 -5
  194. data/lib/puppet/provider/package/pkgdmg.rb +4 -4
  195. data/lib/puppet/provider/package/pkgin.rb +1 -1
  196. data/lib/puppet/provider/package/pkgutil.rb +1 -1
  197. data/lib/puppet/provider/package/portage.rb +48 -8
  198. data/lib/puppet/provider/package/sun.rb +1 -1
  199. data/lib/puppet/provider/package/tdnf.rb +28 -0
  200. data/lib/puppet/provider/package/yum.rb +22 -4
  201. data/lib/puppet/provider/parsedfile.rb +2 -2
  202. data/lib/puppet/provider/service/base.rb +1 -1
  203. data/lib/puppet/provider/service/bsd.rb +1 -1
  204. data/lib/puppet/provider/service/daemontools.rb +2 -2
  205. data/lib/puppet/provider/service/debian.rb +3 -3
  206. data/lib/puppet/provider/service/init.rb +5 -3
  207. data/lib/puppet/provider/service/launchd.rb +16 -2
  208. data/lib/puppet/provider/service/runit.rb +1 -1
  209. data/lib/puppet/provider/service/smf.rb +8 -1
  210. data/lib/puppet/provider/service/systemd.rb +39 -6
  211. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
  212. data/lib/puppet/provider/user/aix.rb +3 -2
  213. data/lib/puppet/provider/user/directoryservice.rb +4 -3
  214. data/lib/puppet/provider/user/hpux.rb +1 -1
  215. data/lib/puppet/provider/user/user_role_add.rb +1 -1
  216. data/lib/puppet/provider/user/windows_adsi.rb +3 -0
  217. data/lib/puppet/provider/zfs/zfs.rb +1 -1
  218. data/lib/puppet/reference/type.rb +1 -1
  219. data/lib/puppet/resource.rb +33 -7
  220. data/lib/puppet/resource/capability_finder.rb +74 -54
  221. data/lib/puppet/resource/status.rb +11 -2
  222. data/lib/puppet/settings.rb +17 -6
  223. data/lib/puppet/settings/environment_conf.rb +1 -1
  224. data/lib/puppet/settings/server_list_setting.rb +20 -0
  225. data/lib/puppet/ssl/certificate_authority.rb +32 -9
  226. data/lib/puppet/ssl/certificate_authority/interface.rb +164 -24
  227. data/lib/puppet/ssl/host.rb +3 -3
  228. data/lib/puppet/ssl/oids.rb +10 -0
  229. data/lib/puppet/ssl/validator/default_validator.rb +2 -2
  230. data/lib/puppet/test/test_helper.rb +2 -2
  231. data/lib/puppet/transaction.rb +12 -0
  232. data/lib/puppet/transaction/additional_resource_generator.rb +1 -1
  233. data/lib/puppet/transaction/event.rb +29 -2
  234. data/lib/puppet/transaction/event_manager.rb +1 -1
  235. data/lib/puppet/transaction/persistence.rb +84 -0
  236. data/lib/puppet/transaction/report.rb +49 -2
  237. data/lib/puppet/transaction/resource_harness.rb +98 -18
  238. data/lib/puppet/type.rb +63 -21
  239. data/lib/puppet/type/augeas.rb +3 -3
  240. data/lib/puppet/type/cron.rb +1 -1
  241. data/lib/puppet/type/file.rb +39 -2
  242. data/lib/puppet/type/file/data_sync.rb +13 -5
  243. data/lib/puppet/type/host.rb +1 -1
  244. data/lib/puppet/type/mount.rb +2 -6
  245. data/lib/puppet/type/notify.rb +1 -1
  246. data/lib/puppet/type/package.rb +1 -1
  247. data/lib/puppet/type/resources.rb +1 -1
  248. data/lib/puppet/type/scheduled_task.rb +1 -1
  249. data/lib/puppet/type/ssh_authorized_key.rb +2 -2
  250. data/lib/puppet/type/tidy.rb +1 -1
  251. data/lib/puppet/type/yumrepo.rb +3 -3
  252. data/lib/puppet/type/zone.rb +1 -1
  253. data/lib/puppet/util.rb +2 -2
  254. data/lib/puppet/util/classgen.rb +1 -1
  255. data/lib/puppet/util/command_line.rb +6 -2
  256. data/lib/puppet/util/command_line/trollop.rb +1 -1
  257. data/lib/puppet/util/execution.rb +2 -2
  258. data/lib/puppet/util/http_proxy.rb +1 -1
  259. data/lib/puppet/util/inifile.rb +1 -1
  260. data/lib/puppet/util/instance_loader.rb +1 -1
  261. data/lib/puppet/util/logging.rb +1 -1
  262. data/lib/puppet/util/multi_match.rb +1 -1
  263. data/lib/puppet/util/plist.rb +15 -5
  264. data/lib/puppet/util/profiler.rb +1 -1
  265. data/lib/puppet/util/profiler/around_profiler.rb +1 -1
  266. data/lib/puppet/util/psych_support.rb +1 -1
  267. data/lib/puppet/util/rdoc.rb +2 -2
  268. data/lib/puppet/util/rubygems.rb +1 -1
  269. data/lib/puppet/util/watcher/periodic_watcher.rb +2 -2
  270. data/lib/puppet/util/windows/access_control_entry.rb +1 -1
  271. data/lib/puppet/util/windows/adsi.rb +30 -8
  272. data/lib/puppet/util/windows/api_types.rb +1 -1
  273. data/lib/puppet/util/windows/file.rb +59 -0
  274. data/lib/puppet/util/windows/process.rb +10 -0
  275. data/lib/puppet/util/windows/security.rb +1 -1
  276. data/lib/puppet/util/windows/user.rb +22 -4
  277. data/lib/puppet/util/yaml.rb +15 -3
  278. data/lib/puppet/vendor/deep_merge/test/test_deep_merge.rb +1 -1
  279. data/lib/puppet/vendor/rgen_patch.rb +1 -1
  280. data/lib/puppet/version.rb +2 -2
  281. data/spec/fixtures/unit/pops/loaders/loaders/no_modules/manifests/site.pp +10 -0
  282. data/spec/integration/agent/logging_spec.rb +15 -14
  283. data/spec/integration/application/apply_spec.rb +1 -0
  284. data/spec/integration/directory_environments_spec.rb +16 -0
  285. data/spec/integration/environments/settings_spec.rb +32 -4
  286. data/spec/integration/faces/documentation_spec.rb +1 -1
  287. data/spec/integration/network/http/api/indirected_routes_spec.rb +33 -0
  288. data/spec/integration/node/environment_spec.rb +21 -0
  289. data/spec/integration/parser/collection_spec.rb +10 -0
  290. data/spec/integration/parser/compiler_spec.rb +76 -840
  291. data/spec/integration/parser/functions/require_spec.rb +3 -3
  292. data/spec/integration/parser/parameter_defaults_spec.rb +6 -2
  293. data/spec/integration/parser/pcore_resource_spec.rb +208 -0
  294. data/spec/integration/parser/resource_expressions_spec.rb +4 -2
  295. data/spec/integration/provider/yumrepo_spec.rb +4 -1
  296. data/spec/integration/transaction/report_spec.rb +666 -0
  297. data/spec/integration/type/file_spec.rb +11 -12
  298. data/spec/integration/util/windows/adsi_spec.rb +99 -0
  299. data/spec/integration/util/windows/principal_spec.rb +109 -60
  300. data/spec/integration/util/windows/process_spec.rb +4 -2
  301. data/spec/integration/util/windows/security_spec.rb +34 -8
  302. data/spec/integration/util/windows/user_spec.rb +26 -4
  303. data/spec/lib/puppet_spec/files.rb +2 -2
  304. data/spec/lib/puppet_spec/network.rb +12 -8
  305. data/spec/shared_examples/rhel_package_provider.rb +341 -0
  306. data/spec/spec_helper.rb +8 -2
  307. data/spec/unit/application/cert_spec.rb +20 -0
  308. data/spec/unit/configurer/plugin_handler_spec.rb +0 -26
  309. data/spec/unit/configurer_spec.rb +46 -0
  310. data/spec/unit/defaults_spec.rb +14 -0
  311. data/spec/unit/face/generate_spec.rb +230 -0
  312. data/spec/unit/face/help_spec.rb +53 -0
  313. data/spec/unit/face/parser_spec.rb +6 -0
  314. data/spec/unit/face/plugin_spec.rb +0 -4
  315. data/spec/unit/file_system_spec.rb +85 -0
  316. data/spec/unit/functions/lookup_spec.rb +4 -4
  317. data/spec/unit/functions/match_spec.rb +2 -2
  318. data/spec/unit/functions/regsubst_spec.rb +1 -1
  319. data/spec/unit/functions/split_spec.rb +1 -1
  320. data/spec/unit/functions/unwrap_spec.rb +29 -0
  321. data/spec/unit/functions/versioncmp_spec.rb +1 -1
  322. data/spec/unit/functions4_spec.rb +8 -8
  323. data/spec/unit/indirector/facts/facter_spec.rb +1 -9
  324. data/spec/unit/indirector/rest_spec.rb +95 -9
  325. data/spec/unit/module_spec.rb +43 -7
  326. data/spec/unit/module_tool/applications/installer_spec.rb +10 -1
  327. data/spec/unit/module_tool/applications/unpacker_spec.rb +2 -1
  328. data/spec/unit/module_tool/applications/upgrader_spec.rb +8 -0
  329. data/spec/unit/module_tool/tar/mini_spec.rb +3 -3
  330. data/spec/unit/network/http/api/indirected_routes_spec.rb +49 -58
  331. data/spec/unit/network/http/api/master/v3_spec.rb +7 -4
  332. data/spec/unit/network/rights_spec.rb +1 -1
  333. data/spec/unit/parameter_spec.rb +11 -0
  334. data/spec/unit/parser/compiler_spec.rb +19 -33
  335. data/spec/unit/{appmgmt_spec.rb → parser/environment_compiler_spec.rb} +12 -1
  336. data/spec/unit/parser/functions/create_resources_spec.rb +76 -4
  337. data/spec/unit/parser/functions/require_spec.rb +2 -2
  338. data/spec/unit/parser/resource_spec.rb +21 -11
  339. data/spec/unit/parser/scope_spec.rb +1 -5
  340. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +1 -1
  341. data/spec/unit/pops/loaders/dependency_loader_spec.rb +1 -1
  342. data/spec/unit/pops/loaders/loader_paths_spec.rb +1 -1
  343. data/spec/unit/pops/loaders/loaders_spec.rb +63 -5
  344. data/spec/unit/pops/loaders/module_loaders_spec.rb +2 -2
  345. data/spec/unit/pops/loaders/static_loader_spec.rb +1 -1
  346. data/spec/unit/pops/parser/lexer2_spec.rb +27 -3
  347. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +8 -0
  348. data/spec/unit/pops/parser/parse_calls_spec.rb +9 -0
  349. data/spec/unit/pops/puppet_stack_spec.rb +79 -0
  350. data/spec/unit/pops/resource/resource_type_impl_spec.rb +37 -0
  351. data/spec/unit/pops/serialization/packer_spec.rb +153 -0
  352. data/spec/unit/pops/serialization/rgen_spec.rb +88 -0
  353. data/spec/unit/pops/serialization/serialization_spec.rb +228 -0
  354. data/spec/unit/pops/types/p_object_type_spec.rb +44 -2
  355. data/spec/unit/pops/types/p_sem_ver_type_spec.rb +42 -0
  356. data/spec/unit/pops/types/p_sensitive_type_spec.rb +139 -0
  357. data/spec/unit/pops/types/p_type_set_type_spec.rb +424 -0
  358. data/spec/unit/pops/types/ruby_generator_spec.rb +497 -181
  359. data/spec/unit/pops/types/type_calculator_spec.rb +10 -4
  360. data/spec/unit/pops/types/type_formatter_spec.rb +1 -1
  361. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +2 -2
  362. data/spec/unit/pops/types/type_parser_spec.rb +1 -1
  363. data/spec/unit/pops/types/types_spec.rb +1 -1
  364. data/spec/unit/pops/validator/validator_spec.rb +18 -1
  365. data/spec/unit/property_spec.rb +48 -11
  366. data/spec/unit/provider/group/windows_adsi_spec.rb +11 -1
  367. data/spec/unit/provider/package/dnf_spec.rb +1 -99
  368. data/spec/unit/provider/package/pacman_spec.rb +4 -4
  369. data/spec/unit/provider/package/pip_spec.rb +14 -0
  370. data/spec/unit/provider/package/pkg_spec.rb +6 -0
  371. data/spec/unit/provider/package/pkgdmg_spec.rb +0 -3
  372. data/spec/unit/provider/package/portage_spec.rb +64 -8
  373. data/spec/unit/provider/package/tdnf_spec.rb +18 -0
  374. data/spec/unit/provider/package/windows/package_spec.rb +4 -1
  375. data/spec/unit/provider/package/windows_spec.rb +8 -2
  376. data/spec/unit/provider/package/yum_spec.rb +6 -377
  377. data/spec/unit/provider/service/base_spec.rb +6 -0
  378. data/spec/unit/provider/service/debian_spec.rb +16 -7
  379. data/spec/unit/provider/service/gentoo_spec.rb +6 -0
  380. data/spec/unit/provider/service/init_spec.rb +7 -0
  381. data/spec/unit/provider/service/launchd_spec.rb +35 -4
  382. data/spec/unit/provider/service/openrc_spec.rb +6 -0
  383. data/spec/unit/provider/service/smf_spec.rb +31 -6
  384. data/spec/unit/provider/service/src_spec.rb +6 -0
  385. data/spec/unit/provider/service/systemd_spec.rb +70 -20
  386. data/spec/unit/provider/service/upstart_spec.rb +6 -0
  387. data/spec/unit/provider/user/aix_spec.rb +7 -0
  388. data/spec/unit/provider/user/directoryservice_spec.rb +30 -1
  389. data/spec/unit/provider/user/windows_adsi_spec.rb +19 -0
  390. data/spec/unit/resource/capability_finder_spec.rb +51 -3
  391. data/spec/unit/resource/catalog_spec.rb +5 -0
  392. data/spec/unit/resource/type_spec.rb +2 -2
  393. data/spec/unit/resource_spec.rb +19 -0
  394. data/spec/unit/settings_spec.rb +13 -0
  395. data/spec/unit/ssl/certificate_authority/interface_spec.rb +176 -10
  396. data/spec/unit/ssl/certificate_authority_spec.rb +63 -22
  397. data/spec/unit/ssl/host_spec.rb +1 -1
  398. data/spec/unit/ssl/oids_spec.rb +24 -21
  399. data/spec/unit/transaction/event_spec.rb +3 -1
  400. data/spec/unit/transaction/persistence_spec.rb +173 -0
  401. data/spec/unit/transaction/report_spec.rb +64 -1
  402. data/spec/unit/transaction/resource_harness_spec.rb +91 -0
  403. data/spec/unit/type/file/content_spec.rb +47 -15
  404. data/spec/unit/type/file_spec.rb +28 -0
  405. data/spec/unit/type/mount_spec.rb +5 -12
  406. data/spec/unit/type/yumrepo_spec.rb +1 -5
  407. data/spec/unit/type_spec.rb +32 -0
  408. data/spec/unit/util/command_line_spec.rb +11 -0
  409. data/spec/unit/util/execution_spec.rb +1 -1
  410. data/spec/unit/util/plist_spec.rb +16 -3
  411. data/spec/unit/util/storage_spec.rb +4 -1
  412. data/spec/unit/util/windows/adsi_spec.rb +23 -2
  413. data/spec/unit/util/windows/file_spec.rb +56 -1
  414. data/spec/unit/util/windows/sid_spec.rb +31 -7
  415. data/spec/unit/util/yaml_spec.rb +12 -0
  416. data/spec/unit/util_spec.rb +87 -20
  417. metadata +89 -34
  418. data/ext/puppetlisten/puppetlisten.rb +0 -77
  419. data/ext/puppetlisten/puppetrun.rb +0 -38
  420. data/lib/puppet/resource/type_collection_helper.rb +0 -7
  421. data/spec/unit/parser/functions/defined_spec.rb +0 -120
  422. data/spec/unit/resource/type_collection_helper_spec.rb +0 -24
@@ -0,0 +1,91 @@
1
+ require_relative 'extension'
2
+
3
+ module Puppet::Pops
4
+ module Serialization
5
+ # The serializer is capable of writing, arrays, maps, and complex objects using an underlying protocol writer. It takes care of
6
+ # tabulating and disassembling complex objects.
7
+ # @api public
8
+ class Serializer
9
+ # @param [AbstractWriter] writer the writer that is used for writing primitive values
10
+ # @api public
11
+ def initialize(writer)
12
+ @written = {}
13
+ @writer = writer
14
+ end
15
+
16
+ # Tell the underlying writer to finish
17
+ # @api public
18
+ def finish
19
+ @writer.finish
20
+ end
21
+
22
+ # Write an object
23
+ # @param [Object] value the object to write
24
+ # @api public
25
+ def write(value)
26
+ case value
27
+ when Integer, Float, String, true, false, nil, Time
28
+ @writer.write(value)
29
+ when :default
30
+ @writer.write(Extension::Default::INSTANCE)
31
+ else
32
+ index = @written[value.object_id]
33
+ if index.nil?
34
+ write_tabulated_first_time(value)
35
+ else
36
+ @writer.write(Extension::Tabulation.new(index)) unless index.nil?
37
+ end
38
+ end
39
+ end
40
+
41
+ # Write the start of an array.
42
+ # @param [Integer] size the size of the array
43
+ # @api private
44
+ def start_array(size)
45
+ @writer.write(Extension::ArrayStart.new(size))
46
+ end
47
+
48
+ # Write the start of a map (hash).
49
+ # @param [Integer] size the number of entries in the map
50
+ # @api private
51
+ def start_map(size)
52
+ @writer.write(Extension::MapStart.new(size))
53
+ end
54
+
55
+ # Write the start of a complex object
56
+ # @param [String] type_ref the name of the type
57
+ # @param [Integer] attr_count the number of attributes in the object
58
+ # @api private
59
+ def start_object(type_ref, attr_count)
60
+ @writer.write(Extension::ObjectStart.new(type_ref, attr_count))
61
+ end
62
+
63
+ # First time write of a tabulated object. This means that the object is written and then remembered. Subsequent writes
64
+ # of the same object will yield a write of a tabulation index instead.
65
+ # @param [Object] value the value to write
66
+ # @api private
67
+ def write_tabulated_first_time(value)
68
+ @written[value.object_id] = @written.size
69
+ case value
70
+ when Symbol, Regexp, Semantic::Version, Semantic::VersionRange
71
+ @writer.write(value)
72
+ when Array
73
+ start_array(value.size)
74
+ value.each { |elem| write(elem) }
75
+ when Hash
76
+ start_map(value.size)
77
+ value.each_pair { |key, val| write(key); write(val) }
78
+ when Types::PTypeReferenceType
79
+ @writer.write(value)
80
+ when Types::PuppetObject
81
+ value._ptype.write(value, self)
82
+ else
83
+ impl_class = value.class
84
+ type = Loaders.implementation_registry.type_for_module(impl_class)
85
+ raise SerializationError, "No Puppet Type found for #{impl_class.name}" unless type.is_a?(Types::PObjectType)
86
+ type.write(value, self)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,66 @@
1
+ module Puppet::Pops
2
+ module Serialization
3
+ # Implements all the constructors found in the Time class and ensures that
4
+ # the created Time object can be serialized and deserialized using its
5
+ # seconds and nanoseconds without loss of precision.
6
+ #
7
+ # @api public
8
+ class TimeFactory
9
+
10
+ NANO_DENOMINATOR = 10**9
11
+
12
+ def self.at(*args)
13
+ sec_nsec_safe(Time.at(*args))
14
+ end
15
+
16
+ def self.gm(*args)
17
+ sec_nsec_safe(Time.gm(*args))
18
+ end
19
+
20
+ def self.local(*args)
21
+ sec_nsec_safe(Time.local(*args))
22
+ end
23
+
24
+ def self.mktime(*args)
25
+ sec_nsec_safe(Time.mktime(*args))
26
+ end
27
+
28
+ def self.new(*args)
29
+ sec_nsec_safe(Time.new(*args))
30
+ end
31
+
32
+ def self.now
33
+ sec_nsec_safe(Time.now)
34
+ end
35
+
36
+ def self.utc(*args)
37
+ sec_nsec_safe(Time.utc(*args))
38
+ end
39
+
40
+ # Creates a Time object from a Rational defined as:
41
+ #
42
+ # (_sec_ * #NANO_DENOMINATOR + _nsec_) / #NANO_DENOMINATOR
43
+ #
44
+ # This ensures that a Time object can be reliably serialized and using its
45
+ # its #tv_sec and #tv_nsec values and then recreated again (using this method)
46
+ # without loss of precision.
47
+ #
48
+ # @param sec [Integer] seconds since Epoch
49
+ # @param nsec [Integer] nano seconds
50
+ # @return [Time] the created object
51
+ #
52
+ def self.from_sec_nsec(sec, nsec)
53
+ Time.at(Rational(sec * NANO_DENOMINATOR + nsec, NANO_DENOMINATOR))
54
+ end
55
+
56
+ # Returns a new Time object that is adjusted to ensure that precision is not
57
+ # lost when it is serialized and deserialized using its seconds and nanoseconds
58
+ # @param t [Time] the object to adjust
59
+ # @return [Time] the adjusted object
60
+ #
61
+ def self.sec_nsec_safe(t)
62
+ from_sec_nsec(t.tv_sec, t.tv_nsec)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,36 @@
1
+ module Puppet::Pops
2
+ module Types
3
+
4
+ KEY_ANNOTATIONS = 'annotations'.freeze
5
+
6
+ # Behaviour common to all Pcore annotatable classes
7
+ #
8
+ # @api public
9
+ module Annotatable
10
+ TYPE_ANNOTATION_KEY_TYPE = PType::DEFAULT # TBD
11
+ TYPE_ANNOTATION_VALUE_TYPE = PStructType::DEFAULT #TBD
12
+ TYPE_ANNOTATIONS = PHashType.new(TYPE_ANNOTATION_KEY_TYPE, TYPE_ANNOTATION_VALUE_TYPE)
13
+
14
+ # @return [{PType => PStructType}] the map of annotations
15
+ # @api public
16
+ attr_reader :annotations
17
+
18
+ # @api private
19
+ def init_annotatable(i12n_hash)
20
+ @annotations = i12n_hash[KEY_ANNOTATIONS].freeze
21
+ end
22
+
23
+ # @api private
24
+ def annotatable_accept(visitor, guard)
25
+ @annotations.each_key { |key| key.accept(visitor, guard) } unless @annotations.nil?
26
+ end
27
+
28
+ # @api private
29
+ def i12n_hash
30
+ result = {}
31
+ result[KEY_ANNOTATIONS] = @annotations unless @annotations.nil?
32
+ result
33
+ end
34
+ end
35
+ end
36
+ end
@@ -21,11 +21,6 @@ module Types
21
21
  @implementations_per_type_name = {}
22
22
  @type_name_substitutions = []
23
23
  @impl_name_substitutions = []
24
- @type_parser = Types::TypeParser.new
25
-
26
- register_implementation('Pcore::AST::Locator', 'Puppet::Pops::Parser::Locator::Locator19', static_loader)
27
- register_implementation_namespace('Pcore::AST', 'Puppet::Pops::Model', static_loader)
28
-
29
24
  TypeParser.type_map.values.each { |type| register_implementation(type.simple_name, type.class.name, static_loader) }
30
25
  end
31
26
 
@@ -59,8 +54,8 @@ module Types
59
54
  def register_implementation_namespace(type_namespace, impl_namespace, loader)
60
55
  ns = TypeFormatter::NAME_SEGMENT_SEPARATOR
61
56
  register_implementation_regexp(
62
- [Regexp.compile("^#{type_namespace}#{ns}(\\w+)$"), "#{impl_namespace}#{ns}\\1"],
63
- [Regexp.compile("^#{impl_namespace}#{ns}(\\w+)$"), "#{type_namespace}#{ns}\\1"],
57
+ [/\A#{type_namespace}#{ns}(\w+)\z/, "#{impl_namespace}#{ns}\\1"],
58
+ [/\A#{impl_namespace}#{ns}(\w+)\z/, "#{type_namespace}#{ns}\\1"],
64
59
  loader)
65
60
  end
66
61
 
@@ -127,7 +122,7 @@ module Types
127
122
  if name_and_loader.nil?
128
123
  nil
129
124
  else
130
- @type_parser.parse(*name_and_loader)
125
+ TypeParser.singleton.parse(*name_and_loader)
131
126
  end
132
127
  end
133
128
 
@@ -0,0 +1,83 @@
1
+ # @abstract base class for PObjectType and other types that implements lazy evaluation of content
2
+ # @api private
3
+ module Puppet::Pops
4
+ module Types
5
+
6
+ KEY_NAME = 'name'.freeze
7
+ KEY_TYPE = 'type'.freeze
8
+ KEY_VALUE = 'value'.freeze
9
+
10
+ class PMetaType < PAnyType
11
+ include Annotatable
12
+
13
+ def self.register_ptype(loader, ir)
14
+ # Abstract type. It doesn't register anything
15
+ end
16
+
17
+ def accept(visitor, guard)
18
+ annotatable_accept(visitor, guard)
19
+ super
20
+ end
21
+
22
+ # Called from the TypeParser once it has found a type using the Loader. The TypeParser will
23
+ # interpret the contained expression and the resolved type is remembered. This method also
24
+ # checks and remembers if the resolve type contains self recursion.
25
+ #
26
+ # @param type_parser [TypeParser] type parser that will interpret the type expression
27
+ # @param loader [Loader::Loader] loader to use when loading type aliases
28
+ # @return [PTypeAliasType] the receiver of the call, i.e. `self`
29
+ # @api private
30
+ def resolve(type_parser, loader)
31
+ unless @i12n_hash_expression.nil?
32
+ @self_recursion = true # assumed while it being found out below
33
+
34
+ i12n_hash_expression = @i12n_hash_expression
35
+ @i12n_hash_expression = nil
36
+ if i12n_hash_expression.is_a?(Model::LiteralHash)
37
+ i12n_hash = resolve_literal_hash(type_parser, loader, i12n_hash_expression)
38
+ else
39
+ i12n_hash = resolve_hash(type_parser, loader, i12n_hash_expression)
40
+ end
41
+ initialize_from_hash(i12n_hash)
42
+
43
+ # Find out if this type is recursive. A recursive type has performance implications
44
+ # on several methods and this knowledge is used to avoid that for non-recursive
45
+ # types.
46
+ guard = RecursionGuard.new
47
+ accept(NoopTypeAcceptor::INSTANCE, guard)
48
+ @self_recursion = guard.recursive_this?(self)
49
+ end
50
+ self
51
+ end
52
+
53
+ def resolve_literal_hash(type_parser, loader, i12n_hash_expression)
54
+ type_parser.interpret_LiteralHash(i12n_hash_expression, loader)
55
+ end
56
+
57
+ def resolve_hash(type_parser, loader, i12n_hash)
58
+ resolve_type_refs(type_parser, loader, i12n_hash)
59
+ end
60
+
61
+ def resolve_type_refs(type_parser, loader, o)
62
+ case o
63
+ when Hash
64
+ Hash[o.map { |k, v| [resolve_type_refs(type_parser, loader, k), resolve_type_refs(type_parser, loader, v)] }]
65
+ when Array
66
+ o.map { |e| resolve_type_refs(type_parser, loader, e) }
67
+ when PAnyType
68
+ o.resolve(type_parser, loader)
69
+ else
70
+ o
71
+ end
72
+ end
73
+
74
+ # Returns the expanded string the form of the alias, e.g. <alias name> = <resolved type>
75
+ #
76
+ # @return [String] the expanded form of this alias
77
+ # @api public
78
+ def to_s
79
+ TypeFormatter.singleton.alias_expanded_string(self)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -3,31 +3,24 @@ require_relative 'ruby_generator'
3
3
  module Puppet::Pops
4
4
  module Types
5
5
 
6
+ KEY_ATTRIBUTES = 'attributes'.freeze
7
+ KEY_CHECKS = 'checks'.freeze
8
+ KEY_EQUALITY = 'equality'.freeze
9
+ KEY_EQUALITY_INCLUDE_TYPE = 'equality_include_type'.freeze
10
+ KEY_FINAL = 'final'.freeze
11
+ KEY_FUNCTIONS = 'functions'.freeze
12
+ KEY_KIND = 'kind'.freeze
13
+ KEY_OVERRIDE = 'override'.freeze
14
+ KEY_PARENT = 'parent'.freeze
15
+
6
16
  # @api public
7
- class PObjectType < PAnyType
8
- KEY_ANNOTATIONS = 'annotations'.freeze
9
- KEY_ATTRIBUTES = 'attributes'.freeze
10
- KEY_CHECKS = 'checks'.freeze
11
- KEY_EQUALITY = 'equality'.freeze
12
- KEY_EQUALITY_INCLUDE_TYPE = 'equality_include_type'.freeze
13
- KEY_FINAL = 'final'.freeze
14
- KEY_FUNCTIONS = 'functions'.freeze
15
- KEY_KIND = 'kind'.freeze
16
- KEY_NAME = 'name'.freeze
17
- KEY_OVERRIDE = 'override'.freeze
18
- KEY_PARENT = 'parent'.freeze
19
- KEY_TYPE = 'type'.freeze
20
- KEY_VALUE = 'value'.freeze
17
+ class PObjectType < PMetaType
21
18
 
22
19
  ATTRIBUTE_KIND_CONSTANT = 'constant'.freeze
23
20
  ATTRIBUTE_KIND_DERIVED = 'derived'.freeze
24
21
  ATTRIBUTE_KIND_GIVEN_OR_DERIVED = 'given_or_derived'.freeze
25
22
  TYPE_ATTRIBUTE_KIND = TypeFactory.enum(ATTRIBUTE_KIND_CONSTANT, ATTRIBUTE_KIND_DERIVED, ATTRIBUTE_KIND_GIVEN_OR_DERIVED)
26
23
 
27
- TYPE_ANNOTATION_KEY_TYPE = PType::DEFAULT # TBD
28
- TYPE_ANNOTATION_VALUE_TYPE = PStructType::DEFAULT #TBD
29
- TYPE_ANNOTATIONS = PHashType.new(TYPE_ANNOTATION_KEY_TYPE, TYPE_ANNOTATION_VALUE_TYPE)
30
-
31
24
  TYPE_OBJECT_NAME = Pcore::TYPE_QUALIFIED_REFERENCE
32
25
  TYPE_MEMBER_NAME = PPatternType.new([PRegexpType.new(Patterns::PARAM_NAME)])
33
26
 
@@ -67,9 +60,14 @@ class PObjectType < PAnyType
67
60
  KEY_ANNOTATIONS => TypeFactory.optional(TYPE_ANNOTATIONS)
68
61
  })
69
62
 
63
+ def self.register_ptype(loader, ir)
64
+ create_ptype(loader, ir, 'AnyType', 'i12n_hash' => TYPE_OBJECT_I12N)
65
+ end
66
+
70
67
  # @abstract Encapsulates behavior common to {PAttribute} and {PFunction}
71
68
  # @api public
72
69
  class PAnnotatedMember
70
+ include Annotatable
73
71
 
74
72
  # @return [PObjectType] the object type containing this member
75
73
  # @api public
@@ -83,10 +81,6 @@ class PObjectType < PAnyType
83
81
  # @api public
84
82
  attr_reader :type
85
83
 
86
- # @return [Hash{PType => Hash}] the annotations or `nil`
87
- # @api public
88
- attr_reader :annotations
89
-
90
84
  # @param name [String] The name of the member
91
85
  # @param container [PObjectType] The containing object type
92
86
  # @param i12n_hash [Hash{String=>Object}] Hash containing feature options
@@ -103,8 +97,7 @@ class PObjectType < PAnyType
103
97
  @override = false if @override.nil?
104
98
  @final = i12n_hash[KEY_FINAL]
105
99
  @final = false if @final.nil?
106
- @annotations = i12n_hash[KEY_ANNOTATIONS]
107
- @annotations.freeze unless @annotations.nil?
100
+ init_annotatable(i12n_hash)
108
101
  end
109
102
 
110
103
  # Delegates to the contained type
@@ -112,8 +105,8 @@ class PObjectType < PAnyType
112
105
  # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
113
106
  # @api public
114
107
  def accept(visitor, guard)
108
+ annotatable_accept(visitor, guard)
115
109
  @type.accept(visitor, guard)
116
- @annotations.each_key { |key| key.accept(visitor, guard) } unless @annotations.nil?
117
110
  end
118
111
 
119
112
  # Checks if the this _member_ overrides an inherited member, and if so, that this member is declared with override = true and that
@@ -260,7 +253,8 @@ class PObjectType < PAnyType
260
253
  if @kind == ATTRIBUTE_KIND_DERIVED || @kind == ATTRIBUTE_KIND_GIVEN_OR_DERIVED
261
254
  raise Puppet::ParseError, "#{label} of kind '#{@kind}' cannot be combined with an attribute value"
262
255
  end
263
- @value = TypeAsserter.assert_instance_of(nil, type, i12n_hash[KEY_VALUE]) {"#{label} #{KEY_VALUE}" }
256
+ v = i12n_hash[KEY_VALUE]
257
+ @value = v == :default ? v : TypeAsserter.assert_instance_of(nil, type, v) {"#{label} #{KEY_VALUE}" }
264
258
  else
265
259
  raise Puppet::ParseError, "#{label} of kind 'constant' requires a value" if @kind == ATTRIBUTE_KIND_CONSTANT
266
260
  @value = :undef # Not to be confused with nil or :default
@@ -375,48 +369,50 @@ class PObjectType < PAnyType
375
369
  @new_function ||= create_new_function(loader)
376
370
  end
377
371
 
372
+ # Assign a new instance reader to this type
373
+ # @param [Serialization::InstanceReader] reader the reader to assign
378
374
  # @api private
379
- def create_new_function(loader)
380
- impl_name = Loaders.implementation_registry.module_name_for_type(self)
381
- if impl_name.nil?
382
- # Use generator to create a default implementation
383
- impl_class = RubyGenerator.new.create_class(self)
384
- class_name = "Anonymous Ruby class for #{name}"
385
- else
386
- # Can the mapping be loaded?
387
- class_name = impl_name[0]
388
- impl_class = ClassLoader.provide(class_name)
375
+ def reader=(reader)
376
+ @reader = reader
377
+ end
389
378
 
390
- raise Puppet::Error, "Unable to load class #{class_name}" if impl_class.nil?
391
- unless impl_class < PuppetObject
392
- raise Puppet::Error, "Unable to create an instance of #{name}. #{class_name} does not include module #{PuppetObject.name}"
393
- end
394
- end
379
+ # Assign a new instance write to this type
380
+ # @param [Serialization::InstanceWriter] the writer to assign
381
+ # @api private
382
+ def writer=(writer)
383
+ @writer = writer
384
+ end
395
385
 
396
- i12n_t = i12n_type
397
- from_hash_type = TypeFactory.callable(i12n_t, 1, 1)
386
+ # Read an instance of this type from a deserializer
387
+ # @param [Integer] value_count the number attributes needed to create the instance
388
+ # @param [Serialization::Deserializer] deserializer the deserializer to read from
389
+ # @return [Object] the created instance
390
+ # @api private
391
+ def read(value_count, deserializer)
392
+ reader.read(implementation_class, value_count, deserializer)
393
+ end
398
394
 
399
- # Create a types and a names array where optional entries ends up last
400
- opt_types = []
401
- opt_names = []
402
- non_opt_types = []
403
- non_opt_names = []
404
- i12n_t.elements.each do |se|
405
- if se.key_type.is_a?(POptionalType)
406
- opt_names << se.name
407
- opt_types << se.value_type
408
- else
409
- non_opt_names << se.name
410
- non_opt_types << se.value_type
411
- end
412
- end
413
- param_names = non_opt_names + opt_names
414
- param_types = non_opt_types + opt_types
395
+ # Write an instance of this type using a serializer
396
+ # @param [Object] value the instance to write
397
+ # @param [Serialization::Serializer] the serializer to write to
398
+ # @api private
399
+ def write(value, serializer)
400
+ writer.write(self, value, serializer)
401
+ end
402
+
403
+ # @api private
404
+ def create_new_function(loader)
405
+ impl_class = implementation_class
406
+ class_name = impl_class.name || "Anonymous Ruby class for #{name}"
407
+
408
+ (param_names, param_types, required_param_count) = parameter_info
415
409
 
416
410
  # Create the callable with a size that reflects the required and optional parameters
417
- param_types << non_opt_types.size
411
+ param_types << required_param_count
418
412
  param_types << param_names.size
413
+
419
414
  create_type = TypeFactory.callable(*param_types)
415
+ from_hash_type = TypeFactory.callable(i12n_type, 1, 1)
420
416
 
421
417
  # Create and return a #new_XXX function where the dispatchers are added programmatically.
422
418
  Puppet::Functions.create_loaded_function(:"new_#{name}", loader) do
@@ -450,62 +446,63 @@ class PObjectType < PAnyType
450
446
  end
451
447
 
452
448
  # @api private
453
- def include_class_in_equality?
454
- @equality_include_type && !(@parent.is_a?(PObjectType) && parent.include_class_in_equality?)
449
+ def implementation_class
450
+ if @implementation_class.nil?
451
+ impl_name = Loaders.implementation_registry.module_name_for_type(self)
452
+ if impl_name.nil?
453
+ # Use generator to create a default implementation
454
+ @implementation_class = RubyGenerator.new.create_class(self)
455
+ else
456
+ # Can the mapping be loaded?
457
+ class_name = impl_name[0]
458
+ @implementation_class = ClassLoader.provide(class_name)
459
+
460
+ raise Puppet::Error, "Unable to load class #{class_name}" if @implementation_class.nil?
461
+ unless @implementation_class < PuppetObject || @implementation_class.respond_to?(:ecore)
462
+ raise Puppet::Error, "Unable to create an instance of #{name}. #{class_name} does not include module #{PuppetObject.name}"
463
+ end
464
+ end
465
+ end
466
+ @implementation_class
455
467
  end
456
468
 
457
- # Called from the TypeParser once it has found a type using the Loader. The TypeParser will
458
- # interpret the contained expression and the resolved type is remembered. This method also
459
- # checks and remembers if the resolve type contains self recursion.
460
- #
461
- # @param type_parser [TypeParser] type parser that will interpret the type expression
462
- # @param loader [Loader::Loader] loader to use when loading type aliases
463
- # @return [PObjectType] the receiver of the call, i.e. `self`
464
469
  # @api private
465
- def resolve(type_parser, loader)
466
- unless @i12n_hash_expression.nil?
467
- @self_recursion = true # assumed while it being found out below
468
-
469
- i12n_hash_expression = @i12n_hash_expression
470
- @i12n_hash_expression = nil
471
- if i12n_hash_expression.is_a?(Model::LiteralHash)
472
- i12n_hash = resolve_literal_hash(type_parser, loader, i12n_hash_expression)
470
+ # @return [(Array<String>, Array<PAnyType>, Integer)] array of parameter names, array of parameter types, and a count reflecting the required number of parameters
471
+ def parameter_info(attr_readers = false)
472
+ # Create a types and a names array where optional entries ends up last
473
+ opt_types = []
474
+ opt_names = []
475
+ non_opt_types = []
476
+ non_opt_names = []
477
+ i12n_type.elements.each do |se|
478
+ if se.key_type.is_a?(POptionalType)
479
+ opt_names << (attr_readers ? attr_reader_name(se) : se.name)
480
+ opt_types << se.value_type
473
481
  else
474
- i12n_hash = resolve_hash(type_parser, loader, i12n_hash_expression)
482
+ non_opt_names << (attr_readers ? attr_reader_name(se) : se.name)
483
+ non_opt_types << se.value_type
475
484
  end
476
- initialize_from_hash(i12n_hash)
477
-
478
- # Find out if this type is recursive. A recursive type has performance implications
479
- # on several methods and this knowledge is used to avoid that for non-recursive
480
- # types.
481
- guard = RecursionGuard.new
482
- accept(NoopTypeAcceptor::INSTANCE, guard)
483
- @self_recursion = guard.recursive_this?(self)
484
485
  end
485
- self
486
- end
487
-
488
- def resolve_literal_hash(type_parser, loader, i12n_hash_expression)
489
- type_parser.interpret_LiteralHash(i12n_hash_expression, loader)
490
- end
486
+ param_names = non_opt_names + opt_names
487
+ param_types = non_opt_types + opt_types
491
488
 
492
- def resolve_hash(type_parser, loader, i12n_hash)
493
- resolve_type_refs(type_parser, loader, i12n_hash)
489
+ [param_names, param_types, non_opt_types.size]
494
490
  end
495
491
 
496
- def resolve_type_refs(type_parser, loader, o)
497
- case o
498
- when Hash
499
- Hash[o.map { |k, v| [resolve_type_refs(type_parser, loader, k), resolve_type_refs(type_parser, loader, v)] }]
500
- when Array
501
- o.map { |e| resolve_type_refs(type_parser, loader, e) }
502
- when PTypeReferenceType
503
- o.resolve(type_parser, loader)
492
+ # @api private
493
+ def attr_reader_name(se)
494
+ if se.value_type.is_a?(PBooleanType) || se.value_type.is_a?(POptionalType) && se.value_type.type.is_a?(PBooleanType)
495
+ "#{se.name}?"
504
496
  else
505
- o
497
+ se.name
506
498
  end
507
499
  end
508
500
 
501
+ # @api private
502
+ def include_class_in_equality?
503
+ @equality_include_type && !(@parent.is_a?(PObjectType) && parent.include_class_in_equality?)
504
+ end
505
+
509
506
  # @api private
510
507
  def initialize_from_hash(i12n_hash)
511
508
  TypeAsserter.assert_instance_of('object initializer', TYPE_OBJECT_I12N, i12n_hash)
@@ -584,9 +581,7 @@ class PObjectType < PAnyType
584
581
  @equality = equality
585
582
 
586
583
  @checks = i12n_hash[KEY_CHECKS]
587
-
588
- @annotations = i12n_hash[KEY_ANNOTATIONS]
589
- @annotations.freeze unless @annotations.nil?
584
+ init_annotatable(i12n_hash)
590
585
  end
591
586
 
592
587
  def [](name)
@@ -604,7 +599,6 @@ class PObjectType < PAnyType
604
599
  @parent.accept(visitor, g) unless parent.nil?
605
600
  @attributes.values.each { |a| a.accept(visitor, g) }
606
601
  @functions.values.each { |f| f.accept(visitor, g) }
607
- @annotations.each_key { |key| key.accept(visitor, g) } unless @annotations.nil?
608
602
  end
609
603
  end
610
604
 
@@ -644,14 +638,13 @@ class PObjectType < PAnyType
644
638
  # @return [Hash{String=>Object}] the features hash
645
639
  # @api public
646
640
  def i12n_hash(include_name = true)
647
- result = {}
641
+ result = super()
648
642
  result[KEY_NAME] = @name if include_name && !@name.nil?
649
643
  result[KEY_PARENT] = @parent unless @parent.nil?
650
644
  result[KEY_ATTRIBUTES] = compressed_members_hash(@attributes) unless @attributes.empty?
651
645
  result[KEY_FUNCTIONS] = compressed_members_hash(@functions) unless @functions.empty?
652
646
  result[KEY_EQUALITY] = @equality unless @equality.nil?
653
647
  result[KEY_CHECKS] = @checks unless @checks.nil?
654
- result[KEY_ANNOTATIONS] = @annotations unless @annotations.nil?
655
648
  result
656
649
  end
657
650
 
@@ -741,14 +734,6 @@ class PObjectType < PAnyType
741
734
  end
742
735
  end
743
736
 
744
- # Returns the expanded string the form of the alias, e.g. <alias name> = <resolved type>
745
- #
746
- # @return [String] the expanded form of this alias
747
- # @api public
748
- def to_s
749
- TypeFormatter.singleton.alias_expanded_string(self)
750
- end
751
-
752
737
  # @api private
753
738
  def label
754
739
  @name || '<anonymous object type>'
@@ -841,6 +826,14 @@ class PObjectType < PAnyType
841
826
  yield(guard)
842
827
  end
843
828
  end
829
+
830
+ def reader
831
+ @reader ||= Serialization::ObjectReader::INSTANCE
832
+ end
833
+
834
+ def writer
835
+ @writer ||= Serialization::ObjectWriter::INSTANCE
836
+ end
844
837
  end
845
838
  end
846
839
  end