puppet 4.3.2-x64-mingw32 → 4.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.
- checksums.yaml +4 -4
- data/COMMITTERS.md +2 -2
- data/CONTRIBUTING.md +6 -6
- data/LICENSE +1 -1
- data/README.md +8 -9
- data/conf/auth.conf +2 -2
- data/ext/README.environment +1 -1
- data/ext/debian/README.source +1 -1
- data/ext/debian/control +1 -1
- data/ext/debian/copyright +4 -4
- data/ext/debian/puppetmaster.README.debian +11 -9
- data/ext/emacs/puppet-mode.el +1 -1
- data/ext/envpuppet +2 -2
- data/ext/ips/puppetagent.xml +1 -1
- data/ext/ips/puppetmaster.xml +1 -1
- data/ext/project_data.yaml +8 -0
- data/ext/puppet-test +3 -3
- data/ext/rack/example-passenger-vhost.conf +1 -1
- data/ext/redhat/puppet.spec.erb +2 -2
- data/ext/regexp_nodes/regexp_nodes.rb +1 -1
- data/ext/solaris/pkginfo +1 -1
- data/ext/solaris/smf/puppet.xml +1 -1
- data/ext/suse/puppet.spec +2 -2
- data/ext/upload_facts.rb +1 -1
- data/ext/windows/puppet_interactive.bat +6 -0
- data/ext/windows/puppet_shell.bat +9 -0
- data/ext/windows/run_puppet_interactive.bat +9 -0
- data/ext/yaml_nodes.rb +1 -1
- data/install.rb +30 -20
- data/lib/puppet/agent.rb +1 -1
- data/lib/puppet/application/agent.rb +4 -2
- data/lib/puppet/application/apply.rb +7 -4
- data/lib/puppet/application/cert.rb +1 -1
- data/lib/puppet/application/device.rb +1 -1
- data/lib/puppet/application/filebucket.rb +1 -1
- data/lib/puppet/application/inspect.rb +1 -1
- data/lib/puppet/application/lookup.rb +4 -4
- data/lib/puppet/application/master.rb +2 -2
- data/lib/puppet/application/resource.rb +1 -1
- data/lib/puppet/configurer.rb +100 -22
- data/lib/puppet/data_providers/hiera_config.rb +28 -3
- data/lib/puppet/data_providers/hiera_interpolate.rb +30 -15
- data/lib/puppet/data_providers/hiera_support.rb +1 -1
- data/lib/puppet/data_providers/json_data_provider_factory.rb +2 -2
- data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -2
- data/lib/puppet/defaults.rb +65 -19
- data/lib/puppet/environments.rb +3 -1
- data/lib/puppet/face/config.rb +1 -1
- data/lib/puppet/face/epp.rb +1 -1
- data/lib/puppet/face/help/man.erb +1 -1
- data/lib/puppet/face/module/install.rb +6 -6
- data/lib/puppet/face/parser.rb +12 -9
- data/lib/puppet/face/status.rb +2 -1
- data/lib/puppet/feature/cfpropertylist.rb +3 -0
- data/lib/puppet/feature/telnet.rb +9 -0
- data/lib/puppet/file_serving/http_metadata.rb +46 -0
- data/lib/puppet/file_serving/metadata.rb +18 -2
- data/lib/puppet/file_serving/terminus_selector.rb +2 -0
- data/lib/puppet/file_system.rb +2 -2
- data/lib/puppet/file_system/file_impl.rb +2 -2
- data/lib/puppet/file_system/memory_impl.rb +1 -1
- data/lib/puppet/file_system/uniquefile.rb +1 -1
- data/lib/puppet/forge.rb +1 -1
- data/lib/puppet/forge/repository.rb +1 -31
- data/lib/puppet/functions.rb +45 -6
- data/lib/puppet/functions/assert_type.rb +9 -9
- data/lib/puppet/functions/each.rb +5 -13
- data/lib/puppet/functions/filter.rb +5 -14
- data/lib/puppet/functions/map.rb +6 -14
- data/lib/puppet/functions/reduce.rb +5 -13
- data/lib/puppet/functions/reverse_each.rb +82 -0
- data/lib/puppet/functions/scanf.rb +15 -18
- data/lib/puppet/functions/slice.rb +22 -36
- data/lib/puppet/functions/split.rb +2 -2
- data/lib/puppet/functions/step.rb +88 -0
- data/lib/puppet/functions/type.rb +70 -0
- data/lib/puppet/graph/rb_tree_map.rb +1 -1
- data/lib/puppet/indirector/catalog/compiler.rb +188 -5
- data/lib/puppet/indirector/file_content/http.rb +15 -0
- data/lib/puppet/indirector/file_metadata/http.rb +27 -0
- data/lib/puppet/indirector/generic_http.rb +16 -0
- data/lib/puppet/indirector/node/exec.rb +1 -1
- data/lib/puppet/indirector/node/ldap.rb +1 -1
- data/lib/puppet/indirector/rest.rb +2 -1
- data/lib/puppet/info_service/class_information_service.rb +13 -12
- data/lib/puppet/loaders.rb +1 -0
- data/lib/puppet/module.rb +3 -0
- data/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +9 -2
- data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +1 -1
- data/lib/puppet/module_tool/skeleton/templates/generator/tests/init.pp.erb +2 -2
- data/lib/puppet/module_tool/tar/mini.rb +3 -3
- data/lib/puppet/network/http/pool.rb +9 -0
- data/lib/puppet/node.rb +1 -1
- data/lib/puppet/node/environment.rb +11 -2
- data/lib/puppet/parser/ast/pops_bridge.rb +19 -22
- data/lib/puppet/parser/compiler.rb +3 -3
- data/lib/puppet/parser/environment_compiler.rb +0 -1
- data/lib/puppet/parser/functions.rb +28 -16
- data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
- data/lib/puppet/parser/functions/inline_template.rb +1 -1
- data/lib/puppet/parser/functions/map.rb +1 -1
- data/lib/puppet/parser/functions/scanf.rb +15 -26
- data/lib/puppet/parser/functions/slice.rb +17 -24
- data/lib/puppet/parser/functions/split.rb +1 -1
- data/lib/puppet/parser/resource.rb +19 -17
- data/lib/puppet/parser/scope.rb +176 -5
- data/lib/puppet/plugins/data_providers/data_provider.rb +54 -13
- data/lib/puppet/pops.rb +0 -8
- data/lib/puppet/pops/adaptable.rb +4 -1
- data/lib/puppet/pops/adapters.rb +38 -13
- data/lib/puppet/pops/binder/binder.rb +21 -17
- data/lib/puppet/pops/binder/binder_issues.rb +8 -6
- data/lib/puppet/pops/binder/bindings_checker.rb +12 -8
- data/lib/puppet/pops/binder/bindings_composer.rb +16 -12
- data/lib/puppet/pops/binder/bindings_factory.rb +108 -104
- data/lib/puppet/pops/binder/bindings_model.rb +49 -47
- data/lib/puppet/pops/binder/config/diagnostic_producer.rb +10 -6
- data/lib/puppet/pops/binder/injector.rb +53 -48
- data/lib/puppet/pops/binder/key_factory.rb +10 -6
- data/lib/puppet/pops/binder/producers.rb +67 -62
- data/lib/puppet/pops/evaluator/access_operator.rb +95 -93
- data/lib/puppet/pops/evaluator/closure.rb +84 -68
- data/lib/puppet/pops/evaluator/collector_transformer.rb +18 -14
- data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +0 -1
- data/lib/puppet/pops/evaluator/compare_operator.rb +13 -9
- data/lib/puppet/pops/evaluator/epp_evaluator.rb +9 -8
- data/lib/puppet/pops/evaluator/evaluator_impl.rb +78 -76
- data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +85 -0
- data/lib/puppet/pops/evaluator/relationship_operator.rb +13 -11
- data/lib/puppet/pops/evaluator/runtime3_converter.rb +5 -0
- data/lib/puppet/pops/evaluator/runtime3_support.rb +41 -45
- data/lib/puppet/pops/issue_reporter.rb +6 -4
- data/lib/puppet/pops/issues.rb +34 -11
- data/lib/puppet/pops/loader/base_loader.rb +1 -1
- data/lib/puppet/pops/loader/loader.rb +1 -1
- data/lib/puppet/pops/loader/loader_paths.rb +15 -0
- data/lib/puppet/pops/loader/module_loaders.rb +17 -13
- data/lib/puppet/pops/loader/puppet_function_instantiator.rb +16 -12
- data/lib/puppet/pops/loader/ruby_function_instantiator.rb +16 -3
- data/lib/puppet/pops/loader/type_definition_instantiator.rb +55 -0
- data/lib/puppet/pops/loaders.rb +51 -9
- data/lib/puppet/pops/lookup.rb +14 -12
- data/lib/puppet/pops/merge_strategy.rb +16 -19
- data/lib/puppet/pops/model/factory.rb +26 -2
- data/lib/puppet/pops/model/model.rb +8 -8
- data/lib/puppet/pops/model/model_label_provider.rb +13 -7
- data/lib/puppet/pops/model/model_meta.rb +17 -0
- data/lib/puppet/pops/model/model_tree_dumper.rb +8 -0
- data/lib/puppet/pops/parser/egrammar.ra +38 -14
- data/lib/puppet/pops/parser/eparser.rb +1353 -1276
- data/lib/puppet/pops/parser/epp_support.rb +11 -7
- data/lib/puppet/pops/parser/evaluating_parser.rb +14 -10
- data/lib/puppet/pops/parser/heredoc_support.rb +15 -11
- data/lib/puppet/pops/parser/lexer2.rb +26 -19
- data/lib/puppet/pops/parser/lexer_support.rb +85 -7
- data/lib/puppet/pops/parser/locator.rb +21 -0
- data/lib/puppet/pops/parser/parser_support.rb +19 -16
- data/lib/puppet/pops/parser/slurp_support.rb +11 -7
- data/lib/puppet/pops/types/class_loader.rb +23 -19
- data/lib/puppet/pops/types/enumeration.rb +9 -26
- data/lib/puppet/pops/types/iterable.rb +308 -0
- data/lib/puppet/pops/types/recursion_guard.rb +82 -0
- data/lib/puppet/pops/types/type_acceptor.rb +25 -0
- data/lib/puppet/pops/types/type_asserter.rb +10 -9
- data/lib/puppet/pops/types/type_calculator.rb +138 -381
- data/lib/puppet/pops/types/type_factory.rb +91 -57
- data/lib/puppet/pops/types/type_formatter.rb +334 -0
- data/lib/puppet/pops/types/type_mismatch_describer.rb +226 -59
- data/lib/puppet/pops/types/type_parser.rb +159 -112
- data/lib/puppet/pops/types/types.rb +2057 -1247
- data/lib/puppet/pops/utils.rb +11 -10
- data/lib/puppet/pops/validation.rb +11 -9
- data/lib/puppet/pops/validation/checker4_0.rb +83 -55
- data/lib/puppet/pops/validation/validator_factory_4_0.rb +8 -4
- data/lib/puppet/provider/aixobject.rb +1 -1
- data/lib/puppet/provider/augeas/augeas.rb +1 -1
- data/lib/puppet/provider/cron/crontab.rb +1 -1
- data/lib/puppet/provider/exec/windows.rb +1 -1
- data/lib/puppet/provider/macauthorization/macauthorization.rb +10 -9
- data/lib/puppet/provider/nameservice/directoryservice.rb +35 -50
- data/lib/puppet/provider/package/appdmg.rb +3 -2
- data/lib/puppet/provider/package/dnf.rb +1 -1
- data/lib/puppet/provider/package/pip.rb +5 -8
- data/lib/puppet/provider/package/pip3.rb +1 -1
- data/lib/puppet/provider/package/pkg.rb +1 -1
- data/lib/puppet/provider/package/pkgdmg.rb +3 -2
- data/lib/puppet/provider/package/pkgng.rb +13 -4
- data/lib/puppet/provider/package/windows.rb +1 -1
- data/lib/puppet/provider/package/yum.rb +1 -1
- data/lib/puppet/provider/package/zypper.rb +19 -0
- data/lib/puppet/provider/service/debian.rb +2 -2
- data/lib/puppet/provider/service/launchd.rb +6 -18
- data/lib/puppet/provider/service/systemd.rb +9 -2
- data/lib/puppet/provider/sshkey/parsed.rb +1 -1
- data/lib/puppet/provider/user/aix.rb +1 -1
- data/lib/puppet/provider/user/directoryservice.rb +33 -58
- data/lib/puppet/provider/zfs/zfs.rb +1 -1
- data/lib/puppet/provider/zpool/zpool.rb +1 -1
- data/lib/puppet/reference/configuration.rb +1 -1
- data/lib/puppet/reference/providers.rb +1 -1
- data/lib/puppet/resource.rb +15 -12
- data/lib/puppet/resource/capability_finder.rb +20 -13
- data/lib/puppet/resource/catalog.rb +60 -3
- data/lib/puppet/resource/status.rb +11 -2
- data/lib/puppet/resource/type.rb +28 -38
- data/lib/puppet/settings.rb +1 -1
- data/lib/puppet/settings/config_file.rb +1 -1
- data/lib/puppet/settings/environment_conf.rb +13 -5
- data/lib/puppet/ssl/certificate_factory.rb +3 -3
- data/lib/puppet/ssl/certificate_request.rb +4 -4
- data/lib/puppet/ssl/certificate_signer.rb +1 -1
- data/lib/puppet/ssl/validator/default_validator.rb +1 -1
- data/lib/puppet/test/test_helper.rb +16 -4
- data/lib/puppet/transaction.rb +15 -2
- data/lib/puppet/transaction/additional_resource_generator.rb +6 -2
- data/lib/puppet/transaction/report.rb +31 -1
- data/lib/puppet/transaction/resource_harness.rb +0 -25
- data/lib/puppet/type.rb +11 -11
- data/lib/puppet/type/augeas.rb +1 -1
- data/lib/puppet/type/cron.rb +12 -12
- data/lib/puppet/type/file.rb +91 -39
- data/lib/puppet/type/file/checksum_value.rb +53 -0
- data/lib/puppet/type/file/content.rb +26 -111
- data/lib/puppet/type/file/data_sync.rb +84 -0
- data/lib/puppet/type/file/ensure.rb +17 -14
- data/lib/puppet/type/file/selcontext.rb +1 -1
- data/lib/puppet/type/file/source.rb +103 -18
- data/lib/puppet/type/filebucket.rb +1 -1
- data/lib/puppet/type/interface.rb +8 -3
- data/lib/puppet/type/macauthorization.rb +1 -1
- data/lib/puppet/type/package.rb +6 -0
- data/lib/puppet/type/schedule.rb +1 -1
- data/lib/puppet/type/stage.rb +1 -1
- data/lib/puppet/type/user.rb +19 -17
- data/lib/puppet/type/yumrepo.rb +20 -0
- data/lib/puppet/util.rb +109 -22
- data/lib/puppet/util/autoload.rb +16 -11
- data/lib/puppet/util/checksums.rb +74 -31
- data/lib/puppet/util/execution.rb +1 -1
- data/lib/puppet/util/http_proxy.rb +72 -0
- data/lib/puppet/util/log.rb +2 -0
- data/lib/puppet/util/logging.rb +43 -1
- data/lib/puppet/util/monkey_patches.rb +2 -2
- data/lib/puppet/util/multi_match.rb +51 -0
- data/lib/puppet/util/network_device/cisco/device.rb +10 -2
- data/lib/puppet/util/network_device/cisco/interface.rb +21 -8
- data/lib/puppet/util/network_device/transport/ssh.rb +7 -3
- data/lib/puppet/util/network_device/transport/telnet.rb +39 -36
- data/lib/puppet/util/plist.rb +130 -0
- data/lib/puppet/util/resource_template.rb +1 -1
- data/lib/puppet/util/run_mode.rb +2 -2
- data/lib/puppet/util/skip_tags.rb +9 -0
- data/lib/puppet/util/windows/access_control_entry.rb +1 -1
- data/lib/puppet/util/windows/access_control_list.rb +3 -3
- data/lib/puppet/util/windows/adsi.rb +4 -4
- data/lib/puppet/util/windows/api_types.rb +24 -18
- data/lib/puppet/util/windows/com.rb +3 -3
- data/lib/puppet/util/windows/error.rb +1 -1
- data/lib/puppet/util/windows/file.rb +8 -8
- data/lib/puppet/util/windows/principal.rb +23 -14
- data/lib/puppet/util/windows/process.rb +78 -11
- data/lib/puppet/util/windows/registry.rb +1 -1
- data/lib/puppet/util/windows/root_certs.rb +5 -5
- data/lib/puppet/util/windows/security.rb +33 -35
- data/lib/puppet/util/windows/security_descriptor.rb +1 -1
- data/lib/puppet/util/windows/sid.rb +42 -4
- data/lib/puppet/util/windows/taskscheduler.rb +15 -15
- data/lib/puppet/util/windows/user.rb +10 -10
- data/lib/puppet/vendor/deep_merge/deep_merge.gemspec +1 -1
- data/lib/puppet/vendor/pathspec/LICENSE +2 -2
- data/lib/puppet/vendor/pathspec/README.md +1 -1
- data/lib/puppet/vendor/rgen/README.rdoc +1 -1
- data/lib/puppet/vendor/semantic/lib/semantic/dependency/module_release.rb +14 -0
- data/lib/puppet/version.rb +1 -1
- data/lib/semver.rb +17 -1
- data/man/man5/puppet.conf.5 +12 -12
- data/man/man8/extlookup2hiera.8 +1 -1
- data/man/man8/puppet-agent.8 +2 -2
- data/man/man8/puppet-apply.8 +2 -2
- data/man/man8/puppet-ca.8 +2 -2
- data/man/man8/puppet-catalog.8 +2 -2
- data/man/man8/puppet-cert.8 +2 -2
- data/man/man8/puppet-certificate.8 +2 -2
- data/man/man8/puppet-certificate_request.8 +2 -2
- data/man/man8/puppet-certificate_revocation_list.8 +2 -2
- data/man/man8/puppet-config.8 +3 -3
- data/man/man8/puppet-describe.8 +1 -1
- data/man/man8/puppet-device.8 +1 -1
- data/man/man8/puppet-doc.8 +1 -1
- data/man/man8/puppet-epp.8 +2 -2
- data/man/man8/puppet-facts.8 +2 -2
- data/man/man8/puppet-file.8 +2 -2
- data/man/man8/puppet-filebucket.8 +2 -2
- data/man/man8/puppet-help.8 +2 -2
- data/man/man8/puppet-inspect.8 +2 -2
- data/man/man8/puppet-key.8 +2 -2
- data/man/man8/puppet-man.8 +2 -2
- data/man/man8/puppet-master.8 +2 -2
- data/man/man8/puppet-module.8 +9 -9
- data/man/man8/puppet-node.8 +2 -2
- data/man/man8/puppet-parser.8 +2 -2
- data/man/man8/puppet-plugin.8 +2 -2
- data/man/man8/puppet-report.8 +2 -2
- data/man/man8/puppet-resource.8 +2 -2
- data/man/man8/puppet-resource_type.8 +2 -2
- data/man/man8/puppet-status.8 +3 -3
- data/man/man8/puppet.8 +1 -1
- data/spec/fixtures/module.tar.gz +0 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/bad_data/lib/puppet/functions/bad_data/data.rb +1 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/bad_data/manifests/init.pp +0 -1
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/data/empty.json +0 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/hiera.yaml +5 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/manifests/init.pp +2 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_json/metadata.json +9 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/data/empty.yaml +1 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/hiera.yaml +5 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/manifests/init.pp +2 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/metadata.json +9 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/data/first.json +2 -1
- data/spec/fixtures/unit/module/trailing-comma.json +1 -1
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/manifests/init.pp +3 -1
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/types/zero.pp +1 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/types/withuseeone.pp +1 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/types/withuseezero.pp +1 -0
- data/spec/fixtures/unit/provider/package/yum/yum-check-update-broken-notices.txt +187 -0
- data/spec/fixtures/unit/provider/sshkey/parsed/sample_with_blank_lines +8 -0
- data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_fetch_if_not_on_the_local_disk.yml +205 -0
- data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_not_update_if_content_on_disk_is_up-to-date.yml +213 -0
- data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_update_if_content_differs_on_disk.yml +213 -0
- data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_mtime_is_older_on_disk.yml +205 -0
- data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_no_header_specified.yml +197 -0
- data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_not_on_the_local_disk.yml +205 -0
- data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_not_update_if_mtime_is_newer_on_disk.yml +205 -0
- data/spec/integration/defaults_spec.rb +14 -2
- data/spec/integration/file_system/uniquefile_spec.rb +29 -0
- data/spec/integration/module_tool/tar/mini_spec.rb +28 -0
- data/spec/integration/node/environment_spec.rb +13 -0
- data/spec/integration/parser/dynamic_scoping_spec.rb +67 -0
- data/spec/integration/parser/parameter_defaults_spec.rb +336 -0
- data/spec/integration/parser/undef_param_spec.rb +8 -0
- data/spec/integration/provider/yumrepo_spec.rb +1 -1
- data/spec/integration/test/test_helper_spec.rb +28 -0
- data/spec/integration/transaction/report_spec.rb +16 -0
- data/spec/integration/transaction_spec.rb +11 -0
- data/spec/integration/type/file_spec.rb +194 -4
- data/spec/integration/type/package_spec.rb +5 -1
- data/spec/integration/type/tidy_spec.rb +21 -9
- data/spec/integration/util/execution_spec.rb +22 -0
- data/spec/integration/util/windows/principal_spec.rb +90 -4
- data/spec/integration/util/windows/process_spec.rb +31 -0
- data/spec/integration/util/windows/security_spec.rb +6 -6
- data/spec/integration/util/windows/user_spec.rb +1 -1
- data/spec/integration/util_spec.rb +49 -27
- data/spec/lib/puppet_spec/compiler.rb +17 -0
- data/spec/lib/puppet_spec/files.rb +2 -2
- data/spec/lib/puppet_spec/pops.rb +13 -0
- data/spec/shared_behaviours/iterative_functions.rb +1 -1
- data/spec/shared_contexts/types_setup.rb +96 -0
- data/spec/unit/agent_spec.rb +1 -0
- data/spec/unit/application/agent_spec.rb +10 -0
- data/spec/unit/application/apply_spec.rb +9 -0
- data/spec/unit/configurer/downloader_spec.rb +5 -5
- data/spec/unit/configurer_spec.rb +271 -39
- data/spec/unit/data_providers/hiera_interpolation_spec.rb +57 -0
- data/spec/unit/defaults_spec.rb +15 -0
- data/spec/unit/environments_spec.rb +24 -4
- data/spec/unit/face/parser_spec.rb +43 -2
- data/spec/unit/file_serving/http_metadata_spec.rb +85 -0
- data/spec/unit/file_serving/metadata_spec.rb +50 -0
- data/spec/unit/file_serving/terminus_selector_spec.rb +12 -2
- data/spec/unit/file_system_spec.rb +26 -0
- data/spec/unit/functions/assert_type_spec.rb +36 -2
- data/spec/unit/functions/defined_spec.rb +2 -2
- data/spec/unit/functions/epp_spec.rb +11 -3
- data/spec/unit/functions/lookup_spec.rb +58 -13
- data/spec/unit/functions/regsubst_spec.rb +1 -1
- data/spec/unit/functions/reverse_each_spec.rb +108 -0
- data/spec/unit/functions/step_spec.rb +113 -0
- data/spec/unit/functions/type_spec.rb +35 -0
- data/spec/unit/functions4_spec.rb +61 -5
- data/spec/unit/indirector/catalog/compiler_spec.rb +705 -4
- data/spec/unit/indirector/file_bucket_file/file_spec.rb +1 -1
- data/spec/unit/indirector/indirection_spec.rb +1 -1
- data/spec/unit/info_service_spec.rb +94 -32
- data/spec/unit/module_spec.rb +14 -0
- data/spec/unit/module_tool/applications/builder_spec.rb +4 -4
- data/spec/unit/network/authstore_spec.rb +1 -1
- data/spec/unit/network/http/connection_spec.rb +1 -0
- data/spec/unit/network/http/pool_spec.rb +30 -0
- data/spec/unit/node_spec.rb +1 -1
- data/spec/unit/parser/compiler_spec.rb +16 -0
- data/spec/unit/parser/scope_spec.rb +28 -11
- data/spec/unit/pops/evaluator/access_ops_spec.rb +3 -3
- data/spec/unit/pops/evaluator/comparison_ops_spec.rb +3 -0
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +7 -1
- data/spec/unit/pops/evaluator/evaluator_rspec_helper.rb +4 -4
- data/spec/unit/pops/evaluator/json_strict_literal_evaluator_spec.rb +63 -0
- data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +6 -0
- data/spec/unit/pops/loaders/dependency_loader_spec.rb +53 -0
- data/spec/unit/pops/loaders/loaders_spec.rb +44 -1
- data/spec/unit/pops/parser/lexer2_spec.rb +112 -3
- data/spec/unit/pops/parser/parse_calls_spec.rb +8 -0
- data/spec/unit/pops/parser/parser_spec.rb +10 -0
- data/spec/unit/pops/parser/source_pos_adapter_spec.rb +26 -0
- data/spec/unit/pops/types/iterable_spec.rb +262 -0
- data/spec/unit/pops/types/recursion_guard_spec.rb +91 -0
- data/spec/unit/pops/types/type_acceptor_spec.rb +105 -0
- data/spec/unit/pops/types/type_asserter_spec.rb +43 -0
- data/spec/unit/pops/types/type_calculator_spec.rb +275 -373
- data/spec/unit/pops/types/type_formatter_spec.rb +280 -0
- data/spec/unit/pops/types/type_mismatch_describer_spec.rb +152 -0
- data/spec/unit/pops/types/type_parser_spec.rb +58 -13
- data/spec/unit/pops/types/types_spec.rb +241 -0
- data/spec/unit/pops/validator/validator_spec.rb +100 -43
- data/spec/unit/provider/cron/parsed_spec.rb +1 -0
- data/spec/unit/provider/macauthorization_spec.rb +5 -2
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +14 -19
- data/spec/unit/provider/package/appdmg_spec.rb +3 -3
- data/spec/unit/provider/package/dnf_spec.rb +16 -0
- data/spec/unit/provider/package/pip3_spec.rb +60 -42
- data/spec/unit/provider/package/pip_spec.rb +47 -34
- data/spec/unit/provider/package/pkgdmg_spec.rb +18 -9
- data/spec/unit/provider/package/pkgng_spec.rb +4 -2
- data/spec/unit/provider/package/yum_spec.rb +11 -0
- data/spec/unit/provider/package/zypper_spec.rb +14 -0
- data/spec/unit/provider/service/launchd_spec.rb +17 -35
- data/spec/unit/provider/service/systemd_spec.rb +7 -0
- data/spec/unit/provider/sshkey/parsed_spec.rb +20 -19
- data/spec/unit/provider/user/directoryservice_spec.rb +40 -59
- data/spec/unit/resource/capability_finder_spec.rb +28 -15
- data/spec/unit/resource/catalog_spec.rb +33 -1
- data/spec/unit/resource/type_spec.rb +149 -7
- data/spec/unit/resource_spec.rb +96 -57
- data/spec/unit/settings/environment_conf_spec.rb +18 -1
- data/spec/unit/ssl/certificate_revocation_list_spec.rb +3 -3
- data/spec/unit/transaction/report_spec.rb +27 -0
- data/spec/unit/transaction/resource_harness_spec.rb +0 -47
- data/spec/unit/transaction_spec.rb +5 -0
- data/spec/unit/type/file/checksum_spec.rb +6 -0
- data/spec/unit/type/file/checksum_value_spec.rb +286 -0
- data/spec/unit/type/file/content_spec.rb +12 -193
- data/spec/unit/type/file/source_spec.rb +211 -119
- data/spec/unit/type/file_spec.rb +133 -34
- data/spec/unit/type/interface_spec.rb +32 -0
- data/spec/unit/type/macauthorization_spec.rb +4 -1
- data/spec/unit/type/yumrepo_spec.rb +2 -2
- data/spec/unit/util/filetype_spec.rb +1 -1
- data/spec/unit/util/http_proxy_spec.rb +2 -2
- data/spec/unit/util/log/destinations_spec.rb +0 -2
- data/spec/unit/util/logging_spec.rb +69 -0
- data/spec/unit/util/multi_match_spec.rb +39 -0
- data/spec/unit/util/network_device/cisco/device_spec.rb +253 -216
- data/spec/unit/util/network_device/transport/telnet_spec.rb +60 -58
- data/spec/unit/util/plist_spec.rb +110 -0
- data/spec/unit/util/resource_template_spec.rb +2 -2
- data/spec/unit/util/run_mode_spec.rb +27 -3
- data/spec/unit/util/windows/adsi_spec.rb +4 -4
- data/spec/unit/util/windows/api_types_spec.rb +42 -0
- data/spec/unit/util/windows/security_descriptor_spec.rb +3 -3
- data/spec/unit/util/windows/sid_spec.rb +1 -1
- data/spec/unit/util_spec.rb +123 -13
- data/tasks/cfpropertylist.rake +15 -0
- metadata +114 -26
- data/lib/puppet/vendor/load_plist.rb +0 -1
- data/lib/puppet/vendor/plist/CHANGELOG +0 -82
- data/lib/puppet/vendor/plist/MIT-LICENSE +0 -21
- data/lib/puppet/vendor/plist/PUPPET_README.md +0 -6
- data/lib/puppet/vendor/plist/README +0 -36
- data/lib/puppet/vendor/plist/Rakefile +0 -144
- data/lib/puppet/vendor/plist/docs/USAGE +0 -104
- data/lib/puppet/vendor/plist/docs/jamis-template.rb +0 -591
- data/lib/puppet/vendor/plist/lib/plist.rb +0 -22
- data/lib/puppet/vendor/plist/lib/plist/generator.rb +0 -224
- data/lib/puppet/vendor/plist/lib/plist/parser.rb +0 -225
- data/lib/puppet/vendor/plist/test/assets/AlbumData.xml +0 -203
- data/lib/puppet/vendor/plist/test/assets/Cookies.plist +0 -104
- data/lib/puppet/vendor/plist/test/assets/commented.plist +0 -9
- data/lib/puppet/vendor/plist/test/assets/example_data.bin +0 -0
- data/lib/puppet/vendor/plist/test/assets/example_data.jpg +0 -0
- data/lib/puppet/vendor/plist/test/assets/example_data.plist +0 -259
- data/lib/puppet/vendor/plist/test/assets/test_data_elements.plist +0 -24
- data/lib/puppet/vendor/plist/test/assets/test_empty_key.plist +0 -13
- data/lib/puppet/vendor/plist/test/test_data_elements.rb +0 -115
- data/lib/puppet/vendor/plist/test/test_generator.rb +0 -59
- data/lib/puppet/vendor/plist/test/test_generator_basic_types.rb +0 -58
- data/lib/puppet/vendor/plist/test/test_generator_collections.rb +0 -82
- data/lib/puppet/vendor/plist/test/test_parser.rb +0 -90
@@ -41,6 +41,15 @@ class Puppet::Pops::Parser::Locator
|
|
41
41
|
def char_length(offset, end_offset)
|
42
42
|
end
|
43
43
|
|
44
|
+
# Returns the length measured in number of characters from the given start and end byte offseta
|
45
|
+
def char_length(offset, end_offset)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Extracts the text from offset with given length (measured in what the locator uses for offset)
|
49
|
+
# @returns String - the extracted text
|
50
|
+
def extract_text(offset, length)
|
51
|
+
end
|
52
|
+
|
44
53
|
# Returns the line index - an array of line offsets for the start position of each line, starting at 0 for
|
45
54
|
# the first line.
|
46
55
|
#
|
@@ -238,6 +247,12 @@ class Puppet::Pops::Parser::Locator
|
|
238
247
|
end_offset - offset
|
239
248
|
end
|
240
249
|
|
250
|
+
# Extracts the text from char offset with given byte length
|
251
|
+
# @returns String - the extracted text
|
252
|
+
def extract_text(offset, length)
|
253
|
+
string.slice(offset, length)
|
254
|
+
end
|
255
|
+
|
241
256
|
end
|
242
257
|
|
243
258
|
# This implementation is for Ruby19 and Ruby20. It uses byteslice to get strings from byte based offsets.
|
@@ -263,5 +278,11 @@ class Puppet::Pops::Parser::Locator
|
|
263
278
|
def char_length(offset, end_offset)
|
264
279
|
string.byteslice(offset, end_offset - offset).length
|
265
280
|
end
|
281
|
+
|
282
|
+
# Extracts the text from byte offset with given byte length
|
283
|
+
# @returns String - the extracted text
|
284
|
+
def extract_text(offset, length)
|
285
|
+
string.byteslice(offset, length)
|
286
|
+
end
|
266
287
|
end
|
267
288
|
end
|
@@ -5,11 +5,13 @@ require 'puppet/resource/type_collection_helper'
|
|
5
5
|
require 'puppet/resource/type'
|
6
6
|
require 'monitor'
|
7
7
|
|
8
|
+
module Puppet::Pops
|
9
|
+
module Parser
|
8
10
|
# Supporting logic for the parser.
|
9
11
|
# This supporting logic has slightly different responsibilities compared to the original Puppet::Parser::Parser.
|
10
12
|
# It is only concerned with parsing.
|
11
13
|
#
|
12
|
-
class
|
14
|
+
class Parser
|
13
15
|
# Note that the name of the contained class and the file name (currently parser_support.rb)
|
14
16
|
# needs to be different as the class is generated by Racc, and this file (parser_support.rb) is included as a mix in
|
15
17
|
#
|
@@ -18,8 +20,7 @@ class Puppet::Pops::Parser::Parser
|
|
18
20
|
# Note that the parser/parser support does not have direct knowledge about the Model.
|
19
21
|
# All model construction/manipulation is made by the Factory.
|
20
22
|
#
|
21
|
-
Factory =
|
22
|
-
Model = Puppet::Pops::Model
|
23
|
+
Factory = Model::Factory
|
23
24
|
|
24
25
|
include Puppet::Resource::TypeCollectionHelper
|
25
26
|
|
@@ -51,19 +52,19 @@ class Puppet::Pops::Parser::Parser
|
|
51
52
|
#
|
52
53
|
def error(semantic, message)
|
53
54
|
except = Puppet::ParseError.new(message)
|
54
|
-
if semantic.is_a?(
|
55
|
+
if semantic.is_a?(LexerSupport::TokenValue)
|
55
56
|
except.file = semantic[:file];
|
56
57
|
except.line = semantic[:line];
|
57
58
|
except.pos = semantic[:pos];
|
58
59
|
else
|
59
|
-
semantic = semantic.current() if semantic.is_a?(
|
60
|
+
semantic = semantic.current() if semantic.is_a?(Factory)
|
60
61
|
|
61
62
|
# Adapt the model so it is possible to get location information.
|
62
63
|
# The model may not have been added to the source tree, so give it the lexer's locator
|
63
64
|
# directly instead of searching for the root Program where the locator is normally stored.
|
64
65
|
#
|
65
|
-
if semantic.is_a?(
|
66
|
-
adapter =
|
66
|
+
if semantic.is_a?(Model::Positioned)
|
67
|
+
adapter = Adapters::SourcePosAdapter.adapt(semantic)
|
67
68
|
adapter.locator = @lexer.locator
|
68
69
|
else
|
69
70
|
adapter = nil
|
@@ -87,7 +88,7 @@ class Puppet::Pops::Parser::Parser
|
|
87
88
|
end
|
88
89
|
|
89
90
|
def initialize()
|
90
|
-
@lexer =
|
91
|
+
@lexer = Lexer2.new
|
91
92
|
@namestack = []
|
92
93
|
@definitions = []
|
93
94
|
end
|
@@ -100,7 +101,7 @@ class Puppet::Pops::Parser::Parser
|
|
100
101
|
else
|
101
102
|
value_at = "'#{value[:value]}'"
|
102
103
|
end
|
103
|
-
error =
|
104
|
+
error = Issues::SYNTAX_ERROR.format(:where => value_at)
|
104
105
|
error = "#{error}, token: #{token}" if @yydebug
|
105
106
|
|
106
107
|
# Note, old parser had processing of "expected token here" - do not try to reinstate:
|
@@ -126,7 +127,7 @@ class Puppet::Pops::Parser::Parser
|
|
126
127
|
file = lexer.file
|
127
128
|
end
|
128
129
|
file = nil unless file.is_a?(String) && !file.empty?
|
129
|
-
raise Puppet::ParseErrorWithIssue.new(error, file, line, pos, nil, issue_code =
|
130
|
+
raise Puppet::ParseErrorWithIssue.new(error, file, line, pos, nil, issue_code = Issues::SYNTAX_ERROR.issue_code)
|
130
131
|
end
|
131
132
|
|
132
133
|
# Parses a String of pp DSL code.
|
@@ -137,7 +138,7 @@ class Puppet::Pops::Parser::Parser
|
|
137
138
|
end
|
138
139
|
|
139
140
|
# Mark the factory wrapped model object with location information
|
140
|
-
# @return [
|
141
|
+
# @return [Factory] the given factory
|
141
142
|
# @api private
|
142
143
|
#
|
143
144
|
def loc(factory, start_locateable, end_locateable = nil)
|
@@ -145,7 +146,7 @@ class Puppet::Pops::Parser::Parser
|
|
145
146
|
end
|
146
147
|
|
147
148
|
# Mark the factory wrapped heredoc model object with location information
|
148
|
-
# @return [
|
149
|
+
# @return [Factory] the given factory
|
149
150
|
# @api private
|
150
151
|
#
|
151
152
|
def heredoc_loc(factory, start_locateabke, end_locateable = nil)
|
@@ -193,10 +194,10 @@ class Puppet::Pops::Parser::Parser
|
|
193
194
|
#
|
194
195
|
begin
|
195
196
|
Factory.transform_calls(expressions)
|
196
|
-
rescue
|
197
|
+
rescue Factory::ArgsToNonCallError => e
|
197
198
|
# e.args[1] is the first comma token in the list
|
198
199
|
# e.name_expr is the function name expression
|
199
|
-
if e.name_expr.is_a?(
|
200
|
+
if e.name_expr.is_a?(Model::QualifiedName)
|
200
201
|
error(e.args[1], "attempt to pass argument list to the function '#{e.name_expr.value}' which cannot be called without parentheses")
|
201
202
|
else
|
202
203
|
error(e.args[1], "illegal comma separated argument list")
|
@@ -205,8 +206,8 @@ class Puppet::Pops::Parser::Parser
|
|
205
206
|
end
|
206
207
|
|
207
208
|
# Transforms a LEFT followed by the result of attribute_operations, this may be a call or an invalid sequence
|
208
|
-
def transform_resource_wo_title(left, resource)
|
209
|
-
Factory.transform_resource_wo_title(left, resource)
|
209
|
+
def transform_resource_wo_title(left, resource, lbrace_token, rbrace_token)
|
210
|
+
Factory.transform_resource_wo_title(left, resource, lbrace_token, rbrace_token)
|
210
211
|
end
|
211
212
|
|
212
213
|
# Creates a program with the given body.
|
@@ -249,3 +250,5 @@ class Puppet::Pops::Parser::Parser
|
|
249
250
|
end
|
250
251
|
|
251
252
|
end
|
253
|
+
end
|
254
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
module Puppet::Pops
|
2
|
+
module Parser
|
1
3
|
# This module is an integral part of the Lexer.
|
2
4
|
# It defines the string slurping behavior - finding the string and non string parts in interpolated
|
3
5
|
# strings, translating escape sequences in strings to their single character equivalence.
|
@@ -6,8 +8,8 @@
|
|
6
8
|
# additional parameter passing and evaluation of conditional logic.
|
7
9
|
# TODO: More detailed performance analysis of excessive character escaping and interpolation.
|
8
10
|
#
|
9
|
-
module
|
10
|
-
include
|
11
|
+
module SlurpSupport
|
12
|
+
include LexerSupport
|
11
13
|
|
12
14
|
SLURP_SQ_PATTERN = /(?:[^\\]|^|[^\\])(?:[\\]{2})*[']/
|
13
15
|
SLURP_DQ_PATTERN = /(?:[^\\]|^|[^\\])(?:[\\]{2})*(["]|[$]\{?)/
|
@@ -23,7 +25,7 @@ module Puppet::Pops::Parser::SlurpSupport
|
|
23
25
|
# skip the leading '
|
24
26
|
@scanner.pos += 1
|
25
27
|
str = slurp(@scanner, SLURP_SQ_PATTERN, SQ_ESCAPES, :ignore_invalid_escapes)
|
26
|
-
lex_error(
|
28
|
+
lex_error(Issues::UNCLOSED_QUOTE, :after => "\"'\"", :followed_by => followed_by) unless str
|
27
29
|
str[0..-2] # strip closing "'" from result
|
28
30
|
end
|
29
31
|
|
@@ -32,7 +34,7 @@ module Puppet::Pops::Parser::SlurpSupport
|
|
32
34
|
last = scn.matched
|
33
35
|
str = slurp(scn, SLURP_DQ_PATTERN, DQ_ESCAPES, false)
|
34
36
|
unless str
|
35
|
-
lex_error(
|
37
|
+
lex_error(Issues::UNCLOSED_QUOTE, :after => format_quote(last), :followed_by => followed_by)
|
36
38
|
end
|
37
39
|
|
38
40
|
# Terminator may be a single char '"', '$', or two characters '${' group match 1 (scn[1]) from the last slurp holds this
|
@@ -89,14 +91,14 @@ module Puppet::Pops::Parser::SlurpSupport
|
|
89
91
|
when 't' ; "\t"
|
90
92
|
when 's' ; ' '
|
91
93
|
when 'u'
|
92
|
-
lex_warning(
|
94
|
+
lex_warning(Issues::ILLEGAL_UNICODE_ESCAPE)
|
93
95
|
"\\u"
|
94
96
|
when "\n" ; ''
|
95
97
|
when "\r\n"; ''
|
96
98
|
else ch
|
97
99
|
end
|
98
100
|
else
|
99
|
-
lex_warning(
|
101
|
+
lex_warning(Issues::UNRECOGNIZED_ESCAPE, :ch => ch) unless ignore_invalid_escapes
|
100
102
|
"\\#{ch}"
|
101
103
|
end
|
102
104
|
}
|
@@ -105,7 +107,7 @@ module Puppet::Pops::Parser::SlurpSupport
|
|
105
107
|
# have reached this far... Unfortunately there is no more specific error and a match on message is
|
106
108
|
# required to differentiate from other internal problems.
|
107
109
|
if e.message =~ /invalid byte sequence/
|
108
|
-
lex_error(
|
110
|
+
lex_error(Issues::ILLEGAL_UNICODE_ESCAPE)
|
109
111
|
else
|
110
112
|
raise e
|
111
113
|
end
|
@@ -113,3 +115,5 @@ module Puppet::Pops::Parser::SlurpSupport
|
|
113
115
|
str
|
114
116
|
end
|
115
117
|
end
|
118
|
+
end
|
119
|
+
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'rgen/metamodel_builder'
|
2
2
|
|
3
|
+
module Puppet::Pops
|
4
|
+
module Types
|
3
5
|
# The ClassLoader provides a Class instance given a class name or a meta-type.
|
4
6
|
# If the class is not already loaded, it is loaded using the Puppet Autoloader.
|
5
7
|
# This means it can load a class from a gem, or from puppet modules.
|
6
8
|
#
|
7
|
-
class
|
9
|
+
class ClassLoader
|
8
10
|
@autoloader = Puppet::Util::Autoload.new("ClassLoader", "")
|
9
11
|
|
10
12
|
# Returns a Class given a fully qualified class name.
|
11
13
|
# Lookup of class is never relative to the calling namespace.
|
12
|
-
# @param name [String, Array<String>, Array<Symbol>,
|
14
|
+
# @param name [String, Array<String>, Array<Symbol>, PAnyType] A fully qualified
|
13
15
|
# class name String (e.g. '::Foo::Bar', 'Foo::Bar'), a PAnyType, or a fully qualified name in Array form where each part
|
14
16
|
# is either a String or a Symbol, e.g. `%w{Puppetx Puppetlabs SomeExtension}`.
|
15
17
|
# @return [Class, nil] the looked up class or nil if no such class is loaded
|
@@ -24,7 +26,7 @@ class Puppet::Pops::Types::ClassLoader
|
|
24
26
|
when Array
|
25
27
|
provide_from_name_path(name.join('::'), name)
|
26
28
|
|
27
|
-
when
|
29
|
+
when PAnyType, PType
|
28
30
|
provide_from_type(name)
|
29
31
|
|
30
32
|
else
|
@@ -36,38 +38,38 @@ class Puppet::Pops::Types::ClassLoader
|
|
36
38
|
|
37
39
|
def self.provide_from_type(type)
|
38
40
|
case type
|
39
|
-
when
|
41
|
+
when PRuntimeType
|
40
42
|
raise ArgumentError.new("Only Runtime type 'ruby' is supported, got #{type.runtime}") unless type.runtime == :ruby
|
41
43
|
provide_from_string(type.runtime_type_name)
|
42
44
|
|
43
|
-
when
|
45
|
+
when PBooleanType
|
44
46
|
# There is no other thing to load except this Enum meta type
|
45
47
|
RGen::MetamodelBuilder::MMBase::Boolean
|
46
48
|
|
47
|
-
when
|
49
|
+
when PType
|
48
50
|
# TODO: PType should has a type argument (a PAnyType) so the Class' class could be returned
|
49
51
|
# (but this only matters in special circumstances when meta programming has been used).
|
50
52
|
Class
|
51
53
|
|
52
|
-
when
|
54
|
+
when POptionalType
|
53
55
|
# cannot make a distinction between optional and its type
|
54
56
|
provide_from_type(type.optional_type)
|
55
57
|
|
56
58
|
# Although not expected to be the first choice for getting a concrete class for these
|
57
59
|
# types, these are of value if the calling logic just has a reference to type.
|
58
60
|
#
|
59
|
-
when
|
60
|
-
when
|
61
|
-
when
|
62
|
-
when
|
63
|
-
when
|
64
|
-
when
|
65
|
-
when
|
66
|
-
when
|
67
|
-
when
|
68
|
-
when
|
69
|
-
when
|
70
|
-
when
|
61
|
+
when PArrayType ; Array
|
62
|
+
when PTupleType ; Array
|
63
|
+
when PHashType ; Hash
|
64
|
+
when PStructType ; Hash
|
65
|
+
when PRegexpType ; Regexp
|
66
|
+
when PIntegerType ; Integer
|
67
|
+
when PStringType ; String
|
68
|
+
when PPatternType ; String
|
69
|
+
when PEnumType ; String
|
70
|
+
when PFloatType ; Float
|
71
|
+
when PUndefType ; NilClass
|
72
|
+
when PCallableType ; Proc
|
71
73
|
else
|
72
74
|
nil
|
73
75
|
end
|
@@ -127,3 +129,5 @@ class Puppet::Pops::Types::ClassLoader
|
|
127
129
|
end
|
128
130
|
|
129
131
|
end
|
132
|
+
end
|
133
|
+
end
|
@@ -1,33 +1,16 @@
|
|
1
1
|
# The Enumeration class provides default Enumerable::Enumerator creation for Puppet Programming Language
|
2
2
|
# runtime objects that supports the concept of enumeration.
|
3
3
|
#
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
4
|
+
module Puppet::Pops::Types
|
5
|
+
class Enumeration
|
6
|
+
def self.enumerator(o)
|
7
|
+
Puppet.deprecation_warning('Enumeration.enumerator is deprecated. Use Iterable.on instead')
|
8
|
+
Iterable.on(o)
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
case o
|
16
|
-
when String
|
17
|
-
x = o.chars
|
18
|
-
# Ruby 1.9.3 returns an Enumerator, and 2.0.0 an Array
|
19
|
-
x.is_a?(Array) ? x.each : x
|
20
|
-
when Integer
|
21
|
-
o.times
|
22
|
-
when Array
|
23
|
-
o.each
|
24
|
-
when Hash
|
25
|
-
o.each
|
26
|
-
when Puppet::Pops::Types::PIntegerType
|
27
|
-
# Not enumerable if representing an infinite range
|
28
|
-
o.enumerable? ? o.each : nil
|
29
|
-
else
|
30
|
-
nil
|
11
|
+
def enumerator(o)
|
12
|
+
Puppet.deprecation_warning('Enumeration.enumerator is deprecated. Use Iterable.on instead')
|
13
|
+
Iterable.on(o)
|
31
14
|
end
|
32
15
|
end
|
33
16
|
end
|
@@ -0,0 +1,308 @@
|
|
1
|
+
module Puppet::Pops::Types
|
2
|
+
# The runtime Iterable type for an Iterable
|
3
|
+
module Iterable
|
4
|
+
# Produces an `Iterable` for one of the following types with the following characterstics:
|
5
|
+
#
|
6
|
+
# `String` - yields each character in the string
|
7
|
+
# `Array` - yields each element in the array
|
8
|
+
# `Hash` - yields each key/value pair as a two element array
|
9
|
+
# `Integer` - when positive, yields each value from zero to the given number
|
10
|
+
# `PIntegerType` - yields each element from min to max (inclusive) provided min < max and neither is unbounded.
|
11
|
+
# `PEnumtype` - yields each possible value of the enum.
|
12
|
+
# `Range` - yields an iterator for all elements in the range provided that the range start and end
|
13
|
+
# are both integers or both strings and start is less than end using natural ordering.
|
14
|
+
# `Dir` - yields each name in the directory
|
15
|
+
#
|
16
|
+
# An `ArgumentError` is raised for all other objects.
|
17
|
+
#
|
18
|
+
# @param o [Object] The object to produce an `Iterable` for
|
19
|
+
# @return [Iterable,nil] The produced `Iterable`
|
20
|
+
# @raise [ArgumentError] In case an `Iterable` cannot be produced
|
21
|
+
# @api public
|
22
|
+
def self.asserted_iterable(caller, obj)
|
23
|
+
iter = self.on(obj)
|
24
|
+
raise ArgumentError, "#{caller.class}(): wrong argument type (#{obj.class}; is not Iterable." if iter.nil?
|
25
|
+
iter
|
26
|
+
end
|
27
|
+
|
28
|
+
# Produces an `Iterable` for one of the following types with the following characterstics:
|
29
|
+
#
|
30
|
+
# `String` - yields each character in the string
|
31
|
+
# `Array` - yields each element in the array
|
32
|
+
# `Hash` - yields each key/value pair as a two element array
|
33
|
+
# `Integer` - when positive, yields each value from zero to the given number
|
34
|
+
# `PIntegerType` - yields each element from min to max (inclusive) provided min < max and neither is unbounded.
|
35
|
+
# `PEnumtype` - yields each possible value of the enum.
|
36
|
+
# `Range` - yields an iterator for all elements in the range provided that the range start and end
|
37
|
+
# are both integers or both strings and start is less than end using natural ordering.
|
38
|
+
# `Dir` - yields each name in the directory
|
39
|
+
#
|
40
|
+
# The value `nil` is returned for all other objects.
|
41
|
+
#
|
42
|
+
# @param o [Object] The object to produce an `Iterable` for
|
43
|
+
# @return [Iterable,nil] The produced `Iterable` or `nil` if it couldn't be produced
|
44
|
+
#
|
45
|
+
# @api public
|
46
|
+
def self.on(o)
|
47
|
+
case o
|
48
|
+
when Iterable
|
49
|
+
o
|
50
|
+
when String
|
51
|
+
Iterator.new(PStringType.new(PIntegerType.new(1, 1)), o.each_char)
|
52
|
+
when Array
|
53
|
+
if o.empty?
|
54
|
+
Iterator.new(PUnitType::DEFAULT, o.each)
|
55
|
+
else
|
56
|
+
tc = TypeCalculator.singleton
|
57
|
+
Iterator.new(tc.unwrap_single_variant(PVariantType.new(o.map {|e| tc.infer_set(e) })), o.each)
|
58
|
+
end
|
59
|
+
when Hash
|
60
|
+
# Each element is a two element [key, value] tuple.
|
61
|
+
if o.empty?
|
62
|
+
Iterator.new(PHashType::DEFAULT_KEY_PAIR_TUPLE, o.each)
|
63
|
+
else
|
64
|
+
tc = TypeCalculator.singleton
|
65
|
+
Iterator.new(PTupleType.new([
|
66
|
+
tc.unwrap_single_variant(PVariantType.new(o.keys.map {|e| tc.infer_set(e) })),
|
67
|
+
tc.unwrap_single_variant(PVariantType.new(o.values.map {|e| tc.infer_set(e) }))], PHashType::KEY_PAIR_TUPLE_SIZE), o.each_pair)
|
68
|
+
end
|
69
|
+
when Integer
|
70
|
+
if o == 0
|
71
|
+
Iterator.new(PUnitType::DEFAULT, o.times)
|
72
|
+
elsif o > 0
|
73
|
+
IntegerRangeIterator.new(PIntegerType.new(0, o - 1))
|
74
|
+
else
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
when PIntegerType
|
78
|
+
# a finite range will always produce at least one element since it's inclusive
|
79
|
+
o.finite_range? ? IntegerRangeIterator.new(o) : nil
|
80
|
+
when PEnumType
|
81
|
+
Iterator.new(o, o.values.each)
|
82
|
+
when Range
|
83
|
+
min = o.min
|
84
|
+
max = o.max
|
85
|
+
if min.is_a?(Integer) && max.is_a?(Integer) && max >= min
|
86
|
+
IntegerRangeIterator.new(PIntegerType.new(min, max))
|
87
|
+
elsif min.is_a?(String) && max.is_a?(String) && max >= min
|
88
|
+
# A generalized element type where only the size is inferred is used here since inferring the full
|
89
|
+
# range might waste a lot of memory.
|
90
|
+
if min.length < max.length
|
91
|
+
shortest = min
|
92
|
+
longest = max
|
93
|
+
else
|
94
|
+
shortest = max
|
95
|
+
longest = min
|
96
|
+
end
|
97
|
+
Iterator.new(PStringType.new(PIntegerType.new(shortest.length, longest.length)), o.each)
|
98
|
+
else
|
99
|
+
# Unsupported range. It's either descending or nonsensical for other reasons (float, mixed types, etc.)
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
else
|
103
|
+
# Not supported. We cannot determine the element type
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Answers the question if there is an end to the iteration. Puppet does not currently provide any unbounded
|
109
|
+
# iterables.
|
110
|
+
#
|
111
|
+
# @return [Boolean] `true` if the iteration is unbounded
|
112
|
+
def self.unbounded?(object)
|
113
|
+
case object
|
114
|
+
when Iterable
|
115
|
+
object.unbounded?
|
116
|
+
when String,Integer,Array,Hash,Enumerator,PIntegerType,PEnumType,Dir
|
117
|
+
false
|
118
|
+
else
|
119
|
+
TypeAsserter.assert_instance_of('', PIterableType::DEFAULT, object, false)
|
120
|
+
!object.respond_to?(:size)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def each(&block)
|
125
|
+
step(1, &block)
|
126
|
+
end
|
127
|
+
|
128
|
+
def element_type
|
129
|
+
PAnyType::DEFAULT
|
130
|
+
end
|
131
|
+
|
132
|
+
def reverse_each(&block)
|
133
|
+
# Default implementation cannot propagate reverse_each to a new enumerator so chained
|
134
|
+
# calls must put reverse_each last.
|
135
|
+
raise ArgumentError 'Step is not implemented'
|
136
|
+
end
|
137
|
+
|
138
|
+
def step(step, &block)
|
139
|
+
# Default implementation cannot propagate step to a new enumerator so chained
|
140
|
+
# calls must put stepping last.
|
141
|
+
raise ArgumentError 'Step is not implemented'
|
142
|
+
end
|
143
|
+
|
144
|
+
def to_a
|
145
|
+
raise Puppet::Error, 'Attempt to create an Array from an unbounded Iterable' if unbounded?
|
146
|
+
super
|
147
|
+
end
|
148
|
+
|
149
|
+
def unbounded?
|
150
|
+
true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# @api private
|
155
|
+
class Iterator
|
156
|
+
# Note! We do not include Enumerable module here since that would make this class respond
|
157
|
+
# in a bad way to all enumerable methods. We want to delegate all those calls directly to
|
158
|
+
# the contained @enumeration
|
159
|
+
include Iterable
|
160
|
+
|
161
|
+
def initialize(element_type, enumeration)
|
162
|
+
@element_type = element_type
|
163
|
+
@enumeration = enumeration
|
164
|
+
end
|
165
|
+
|
166
|
+
def element_type
|
167
|
+
@element_type
|
168
|
+
end
|
169
|
+
|
170
|
+
def size
|
171
|
+
@enumeration.size
|
172
|
+
end
|
173
|
+
|
174
|
+
def respond_to_missing?(name, include_private)
|
175
|
+
@enumeration.respond_to?(name, include_private)
|
176
|
+
end
|
177
|
+
|
178
|
+
def method_missing(name, *arguments, &block)
|
179
|
+
@enumeration.send(name, *arguments, &block)
|
180
|
+
end
|
181
|
+
|
182
|
+
def step(step, &block)
|
183
|
+
raise ArgumentError if step <= 0
|
184
|
+
r = self
|
185
|
+
r = r.step_iterator(step) if step > 1
|
186
|
+
|
187
|
+
if block_given?
|
188
|
+
begin
|
189
|
+
if block.arity == 1
|
190
|
+
loop { yield(r.next) }
|
191
|
+
else
|
192
|
+
loop { yield(*r.next) }
|
193
|
+
end
|
194
|
+
rescue StopIteration
|
195
|
+
end
|
196
|
+
self
|
197
|
+
else
|
198
|
+
r
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def reverse_each(&block)
|
203
|
+
r = Iterator.new(@element_type, @enumeration.reverse_each)
|
204
|
+
block_given? ? r.each(&block) : r
|
205
|
+
end
|
206
|
+
|
207
|
+
def step_iterator(step)
|
208
|
+
StepIterator.new(@element_type, self, step)
|
209
|
+
end
|
210
|
+
|
211
|
+
def to_s
|
212
|
+
et = element_type
|
213
|
+
et.nil? ? 'Iterator value' : "Iterator[#{et.generalize}] value"
|
214
|
+
end
|
215
|
+
|
216
|
+
def unbounded?
|
217
|
+
Iterable.unbounded?(@enumeration)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# @api private
|
222
|
+
class StepIterator < Iterator
|
223
|
+
include Enumerable
|
224
|
+
|
225
|
+
def initialize(element_type, enumeration, step_size)
|
226
|
+
super(element_type, enumeration)
|
227
|
+
raise ArgumentError if step_size <= 0
|
228
|
+
@step_size = step_size
|
229
|
+
end
|
230
|
+
|
231
|
+
def next
|
232
|
+
result = @enumeration.next
|
233
|
+
skip = @step_size - 1
|
234
|
+
if skip > 0
|
235
|
+
begin
|
236
|
+
skip.times { @enumeration.next }
|
237
|
+
rescue StopIteration
|
238
|
+
end
|
239
|
+
end
|
240
|
+
result
|
241
|
+
end
|
242
|
+
|
243
|
+
def reverse_each(&block)
|
244
|
+
r = Iterator.new(@element_type, to_a.reverse_each)
|
245
|
+
block_given? ? r.each(&block) : r
|
246
|
+
end
|
247
|
+
|
248
|
+
def size
|
249
|
+
super / @step_size
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
# @api private
|
254
|
+
class IntegerRangeIterator < Iterator
|
255
|
+
include Enumerable
|
256
|
+
|
257
|
+
def initialize(range, step = 1)
|
258
|
+
raise ArgumentError if step == 0
|
259
|
+
@range = range
|
260
|
+
@step_size = step
|
261
|
+
@current = (step < 0 ? range.to : range.from) - step
|
262
|
+
end
|
263
|
+
|
264
|
+
def element_type
|
265
|
+
@range
|
266
|
+
end
|
267
|
+
|
268
|
+
def next
|
269
|
+
value = @current + @step_size
|
270
|
+
if @step_size < 0
|
271
|
+
raise StopIteration if value < @range.from
|
272
|
+
else
|
273
|
+
raise StopIteration if value > @range.to
|
274
|
+
end
|
275
|
+
@current = value
|
276
|
+
end
|
277
|
+
|
278
|
+
def reverse_each(&block)
|
279
|
+
r = IntegerRangeIterator.new(@range, -@step_size)
|
280
|
+
block_given? ? r.each(&block) : r
|
281
|
+
end
|
282
|
+
|
283
|
+
def size
|
284
|
+
(@range.to - @range.from) / @step_size.abs
|
285
|
+
end
|
286
|
+
|
287
|
+
def step_iterator(step)
|
288
|
+
# The step iterator must use a range that has its logical end truncated at an even step boundary. This will
|
289
|
+
# fulfil two objectives:
|
290
|
+
# 1. The element_type method should not report excessive integers as possible numbers
|
291
|
+
# 2. A reversed iterator must start at the correct number
|
292
|
+
#
|
293
|
+
range = @range
|
294
|
+
step = @step_size * step
|
295
|
+
mod = (range.to - range.from) % step
|
296
|
+
if mod < 0
|
297
|
+
range = PIntegerType.new(range.from - mod, range.to)
|
298
|
+
elsif mod > 0
|
299
|
+
range = PIntegerType.new(range.from, range.to - mod)
|
300
|
+
end
|
301
|
+
IntegerRangeIterator.new(range, step)
|
302
|
+
end
|
303
|
+
|
304
|
+
def unbounded?
|
305
|
+
false
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|