puppet 3.2.4 → 3.3.0.rc2
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.
- data/COMMITTERS.md +101 -42
- data/Gemfile +15 -4
- data/README.md +5 -1
- data/README_DEVELOPER.md +117 -54
- data/Rakefile +4 -0
- data/ext/build_defaults.yaml +3 -2
- data/ext/debian/puppet-common.manpages +33 -1
- data/ext/gentoo/init.d/puppet +1 -1
- data/ext/gentoo/init.d/puppetmaster +1 -1
- data/ext/redhat/puppet.spec.erb +0 -1
- data/install.rb +2 -1
- data/lib/hiera/backend/puppet_backend.rb +1 -1
- data/lib/puppet/application.rb +10 -9
- data/lib/puppet/application/agent.rb +87 -93
- data/lib/puppet/application/apply.rb +0 -2
- data/lib/puppet/application/device.rb +3 -3
- data/lib/puppet/application/kick.rb +2 -2
- data/lib/puppet/application/master.rb +41 -19
- data/lib/puppet/application/queue.rb +5 -3
- data/lib/puppet/bindings.rb +147 -0
- data/lib/puppet/configurer.rb +25 -15
- data/lib/puppet/configurer/fact_handler.rb +2 -9
- data/lib/puppet/daemon.rb +44 -33
- data/lib/puppet/defaults.rb +57 -26
- data/lib/puppet/error.rb +1 -1
- data/lib/puppet/external/dot.rb +2 -2
- data/lib/puppet/external/nagios/base.rb +1 -6
- data/lib/puppet/external/pson/common.rb +2 -2
- data/lib/puppet/external/pson/pure/generator.rb +2 -2
- data/lib/puppet/external/pson/pure/parser.rb +1 -1
- data/lib/puppet/face/ca.rb +1 -1
- data/lib/puppet/face/config.rb +1 -1
- data/lib/puppet/face/help.rb +2 -2
- data/lib/puppet/face/module/list.rb +2 -2
- data/lib/puppet/feature/rails.rb +1 -1
- data/lib/puppet/file_bucket/dipper.rb +0 -1
- data/lib/puppet/file_serving/base.rb +1 -1
- data/lib/puppet/file_serving/configuration/parser.rb +20 -14
- data/lib/puppet/forge.rb +0 -32
- data/lib/puppet/forge/cache.rb +1 -1
- data/lib/puppet/forge/errors.rb +3 -3
- data/lib/puppet/forge/repository.rb +7 -42
- data/lib/puppet/graph.rb +11 -0
- data/lib/puppet/graph/key.rb +26 -0
- data/lib/puppet/graph/prioritizer.rb +29 -0
- data/lib/puppet/graph/random_prioritizer.rb +16 -0
- data/lib/puppet/{rb_tree_map.rb → graph/rb_tree_map.rb} +3 -3
- data/lib/puppet/graph/relationship_graph.rb +246 -0
- data/lib/puppet/graph/sequential_prioritizer.rb +31 -0
- data/lib/puppet/{simple_graph.rb → graph/simple_graph.rb} +22 -3
- data/lib/puppet/graph/title_hash_prioritizer.rb +16 -0
- data/lib/puppet/indirector.rb +2 -2
- data/lib/puppet/indirector/catalog/compiler.rb +10 -7
- data/lib/puppet/indirector/catalog/static_compiler.rb +50 -0
- data/lib/puppet/indirector/certificate/rest.rb +1 -1
- data/lib/puppet/indirector/exec.rb +1 -1
- data/lib/puppet/indirector/facts/facter.rb +2 -2
- data/lib/puppet/indirector/facts/inventory_active_record.rb +0 -1
- data/lib/puppet/indirector/facts/network_device.rb +1 -1
- data/lib/puppet/indirector/file_bucket_file/file.rb +0 -1
- data/lib/puppet/indirector/indirection.rb +2 -2
- data/lib/puppet/indirector/memory.rb +9 -0
- data/lib/puppet/indirector/node/ldap.rb +2 -4
- data/lib/puppet/indirector/report/processor.rb +1 -2
- data/lib/puppet/indirector/report/rest.rb +1 -1
- data/lib/puppet/indirector/request.rb +32 -10
- data/lib/puppet/indirector/resource/rest.rb +1 -1
- data/lib/puppet/indirector/resource_type/parser.rb +31 -12
- data/lib/puppet/interface.rb +1 -1
- data/lib/puppet/interface/documentation.rb +7 -11
- data/lib/puppet/interface/option.rb +1 -1
- data/lib/puppet/interface/option_builder.rb +1 -1
- data/lib/puppet/metatype/manager.rb +2 -2
- data/lib/puppet/module.rb +7 -1
- data/lib/puppet/module_tool.rb +1 -1
- data/lib/puppet/module_tool/applications/application.rb +10 -0
- data/lib/puppet/module_tool/applications/installer.rb +6 -3
- data/lib/puppet/module_tool/dependency.rb +2 -0
- data/lib/puppet/module_tool/errors/upgrader.rb +1 -1
- data/lib/puppet/module_tool/metadata.rb +25 -13
- data/lib/puppet/module_tool/modulefile.rb +7 -7
- data/lib/puppet/module_tool/shared_behaviors.rb +4 -2
- data/lib/puppet/module_tool/skeleton.rb +1 -1
- data/lib/puppet/module_tool/skeleton/templates/generator/manifests/init.pp.erb +5 -5
- data/lib/puppet/module_tool/skeleton/templates/generator/tests/init.pp.erb +5 -4
- data/lib/puppet/network/auth_config_parser.rb +3 -0
- data/lib/puppet/network/authconfig.rb +0 -1
- data/lib/puppet/network/authorization.rb +1 -1
- data/lib/puppet/network/authstore.rb +2 -2
- data/lib/puppet/network/format_handler.rb +25 -114
- data/lib/puppet/network/format_support.rb +106 -0
- data/lib/puppet/network/formats.rb +10 -4
- data/lib/puppet/network/http/compression.rb +1 -1
- data/lib/puppet/network/http/connection.rb +76 -32
- data/lib/puppet/network/http/handler.rb +122 -61
- data/lib/puppet/network/http/rack/rest.rb +1 -1
- data/lib/puppet/network/http/webrick/rest.rb +9 -3
- data/lib/puppet/network/http_pool.rb +2 -2
- data/lib/puppet/network/resolver.rb +1 -0
- data/lib/puppet/network/server.rb +5 -81
- data/lib/puppet/node/environment.rb +256 -13
- data/lib/puppet/node/facts.rb +28 -2
- data/lib/puppet/parameter.rb +27 -18
- data/lib/puppet/parameter/boolean.rb +20 -0
- data/lib/puppet/parameter/path.rb +1 -1
- data/lib/puppet/parameter/value.rb +1 -1
- data/lib/puppet/parameter/value_collection.rb +1 -1
- data/lib/puppet/parser/ast/arithmetic_operator.rb +8 -0
- data/lib/puppet/parser/ast/casestatement.rb +0 -3
- data/lib/puppet/parser/ast/lambda.rb +25 -6
- data/lib/puppet/parser/ast/leaf.rb +10 -3
- data/lib/puppet/parser/ast/nop.rb +1 -1
- data/lib/puppet/parser/ast/resource_override.rb +0 -2
- data/lib/puppet/parser/compiler.rb +92 -34
- data/lib/puppet/parser/files.rb +0 -5
- data/lib/puppet/parser/functions/create_resources.rb +23 -46
- data/lib/puppet/parser/functions/each.rb +0 -2
- data/lib/puppet/parser/functions/extlookup.rb +2 -2
- data/lib/puppet/parser/functions/foreach.rb +0 -2
- data/lib/puppet/parser/functions/hiera_include.rb +1 -1
- data/lib/puppet/parser/functions/lookup.rb +44 -0
- data/lib/puppet/parser/functions/slice.rb +1 -1
- data/lib/puppet/parser/grammar.ra +0 -1
- data/lib/puppet/parser/lexer.rb +0 -1
- data/lib/puppet/parser/parser.rb +0 -1
- data/lib/puppet/parser/parser_factory.rb +3 -2
- data/lib/puppet/parser/parser_support.rb +1 -1
- data/lib/puppet/parser/relationship.rb +1 -1
- data/lib/puppet/parser/scope.rb +49 -24
- data/lib/puppet/parser/type_loader.rb +13 -18
- data/lib/puppet/pops.rb +45 -0
- data/lib/puppet/pops/adaptable.rb +2 -2
- data/lib/puppet/pops/adapters.rb +4 -0
- data/lib/puppet/pops/binder/binder.rb +421 -0
- data/lib/puppet/pops/binder/binder_issues.rb +142 -0
- data/lib/puppet/pops/binder/bindings_checker.rb +217 -0
- data/lib/puppet/pops/binder/bindings_composer.rb +241 -0
- data/lib/puppet/pops/binder/bindings_factory.rb +847 -0
- data/lib/puppet/pops/binder/bindings_label_provider.rb +46 -0
- data/lib/puppet/pops/binder/bindings_loader.rb +79 -0
- data/lib/puppet/pops/binder/bindings_model.rb +215 -0
- data/lib/puppet/pops/binder/bindings_model_dumper.rb +205 -0
- data/lib/puppet/pops/binder/bindings_validator_factory.rb +28 -0
- data/lib/puppet/pops/binder/config/binder_config.rb +139 -0
- data/lib/puppet/pops/binder/config/binder_config_checker.rb +183 -0
- data/lib/puppet/pops/binder/config/diagnostic_producer.rb +32 -0
- data/lib/puppet/pops/binder/config/issues.rb +106 -0
- data/lib/puppet/pops/binder/hiera2.rb +10 -0
- data/lib/puppet/pops/binder/hiera2/bindings_provider.rb +148 -0
- data/lib/puppet/pops/binder/hiera2/config.rb +69 -0
- data/lib/puppet/pops/binder/hiera2/config_checker.rb +68 -0
- data/lib/puppet/pops/binder/hiera2/diagnostic_producer.rb +36 -0
- data/lib/puppet/pops/binder/hiera2/issues.rb +67 -0
- data/lib/puppet/pops/binder/hiera2/json_backend.rb +18 -0
- data/lib/puppet/pops/binder/hiera2/yaml_backend.rb +21 -0
- data/lib/puppet/pops/binder/injector.rb +688 -0
- data/lib/puppet/pops/binder/injector_entry.rb +53 -0
- data/lib/puppet/pops/binder/key_factory.rb +61 -0
- data/lib/puppet/pops/binder/producers.rb +829 -0
- data/lib/puppet/pops/binder/scheme_handler/confdir_hiera_scheme.rb +67 -0
- data/lib/puppet/pops/binder/scheme_handler/confdir_scheme.rb +34 -0
- data/lib/puppet/pops/binder/scheme_handler/module_hiera_scheme.rb +92 -0
- data/lib/puppet/pops/binder/scheme_handler/module_scheme.rb +84 -0
- data/lib/puppet/pops/binder/scheme_handler/symbolic_scheme.rb +54 -0
- data/lib/puppet/pops/binder/system_bindings.rb +72 -0
- data/lib/puppet/pops/issue_reporter.rb +75 -0
- data/lib/puppet/pops/issues.rb +9 -5
- data/lib/puppet/pops/model/ast_transformer.rb +4 -4
- data/lib/puppet/pops/model/ast_tree_dumper.rb +1 -1
- data/lib/puppet/pops/model/factory.rb +25 -13
- data/lib/puppet/pops/model/model.rb +1 -1
- data/lib/puppet/pops/model/tree_dumper.rb +2 -2
- data/lib/puppet/pops/parser/egrammar.ra +0 -1
- data/lib/puppet/pops/parser/eparser.rb +1 -2
- data/lib/puppet/pops/parser/evaluating_parser.rb +162 -0
- data/lib/puppet/pops/parser/lexer.rb +8 -6
- data/lib/puppet/pops/types/class_loader.rb +118 -0
- data/lib/puppet/pops/types/type_calculator.rb +557 -0
- data/lib/puppet/pops/types/type_factory.rb +147 -0
- data/lib/puppet/pops/types/type_parser.rb +117 -0
- data/lib/puppet/pops/types/types.rb +132 -0
- data/lib/puppet/pops/validation.rb +146 -17
- data/lib/puppet/pops/validation/checker3_1.rb +1 -1
- data/lib/puppet/pops/validation/validator_factory_3_1.rb +6 -16
- data/lib/puppet/property.rb +3 -3
- data/lib/puppet/property/keyvalue.rb +1 -1
- data/lib/puppet/provider.rb +2 -2
- data/lib/puppet/provider/aixobject.rb +19 -21
- data/lib/puppet/provider/augeas/augeas.rb +3 -1
- data/lib/puppet/provider/command.rb +2 -2
- data/lib/puppet/provider/group/aix.rb +1 -1
- data/lib/puppet/provider/group/ldap.rb +1 -1
- data/lib/puppet/provider/macauthorization/macauthorization.rb +1 -1
- data/lib/puppet/provider/mailalias/aliases.rb +3 -8
- data/lib/puppet/provider/mcx/mcxcontent.rb +7 -1
- data/lib/puppet/provider/mount.rb +8 -3
- data/lib/puppet/provider/nameservice.rb +1 -1
- data/lib/puppet/provider/nameservice/directoryservice.rb +5 -5
- data/lib/puppet/provider/package/appdmg.rb +1 -1
- data/lib/puppet/provider/package/apt.rb +0 -1
- data/lib/puppet/provider/package/dpkg.rb +86 -32
- data/lib/puppet/provider/package/fink.rb +0 -2
- data/lib/puppet/provider/package/freebsd.rb +0 -2
- data/lib/puppet/provider/package/openbsd.rb +57 -10
- data/lib/puppet/provider/package/opkg.rb +0 -1
- data/lib/puppet/provider/package/pacman.rb +0 -1
- data/lib/puppet/provider/package/pip.rb +1 -1
- data/lib/puppet/provider/package/pkgdmg.rb +17 -6
- data/lib/puppet/provider/package/pkgutil.rb +1 -1
- data/lib/puppet/provider/package/portage.rb +9 -1
- data/lib/puppet/provider/package/ports.rb +2 -2
- data/lib/puppet/provider/package/rpm.rb +29 -12
- data/lib/puppet/provider/package/rug.rb +1 -1
- data/lib/puppet/provider/package/urpmi.rb +11 -15
- data/lib/puppet/provider/package/windows/exe_package.rb +1 -1
- data/lib/puppet/provider/package/windows/package.rb +1 -26
- data/lib/puppet/provider/package/yum.rb +1 -1
- data/lib/puppet/provider/package/zypper.rb +22 -3
- data/lib/puppet/provider/parsedfile.rb +1 -12
- data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +1 -1
- data/lib/puppet/provider/service/base.rb +1 -1
- data/lib/puppet/provider/service/daemontools.rb +3 -3
- data/lib/puppet/provider/service/debian.rb +1 -1
- data/lib/puppet/provider/service/init.rb +14 -20
- data/lib/puppet/provider/service/openrc.rb +3 -1
- data/lib/puppet/provider/service/redhat.rb +5 -8
- data/lib/puppet/provider/service/runit.rb +3 -2
- data/lib/puppet/provider/service/systemd.rb +1 -1
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
- data/lib/puppet/provider/sshkey/parsed.rb +0 -2
- data/lib/puppet/provider/user/aix.rb +25 -12
- data/lib/puppet/provider/user/directoryservice.rb +4 -7
- data/lib/puppet/provider/user/ldap.rb +0 -1
- data/lib/puppet/provider/user/user_role_add.rb +2 -0
- data/lib/puppet/provider/user/useradd.rb +1 -1
- data/lib/puppet/provider/zone/solaris.rb +1 -2
- data/lib/puppet/reference/metaparameter.rb +1 -1
- data/lib/puppet/reference/type.rb +1 -1
- data/lib/puppet/reports/rrdgraph.rb +1 -1
- data/lib/puppet/reports/tagmail.rb +1 -1
- data/lib/puppet/resource.rb +16 -4
- data/lib/puppet/resource/catalog.rb +111 -173
- data/lib/puppet/resource/status.rb +42 -3
- data/lib/puppet/resource/type.rb +33 -46
- data/lib/puppet/resource/type_collection.rb +19 -15
- data/lib/puppet/run.rb +5 -1
- data/lib/puppet/scheduler/scheduler.rb +14 -15
- data/lib/puppet/settings.rb +78 -41
- data/lib/puppet/settings/boolean_setting.rb +0 -2
- data/lib/puppet/settings/config_file.rb +0 -2
- data/lib/puppet/settings/directory_setting.rb +0 -2
- data/lib/puppet/settings/duration_setting.rb +0 -2
- data/lib/puppet/settings/enum_setting.rb +16 -0
- data/lib/puppet/settings/file_setting.rb +0 -2
- data/lib/puppet/settings/path_setting.rb +0 -2
- data/lib/puppet/settings/string_setting.rb +0 -3
- data/lib/puppet/settings/terminus_setting.rb +0 -2
- data/lib/puppet/ssl/certificate_authority.rb +102 -9
- data/lib/puppet/test/test_helper.rb +1 -0
- data/lib/puppet/transaction.rb +130 -292
- data/lib/puppet/transaction/additional_resource_generator.rb +126 -0
- data/lib/puppet/transaction/event.rb +16 -1
- data/lib/puppet/transaction/report.rb +34 -14
- data/lib/puppet/transaction/resource_harness.rb +16 -19
- data/lib/puppet/type.rb +59 -53
- data/lib/puppet/type/component.rb +0 -2
- data/lib/puppet/type/cron.rb +13 -2
- data/lib/puppet/type/exec.rb +5 -7
- data/lib/puppet/type/file.rb +9 -32
- data/lib/puppet/type/file/content.rb +4 -1
- data/lib/puppet/type/file/ctime.rb +3 -1
- data/lib/puppet/type/file/ensure.rb +1 -1
- data/lib/puppet/type/file/mode.rb +0 -1
- data/lib/puppet/type/file/mtime.rb +2 -1
- data/lib/puppet/type/group.rb +7 -9
- data/lib/puppet/type/host.rb +1 -2
- data/lib/puppet/type/mcx.rb +0 -1
- data/lib/puppet/type/mount.rb +38 -6
- data/lib/puppet/type/package.rb +2 -2
- data/lib/puppet/type/resources.rb +5 -4
- data/lib/puppet/type/schedule.rb +1 -4
- data/lib/puppet/type/selmodule.rb +1 -1
- data/lib/puppet/type/service.rb +1 -3
- data/lib/puppet/type/tidy.rb +3 -3
- data/lib/puppet/type/user.rb +9 -13
- data/lib/puppet/type/yumrepo.rb +11 -7
- data/lib/puppet/util.rb +14 -7
- data/lib/puppet/util/autoload.rb +0 -1
- data/lib/puppet/util/backups.rb +1 -3
- data/lib/puppet/util/classgen.rb +1 -1
- data/lib/puppet/util/command_line/puppet_option_parser.rb +1 -3
- data/lib/puppet/util/command_line/trollop.rb +1 -1
- data/lib/puppet/util/constant_inflector.rb +1 -2
- data/lib/puppet/util/errors.rb +1 -0
- data/lib/puppet/util/file_watcher.rb +28 -0
- data/lib/puppet/util/fileparsing.rb +1 -3
- data/lib/puppet/util/filetype.rb +0 -1
- data/lib/puppet/util/http_proxy.rb +38 -0
- data/lib/puppet/util/ldap/manager.rb +1 -2
- data/lib/puppet/util/log.rb +31 -10
- data/lib/puppet/util/log/destinations.rb +0 -50
- data/lib/puppet/util/metric.rb +8 -1
- data/lib/puppet/util/monkey_patches.rb +14 -148
- data/lib/puppet/util/network_device/cisco/facts.rb +1 -1
- data/lib/puppet/util/network_device/config.rb +6 -9
- data/lib/puppet/util/network_device/transport/ssh.rb +1 -1
- data/lib/puppet/util/pidlock.rb +3 -0
- data/lib/puppet/util/posix.rb +1 -1
- data/lib/puppet/util/profiler.rb +1 -1
- data/lib/puppet/util/rdoc.rb +1 -1
- data/lib/puppet/util/rdoc/generators/puppet_generator.rb +0 -1
- data/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb +50 -42
- data/lib/puppet/util/retryaction.rb +0 -1
- data/lib/puppet/util/symbolic_file_mode.rb +5 -1
- data/lib/puppet/util/tagging.rb +0 -2
- data/lib/puppet/util/warnings.rb +3 -0
- data/lib/puppet/util/watched_file.rb +37 -0
- data/lib/puppet/util/watcher.rb +17 -0
- data/lib/puppet/util/watcher/change_watcher.rb +33 -0
- data/lib/puppet/util/watcher/periodic_watcher.rb +37 -0
- data/lib/puppet/util/watcher/timer.rb +19 -0
- data/lib/puppet/util/windows/user.rb +1 -1
- data/lib/puppet/version.rb +1 -1
- data/lib/puppetx.rb +109 -0
- data/lib/puppetx/puppet/bindings_scheme_handler.rb +130 -0
- data/lib/puppetx/puppet/hiera2_backend.rb +31 -0
- data/lib/puppetx/puppet/syntax_checker.rb +91 -0
- data/lib/puppetx/puppetlabs/syntax_checkers/json.rb +39 -0
- data/lib/semver.rb +1 -1
- data/man/man8/puppet-kick.8 +1 -1
- data/spec/fixtures/integration/provider/cron/crontab/unspecialized +15 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/binder_config.yaml +18 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/hiera.yaml +8 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/modules/good/common.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/modules/good/hiera.yaml +10 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/binder_config.yaml +19 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/common.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/hiera.yaml +11 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/localhost.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/common.yaml +3 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/hiera.yaml +13 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/lib/puppet/bindings/awesome/default.rb +4 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/lib/puppetx/awesome/echo_backend.rb +11 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/lib/puppetx/awesome/echo_scheme_handler.rb +18 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/localhost.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/bad/common.yaml +3 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/bad/hiera_config.yaml +9 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/good/common.yaml +2 -0
- data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/good/hiera.yaml +11 -0
- data/spec/fixtures/unit/pops/binder/config/binder_config/ok/binder_config.yaml +9 -0
- data/spec/fixtures/unit/pops/binder/hiera2/bindings_provider/ok/hiera.yaml +9 -0
- data/spec/fixtures/unit/pops/binder/hiera2/bindings_provider/ok/node.example.com.json +9 -0
- data/spec/fixtures/unit/pops/binder/hiera2/bindings_provider/ok/node.example.com.yaml +5 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/bad_syntax/hiera.yaml +10 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/malformed_hierarchy/hiera.yaml +8 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/missing/foo.txt +1 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/no_backends/hiera.yaml +7 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/no_hierarchy/hiera.yaml +4 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/not_a_hash/hiera.yaml +2 -0
- data/spec/fixtures/unit/pops/binder/hiera2/config/ok/hiera.yaml +8 -0
- data/spec/fixtures/unit/pops/binder/hiera2/yaml_backend/empty/common.yaml +0 -0
- data/spec/fixtures/unit/pops/binder/hiera2/yaml_backend/invalid/common.yaml +1 -0
- data/spec/fixtures/unit/pops/binder/hiera2/yaml_backend/ok/common.yaml +2 -0
- data/spec/fixtures/unit/provider/package/openbsd/pkginfo_flavors.list +2 -0
- data/spec/integration/agent/logging_spec.rb +178 -0
- data/spec/integration/configurer_spec.rb +1 -1
- data/spec/integration/defaults_spec.rb +0 -6
- data/spec/integration/network/authconfig_spec.rb +19 -0
- data/spec/integration/network/server/webrick_spec.rb +10 -11
- data/spec/integration/parser/catalog_spec.rb +85 -0
- data/spec/integration/provider/cron/crontab_spec.rb +11 -0
- data/spec/integration/provider/mount_spec.rb +1 -0
- data/spec/integration/transaction_spec.rb +8 -8
- data/spec/integration/type/file_spec.rb +1 -1
- data/spec/integration/util/settings_spec.rb +58 -11
- data/spec/lib/matchers/include_in_order.rb +21 -0
- data/spec/lib/matchers/include_in_order_spec.rb +30 -0
- data/spec/lib/matchers/relationship_graph_matchers.rb +48 -0
- data/spec/lib/puppet_spec/compiler.rb +24 -0
- data/spec/lib/puppet_spec/pops.rb +16 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/unit/application/agent_spec.rb +145 -145
- data/spec/unit/application/apply_spec.rb +1 -1
- data/spec/unit/application/doc_spec.rb +1 -1
- data/spec/unit/application/face_base_spec.rb +3 -3
- data/spec/unit/application/facts_spec.rb +1 -0
- data/spec/unit/application/master_spec.rb +0 -15
- data/spec/unit/application/queue_spec.rb +6 -12
- data/spec/unit/application/resource_spec.rb +1 -1
- data/spec/unit/configurer/fact_handler_spec.rb +19 -50
- data/spec/unit/configurer_spec.rb +23 -7
- data/spec/unit/daemon_spec.rb +97 -121
- data/spec/unit/defaults_spec.rb +44 -0
- data/spec/unit/face/node_spec.rb +2 -2
- data/spec/unit/file_serving/configuration/parser_spec.rb +23 -33
- data/spec/unit/file_serving/configuration_spec.rb +2 -2
- data/spec/unit/file_serving/mount/file_spec.rb +4 -4
- data/spec/unit/forge/repository_spec.rb +9 -29
- data/spec/unit/graph/key_spec.rb +41 -0
- data/spec/unit/{rb_tree_map_spec.rb → graph/rb_tree_map_spec.rb} +7 -7
- data/spec/unit/graph/relationship_graph_spec.rb +393 -0
- data/spec/unit/graph/sequential_prioritizer_spec.rb +32 -0
- data/spec/unit/{simple_graph_spec.rb → graph/simple_graph.rb} +42 -254
- data/spec/unit/graph/title_hash_prioritizer_spec.rb +49 -0
- data/spec/unit/hiera_puppet_spec.rb +1 -1
- data/spec/unit/indirector/catalog/active_record_spec.rb +4 -2
- data/spec/unit/indirector/catalog/compiler_spec.rb +20 -26
- data/spec/unit/indirector/face_spec.rb +1 -1
- data/spec/unit/indirector/facts/facter_spec.rb +11 -1
- data/spec/unit/indirector/facts/network_device_spec.rb +11 -1
- data/spec/unit/indirector/hiera_spec.rb +1 -1
- data/spec/unit/indirector/instrumentation_data/local_spec.rb +1 -1
- data/spec/unit/indirector/instrumentation_listener/local_spec.rb +1 -1
- data/spec/unit/indirector/request_spec.rb +92 -39
- data/spec/unit/indirector/rest_spec.rb +1 -0
- data/spec/unit/indirector_spec.rb +2 -2
- data/spec/unit/interface/option_builder_spec.rb +1 -0
- data/spec/unit/interface/option_spec.rb +1 -0
- data/spec/unit/interface_spec.rb +2 -2
- data/spec/unit/module_tool/applications/installer_spec.rb +49 -2
- data/spec/unit/module_tool/metadata_spec.rb +13 -0
- data/spec/unit/network/authstore_spec.rb +1 -1
- data/spec/unit/network/format_handler_spec.rb +33 -282
- data/spec/unit/network/format_support_spec.rb +199 -0
- data/spec/unit/network/formats_spec.rb +2 -2
- data/spec/unit/network/http/connection_spec.rb +88 -7
- data/spec/unit/network/http/handler_spec.rb +271 -249
- data/spec/unit/network/http/rack/rest_spec.rb +1 -1
- data/spec/unit/network/http/webrick/rest_spec.rb +73 -22
- data/spec/unit/network/http_pool_spec.rb +40 -0
- data/spec/unit/network/server_spec.rb +18 -207
- data/spec/unit/node/facts_spec.rb +68 -17
- data/spec/unit/other/selinux_spec.rb +24 -20
- data/spec/unit/parameter/boolean_spec.rb +25 -0
- data/spec/unit/parameter/value_collection_spec.rb +7 -7
- data/spec/unit/parameter_spec.rb +10 -13
- data/spec/unit/parser/ast/function_spec.rb +4 -4
- data/spec/unit/parser/ast/leaf_spec.rb +45 -6
- data/spec/unit/parser/collector_spec.rb +3 -3
- data/spec/unit/parser/compiler_spec.rb +4 -3
- data/spec/unit/parser/functions/create_resources_spec.rb +9 -25
- data/spec/unit/parser/functions/extlookup_spec.rb +2 -2
- data/spec/unit/parser/functions/hiera_include_spec.rb +12 -0
- data/spec/unit/parser/functions/lookup_spec.rb +96 -0
- data/spec/unit/parser/functions/regsubst_spec.rb +2 -2
- data/spec/unit/parser/functions/split_spec.rb +2 -2
- data/spec/unit/parser/functions/sprintf_spec.rb +1 -1
- data/spec/unit/parser/functions/versioncmp_spec.rb +2 -2
- data/spec/unit/parser/functions_spec.rb +7 -7
- data/spec/unit/parser/lexer_spec.rb +1 -1
- data/spec/unit/parser/methods/collect_spec.rb +43 -0
- data/spec/unit/parser/resource_spec.rb +9 -9
- data/spec/unit/parser/scope_spec.rb +45 -2
- data/spec/unit/parser/type_loader_spec.rb +159 -175
- data/spec/unit/pops/binder/binder_spec.rb +62 -0
- data/spec/unit/pops/binder/bindings_checker_spec.rb +196 -0
- data/spec/unit/pops/binder/bindings_composer_spec.rb +89 -0
- data/spec/unit/pops/binder/bindings_validator_factory_spec.rb +18 -0
- data/spec/unit/pops/binder/config/binder_config_spec.rb +48 -0
- data/spec/unit/pops/binder/hiera2/bindings_provider_spec.rb +74 -0
- data/spec/unit/pops/binder/hiera2/config_spec.rb +61 -0
- data/spec/unit/pops/binder/hiera2/yaml_backend_spec.rb +33 -0
- data/spec/unit/pops/binder/injector_spec.rb +789 -0
- data/spec/unit/pops/containment_spec.rb +1 -0
- data/spec/unit/pops/issues_spec.rb +1 -1
- data/spec/unit/pops/parser/evaluating_parser_spec.rb +88 -0
- data/spec/unit/pops/parser/lexer_spec.rb +1 -1
- data/spec/unit/pops/parser/parse_calls_spec.rb +4 -0
- data/spec/unit/pops/parser/parser_spec.rb +1 -1
- data/spec/unit/pops/types/type_calculator_spec.rb +484 -0
- data/spec/unit/pops/types/type_factory_spec.rb +65 -0
- data/spec/unit/pops/types/type_parser_spec.rb +93 -0
- data/spec/unit/property/list_spec.rb +1 -1
- data/spec/unit/property/ordered_list_spec.rb +1 -1
- data/spec/unit/provider/aixobject_spec.rb +101 -0
- data/spec/unit/provider/augeas/augeas_spec.rb +14 -3
- data/spec/unit/provider/mcx/mcxcontent_spec.rb +52 -16
- data/spec/unit/provider/mount/parsed_spec.rb +44 -56
- data/spec/unit/provider/mount_spec.rb +11 -2
- data/spec/unit/provider/naginator_spec.rb +8 -0
- data/spec/unit/provider/package/apt_spec.rb +5 -1
- data/spec/unit/provider/package/aptitude_spec.rb +9 -5
- data/spec/unit/provider/package/aptrpm_spec.rb +2 -2
- data/spec/unit/provider/package/dpkg_spec.rb +274 -99
- data/spec/unit/provider/package/openbsd_spec.rb +84 -1
- data/spec/unit/provider/package/opkg_spec.rb +3 -3
- data/spec/unit/provider/package/pip_spec.rb +16 -0
- data/spec/unit/provider/package/pkgdmg_spec.rb +62 -7
- data/spec/unit/provider/package/rpm_spec.rb +112 -21
- data/spec/unit/provider/package/urpmi.rb +80 -0
- data/spec/unit/provider/package/windows/exe_package_spec.rb +1 -1
- data/spec/unit/provider/package/yum_spec.rb +85 -0
- data/spec/unit/provider/package/zypper_spec.rb +25 -6
- data/spec/unit/provider/parsedfile_spec.rb +3 -2
- data/spec/unit/provider/service/init_spec.rb +10 -10
- data/spec/unit/provider/service/openrc_spec.rb +16 -0
- data/spec/unit/provider/service/openwrt_spec.rb +1 -1
- data/spec/unit/provider/service/redhat_spec.rb +7 -0
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +2 -2
- data/spec/unit/provider/user/aix_spec.rb +89 -0
- data/spec/unit/provider/user/directoryservice_spec.rb +11 -4
- data/spec/unit/provider/user/user_role_add_spec.rb +18 -0
- data/spec/unit/provider_spec.rb +2 -13
- data/spec/unit/reports/http_spec.rb +1 -1
- data/spec/unit/resource/catalog_spec.rb +23 -97
- data/spec/unit/resource/resource_type.json +34 -0
- data/spec/unit/resource/status_spec.rb +56 -0
- data/spec/unit/resource/type_collection_spec.rb +6 -6
- data/spec/unit/resource/type_spec.rb +25 -5
- data/spec/unit/resource_spec.rb +68 -24
- data/spec/unit/run_spec.rb +16 -0
- data/spec/unit/scheduler/scheduler_spec.rb +14 -27
- data/spec/unit/semver_spec.rb +5 -0
- data/spec/unit/settings/enum_setting_spec.rb +27 -0
- data/spec/unit/settings_spec.rb +53 -44
- data/spec/unit/ssl/certificate_authority_spec.rb +155 -19
- data/spec/unit/transaction/additional_resource_generator_spec.rb +419 -0
- data/spec/unit/transaction/event_manager_spec.rb +2 -2
- data/spec/unit/transaction/event_spec.rb +57 -0
- data/spec/unit/transaction/report_spec.rb +66 -0
- data/spec/unit/transaction/resource_harness_spec.rb +27 -20
- data/spec/unit/transaction_spec.rb +182 -390
- data/spec/unit/type/augeas_spec.rb +3 -3
- data/spec/unit/type/component_spec.rb +0 -9
- data/spec/unit/type/computer_spec.rb +1 -1
- data/spec/unit/type/cron_spec.rb +2 -2
- data/spec/unit/type/exec_spec.rb +4 -2
- data/spec/unit/type/file/content_spec.rb +11 -0
- data/spec/unit/type/file/group_spec.rb +1 -1
- data/spec/unit/type/file_spec.rb +16 -8
- data/spec/unit/type/mount_spec.rb +445 -259
- data/spec/unit/type/package_spec.rb +4 -4
- data/spec/unit/type/resources_spec.rb +30 -1
- data/spec/unit/type/user_spec.rb +26 -3
- data/spec/unit/type/yumrepo_spec.rb +7 -27
- data/spec/unit/type/zone_spec.rb +4 -1
- data/spec/unit/type_spec.rb +66 -33
- data/spec/unit/util/backups_spec.rb +3 -3
- data/spec/unit/util/http_proxy_spec.rb +83 -0
- data/spec/unit/util/log_spec.rb +79 -8
- data/spec/unit/util/metric_spec.rb +12 -0
- data/spec/unit/util/monkey_patches_spec.rb +6 -0
- data/spec/unit/util/network_device/config_spec.rb +26 -64
- data/spec/unit/util/pidlock_spec.rb +4 -1
- data/spec/unit/util/tagging_spec.rb +5 -9
- data/spec/unit/util/warnings_spec.rb +1 -1
- data/spec/unit/util/watched_file_spec.rb +52 -0
- data/spec/unit/util/watcher/periodic_watcher_spec.rb +52 -0
- data/spec/unit/util/watcher_spec.rb +56 -0
- data/spec/unit/util_spec.rb +16 -0
- metadata +2767 -2576
- data/ext/debian/puppet.manpages +0 -32
- data/ext/osx/PackageInfo.plist +0 -36
- data/ext/osx/createpackage.sh +0 -187
- data/ext/redhat/rundir-perms.patch +0 -28
- data/lib/puppet/external/base64.rb +0 -19
- data/lib/puppet/util/graph.rb +0 -27
- data/lib/puppet/util/loadedfile.rb +0 -61
- data/lib/puppet/util/log_paths.rb +0 -22
- data/lib/puppet/util/subclass_loader.rb +0 -78
- data/spec/monkey_patches/publicize_methods.rb +0 -11
- data/spec/unit/util/loadedfile_spec.rb +0 -71
@@ -0,0 +1,847 @@
|
|
1
|
+
# A helper class that makes it easier to construct a Bindings model.
|
2
|
+
#
|
3
|
+
# The Bindings Model
|
4
|
+
# ------------------
|
5
|
+
# The BindingsModel (defined in {Puppet::Pops::Binder::Bindings} is a model that is intended to be generally free from Ruby concerns.
|
6
|
+
# This means that it is possible for system integrators to create and serialize such models using other technologies than
|
7
|
+
# Ruby. This manifests itself in the model in that producers are described using instances of a `ProducerDescriptor` rather than
|
8
|
+
# describing Ruby classes directly. This is also true of the type system where type is expressed using the {Puppet::Pops::Types} model
|
9
|
+
# to describe all types.
|
10
|
+
#
|
11
|
+
# This class, the `BindingsFactory` is a concrete Ruby API for constructing instances of classes in the model.
|
12
|
+
#
|
13
|
+
# Named Bindings
|
14
|
+
# --------------
|
15
|
+
# The typical usage of the factory is to call {named_bindings} which creates a container of bindings wrapped in a *build object*
|
16
|
+
# equipped with convenience methods to define the details of the just created named bindings.
|
17
|
+
# The returned builder is an instance of {Puppet::Pops::Binder::BindingsFactory::BindingsContainerBuilder BindingsContainerBuilder}.
|
18
|
+
#
|
19
|
+
# Binding
|
20
|
+
# -------
|
21
|
+
# A Binding binds a type/name key to a producer of a value. A binding is conveniently created by calling `bind` on a
|
22
|
+
# `BindingsContainerBuilder`. The call to bind, produces a binding wrapped in a build object equipped with convenience methods
|
23
|
+
# to define the details of the just created binding. The returned builder is an instance of
|
24
|
+
# {Puppet::Pops::Binder::BindingsFactory::BindingsBuilder BindingsBuilder}.
|
25
|
+
#
|
26
|
+
# Multibinding
|
27
|
+
# ------------
|
28
|
+
# A multibinding works like a binding, but it requires an additional ID. It also places constraints on the type of the binding;
|
29
|
+
# it must be a collection type (Hash or Array).
|
30
|
+
#
|
31
|
+
# Constructing and Contributing Bindings from Ruby
|
32
|
+
# ------------------------------------------------
|
33
|
+
# The bindings system is used by referencing bindings symbolically; these are then specified in a Ruby file which is autoloaded
|
34
|
+
# by Puppet. The entry point for user code that creates bindings is described in {Puppet::Bindings Bindings}.
|
35
|
+
# That class makes use of a BindingsFactory, and the builder objects to make it easy to construct bindings.
|
36
|
+
#
|
37
|
+
# It is intended that a user defining bindings in Ruby should be able to use the builder object methods for the majority of tasks.
|
38
|
+
# If something advanced is wanted, use of one of the helper class methods on the BuildingsFactory, and/or the
|
39
|
+
# {Puppet::Pops::Types::TypeCalculator TypeCalculator} will be required to create and configure objects that are not handled by
|
40
|
+
# the methods in the builder objects.
|
41
|
+
#
|
42
|
+
# Chaining of calls
|
43
|
+
# ------------------
|
44
|
+
# Since all the build methods return the build object it is easy to stack on additional calls. The intention is to
|
45
|
+
# do this in an order that is readable from left to right: `bind.string.name('thename').to(42)`, but there is nothing preventing
|
46
|
+
# making the calls in some other order e.g. `bind.to(42).name('thename').string`, the second is quite unreadable but produces
|
47
|
+
# the same result.
|
48
|
+
#
|
49
|
+
# For sake of human readability, the method `name` is alsp available as `named`, with the intention that it is used after a type,
|
50
|
+
# e.g. `bind.integer.named('the meaning of life').to(42)`
|
51
|
+
#
|
52
|
+
# Methods taking blocks
|
53
|
+
# ----------------------
|
54
|
+
# Several methods take an optional block. The block evaluates with the builder object as `self`. This means that there is no
|
55
|
+
# need to chain the methods calls, they can instead be made in sequence - e.g.
|
56
|
+
#
|
57
|
+
# bind do
|
58
|
+
# integer
|
59
|
+
# named 'the meaning of life'
|
60
|
+
# to 42
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# or mix the two styles
|
64
|
+
#
|
65
|
+
# bind do
|
66
|
+
# integer.named 'the meaning of life'
|
67
|
+
# to 42
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# Unwrapping the result
|
71
|
+
# ---------------------
|
72
|
+
# The result from all methods is a builder object. Call the method `model` to unwrap the constructed bindings model object.
|
73
|
+
#
|
74
|
+
# bindings = BindingsFactory.named_bindings('my named bindings') do
|
75
|
+
# # bind things
|
76
|
+
# end.model
|
77
|
+
#
|
78
|
+
# @example Create a NamedBinding with content
|
79
|
+
# result = Puppet::Pops::Binder::BindingsFactory.named_bindings("mymodule::mybindings") do
|
80
|
+
# bind.name("foo").to(42)
|
81
|
+
# when_in_category("node", "kermit.example.com").bind.name("foo").to(43)
|
82
|
+
# bind.string.name("site url").to("http://www.example.com")
|
83
|
+
# end
|
84
|
+
# result.model()
|
85
|
+
#
|
86
|
+
# @api public
|
87
|
+
#
|
88
|
+
module Puppet::Pops::Binder::BindingsFactory
|
89
|
+
|
90
|
+
# Alias for the {Puppet::Pops::Types::TypeFactory TypeFactory}. This is also available as the method
|
91
|
+
# `type_factory`.
|
92
|
+
#
|
93
|
+
T = Puppet::Pops::Types::TypeFactory
|
94
|
+
|
95
|
+
# Abstract base class for bindings object builders.
|
96
|
+
# Supports delegation of method calls to the BindingsFactory class methods for all methods not implemented
|
97
|
+
# by a concrete builder.
|
98
|
+
#
|
99
|
+
# @abstract
|
100
|
+
#
|
101
|
+
class AbstractBuilder
|
102
|
+
# The built model object.
|
103
|
+
attr_reader :model
|
104
|
+
|
105
|
+
# @param binding [Puppet::Pops::Binder::Bindings::AbstractBinding] The binding to build.
|
106
|
+
# @api public
|
107
|
+
def initialize(binding)
|
108
|
+
@model = binding
|
109
|
+
end
|
110
|
+
|
111
|
+
# Provides convenient access to the Bindings Factory class methods. The intent is to provide access to the
|
112
|
+
# methods that return producers for the purpose of composing more elaborate things than the builder convenience
|
113
|
+
# methods support directly.
|
114
|
+
# @api private
|
115
|
+
#
|
116
|
+
def method_missing(meth, *args, &block)
|
117
|
+
factory = Puppet::Pops::Binder::BindingsFactory
|
118
|
+
if factory.respond_to?(meth)
|
119
|
+
factory.send(meth, *args, &block)
|
120
|
+
else
|
121
|
+
super
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# A bindings builder for an AbstractBinding containing other AbstractBinding instances.
|
127
|
+
# @api public
|
128
|
+
class BindingsContainerBuilder < AbstractBuilder
|
129
|
+
|
130
|
+
# Adds an empty binding to the container, and returns a builder for it for further detailing.
|
131
|
+
# An optional block may be given which is evaluated using `instance_eval`.
|
132
|
+
# @return [BindingsBuilder] the builder for the created binding
|
133
|
+
# @api public
|
134
|
+
#
|
135
|
+
def bind(&block)
|
136
|
+
binding = Puppet::Pops::Binder::Bindings::Binding.new()
|
137
|
+
model.addBindings(binding)
|
138
|
+
builder = BindingsBuilder.new(binding)
|
139
|
+
builder.instance_eval(&block) if block_given?
|
140
|
+
builder
|
141
|
+
end
|
142
|
+
|
143
|
+
# Binds a multibind with the given identity where later, the looked up result contains all
|
144
|
+
# contributions to this key. An optional block may be given which is evaluated using `instance_eval`.
|
145
|
+
# @param id [String] the multibind's id used when adding contributions
|
146
|
+
# @return [MultibindingsBuilder] the builder for the created multibinding
|
147
|
+
# @api public
|
148
|
+
#
|
149
|
+
def multibind(id, &block)
|
150
|
+
binding = Puppet::Pops::Binder::Bindings::Multibinding.new()
|
151
|
+
binding.id = id
|
152
|
+
model.addBindings(binding)
|
153
|
+
builder = MultibindingsBuilder.new(binding)
|
154
|
+
builder.instance_eval(&block) if block_given?
|
155
|
+
builder
|
156
|
+
end
|
157
|
+
|
158
|
+
# Adds a categorized bindings to this container. Returns a BindingsContainerBuilder to allow adding
|
159
|
+
# bindings in the newly created container. An optional block may be given which is evaluated using `instance_eval`.
|
160
|
+
# @param categorization [String] the name of the categorization e.g. 'node'
|
161
|
+
# @param category_value [String] the value in that category e.g. 'kermit.example.com'
|
162
|
+
# @return [BindingsContainerBuilder] the builder for the created categorized bindings container
|
163
|
+
# @api public
|
164
|
+
#
|
165
|
+
def when_in_category(categorization, category_value, &block)
|
166
|
+
when_in_categories({categorization => category_value}, &block)
|
167
|
+
end
|
168
|
+
|
169
|
+
# Adds a categorized bindings to this container. Returns a BindingsContainerBuilder to allow adding
|
170
|
+
# bindings in the newly created container.
|
171
|
+
# The result is that a processed request must match all the given categorizations
|
172
|
+
# with the given values. An optional block may be given which is evaluated using `instance_eval`.
|
173
|
+
# @param categories_hash Hash[String, String] a hash with categorization and categorization value entries
|
174
|
+
# @return [BindingsContainerBuilder] the builder for the created categorized bindings container
|
175
|
+
# @api public
|
176
|
+
#
|
177
|
+
def when_in_categories(categories_hash, &block)
|
178
|
+
binding = Puppet::Pops::Binder::Bindings::CategorizedBindings.new()
|
179
|
+
categories_hash.each do |k,v|
|
180
|
+
pred = Puppet::Pops::Binder::Bindings::Category.new()
|
181
|
+
pred.categorization = k
|
182
|
+
pred.value = v
|
183
|
+
binding.addPredicates(pred)
|
184
|
+
end
|
185
|
+
model.addBindings(binding)
|
186
|
+
builder = BindingsContainerBuilder.new(binding)
|
187
|
+
builder.instance_eval(&block) if block_given?
|
188
|
+
builder
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Builds a Binding via convenience methods.
|
193
|
+
#
|
194
|
+
# @api public
|
195
|
+
#
|
196
|
+
class BindingsBuilder < AbstractBuilder
|
197
|
+
|
198
|
+
# @param binding [Puppet::Pops::Binder::Bindings::AbstractBinding] the binding to build.
|
199
|
+
# @api public
|
200
|
+
def initialize(binding)
|
201
|
+
super binding
|
202
|
+
data()
|
203
|
+
end
|
204
|
+
|
205
|
+
# Sets the name of the binding.
|
206
|
+
# @param name [String] the name to bind.
|
207
|
+
# @api public
|
208
|
+
def name(name)
|
209
|
+
model.name = name
|
210
|
+
self
|
211
|
+
end
|
212
|
+
|
213
|
+
# Same as {#name}, but reads better in certain combinations.
|
214
|
+
# @api public
|
215
|
+
alias_method :named, :name
|
216
|
+
|
217
|
+
# Sets the binding to be abstract (it must be overridden)
|
218
|
+
# @api public
|
219
|
+
def abstract
|
220
|
+
model.abstract = true
|
221
|
+
self
|
222
|
+
end
|
223
|
+
|
224
|
+
# Sets the binding to be override (it must override something)
|
225
|
+
# @api public
|
226
|
+
def override
|
227
|
+
model.override = true
|
228
|
+
self
|
229
|
+
end
|
230
|
+
|
231
|
+
# Makes the binding a multibind contribution to the given multibind id
|
232
|
+
# @param id [String] the multibind id to contribute this binding to
|
233
|
+
# @api public
|
234
|
+
def in_multibind(id)
|
235
|
+
model.multibind_id = id
|
236
|
+
self
|
237
|
+
end
|
238
|
+
|
239
|
+
# Sets the type of the binding to the given type.
|
240
|
+
# @note
|
241
|
+
# This is only needed if something other than the default type `Data` is wanted, or if the wanted type is
|
242
|
+
# not provided by one of the convenience methods {#array_of_data}, {#boolean}, {#float}, {#hash_of_data},
|
243
|
+
# {#integer}, {#literal}, {#pattern}, {#string}, or one of the collection methods {#array_of}, or {#hash_of}.
|
244
|
+
#
|
245
|
+
# To create a type, use the method {#type_factory}, to obtain the type.
|
246
|
+
# @example creating a Hash with Integer key and Array[Integer] element type
|
247
|
+
# tc = type_factory
|
248
|
+
# type(tc.hash(tc.array_of(tc.integer), tc.integer)
|
249
|
+
# @param type [Puppet::Pops::Types::PObjectType] the type to set for the binding
|
250
|
+
# @api public
|
251
|
+
#
|
252
|
+
def type(type)
|
253
|
+
model.type = type
|
254
|
+
self
|
255
|
+
end
|
256
|
+
|
257
|
+
# Sets the type of the binding to Integer.
|
258
|
+
# @return [Puppet::Pops::Types::PIntegerType] the type
|
259
|
+
# @api public
|
260
|
+
def integer()
|
261
|
+
type(T.integer())
|
262
|
+
end
|
263
|
+
|
264
|
+
# Sets the type of the binding to Float.
|
265
|
+
# @return [Puppet::Pops::Types::PFloatType] the type
|
266
|
+
# @api public
|
267
|
+
def float()
|
268
|
+
type(T.float())
|
269
|
+
end
|
270
|
+
|
271
|
+
# Sets the type of the binding to Boolean.
|
272
|
+
# @return [Puppet::Pops::Types::PBooleanType] the type
|
273
|
+
# @api public
|
274
|
+
def boolean()
|
275
|
+
type(T.boolean())
|
276
|
+
end
|
277
|
+
|
278
|
+
# Sets the type of the binding to String.
|
279
|
+
# @return [Puppet::Pops::Types::PStringType] the type
|
280
|
+
# @api public
|
281
|
+
def string()
|
282
|
+
type(T.string())
|
283
|
+
end
|
284
|
+
|
285
|
+
# Sets the type of the binding to Pattern.
|
286
|
+
# @return [Puppet::Pops::Types::PPatternType] the type
|
287
|
+
# @api public
|
288
|
+
def pattern()
|
289
|
+
type(T.pattern())
|
290
|
+
end
|
291
|
+
|
292
|
+
# Sets the type of the binding to the abstract type Literal.
|
293
|
+
# @return [Puppet::Pops::Types::PLiteralType] the type
|
294
|
+
# @api public
|
295
|
+
def literal()
|
296
|
+
type(T.literal())
|
297
|
+
end
|
298
|
+
|
299
|
+
# Sets the type of the binding to the abstract type Data.
|
300
|
+
# @return [Puppet::Pops::Types::PDataType] the type
|
301
|
+
# @api public
|
302
|
+
def data()
|
303
|
+
type(T.data())
|
304
|
+
end
|
305
|
+
|
306
|
+
# Sets the type of the binding to Array[Data].
|
307
|
+
# @return [Puppet::Pops::Types::PArrayType] the type
|
308
|
+
# @api public
|
309
|
+
def array_of_data()
|
310
|
+
type(T.array_of_data())
|
311
|
+
end
|
312
|
+
|
313
|
+
# Sets the type of the binding to Array[T], where T is given.
|
314
|
+
# @param t [Puppet::Pops::Types::PObjectType] the type of the elements of the array
|
315
|
+
# @return [Puppet::Pops::Types::PArrayType] the type
|
316
|
+
# @api public
|
317
|
+
def array_of(t)
|
318
|
+
type(T.array_of(t))
|
319
|
+
end
|
320
|
+
|
321
|
+
# Sets the type of the binding to Hash[Literal, Data].
|
322
|
+
# @return [Puppet::Pops::Types::PHashType] the type
|
323
|
+
# @api public
|
324
|
+
def hash_of_data()
|
325
|
+
type(T.hash_of_data())
|
326
|
+
end
|
327
|
+
|
328
|
+
# Sets type of the binding to `Hash[Literal, t]`.
|
329
|
+
# To also limit the key type, use {#type} and give it a fully specified
|
330
|
+
# hash using {#type_factory} and then `hash_of(value_type, key_type)`.
|
331
|
+
# @return [Puppet::Pops::Types::PHashType] the type
|
332
|
+
# @api public
|
333
|
+
def hash_of(t)
|
334
|
+
type(T.hash_of(t))
|
335
|
+
end
|
336
|
+
|
337
|
+
# Sets the type of the binding based on the given argument.
|
338
|
+
# @overload instance_of(t)
|
339
|
+
# The same as calling {#type} with `t`.
|
340
|
+
# @param t [Puppet::Pops::Types::PObjectType] the type
|
341
|
+
# @overload instance_of(o)
|
342
|
+
# Infers the type from the given Ruby object and sets that as the type - i.e. "set the type
|
343
|
+
# of the binding to be that of the given data object".
|
344
|
+
# @param o [Object] the object to infer the type from
|
345
|
+
# @overload instance_of(c)
|
346
|
+
# @param c [Class] the Class to base the type on.
|
347
|
+
# Sets the type based on the given ruby class. The result is one of the specific puppet types
|
348
|
+
# if the class can be represented by a specific type, or the open ended PRubyType otherwise.
|
349
|
+
# @overload instance_of(s)
|
350
|
+
# The same as using a class, but instead of giving a class instance, the class is expressed using its fully
|
351
|
+
# qualified name. This method of specifying the type allows late binding (the class does not have to be loaded
|
352
|
+
# before it can be used in a binding).
|
353
|
+
# @param s [String] the fully qualified classname to base the type on.
|
354
|
+
# @return the resulting type
|
355
|
+
# @api public
|
356
|
+
#
|
357
|
+
def instance_of(t)
|
358
|
+
type(T.type_of(t))
|
359
|
+
end
|
360
|
+
|
361
|
+
# Provides convenient access to the type factory.
|
362
|
+
# This is intended to be used when methods taking a type as argument i.e. {#type}, {#array_of}, {#hash_of}, and {#instance_of}.
|
363
|
+
# @note
|
364
|
+
# The type factory is also available via the constant {T}.
|
365
|
+
# @api public
|
366
|
+
def type_factory
|
367
|
+
Puppet::Pops::Types::TypeFactory
|
368
|
+
end
|
369
|
+
|
370
|
+
# Sets the binding's producer to a singleton producer, if given argument is a value, a literal producer is created for it.
|
371
|
+
# To create a producer producing an instance of a class with lazy loading of the class, use {#to_instance}.
|
372
|
+
#
|
373
|
+
# @overload to(a_literal)
|
374
|
+
# Sets a constant producer in the binding.
|
375
|
+
# @overload to(a_class, *args)
|
376
|
+
# Sets an Instantiating producer (producing an instance of the given class)
|
377
|
+
# @overload to(a_producer_descriptor)
|
378
|
+
# Sets the producer from the given producer descriptor
|
379
|
+
# @return [BindingsBuilder] self
|
380
|
+
# @api public
|
381
|
+
#
|
382
|
+
def to(producer, *args)
|
383
|
+
case producer
|
384
|
+
when Class
|
385
|
+
producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(producer.name, *args)
|
386
|
+
when Puppet::Pops::Model::Expression
|
387
|
+
producer = Puppet::Pops::Binder::BindingsFactory.evaluating_producer(producer)
|
388
|
+
when Puppet::Pops::Binder::Bindings::ProducerDescriptor
|
389
|
+
else
|
390
|
+
# If given producer is not a producer, create a literal producer
|
391
|
+
producer = Puppet::Pops::Binder::BindingsFactory.literal_producer(producer)
|
392
|
+
end
|
393
|
+
model.producer = producer
|
394
|
+
self
|
395
|
+
end
|
396
|
+
|
397
|
+
# Sets the binding's producer to a producer of an instance of given class (a String class name, or a Class instance).
|
398
|
+
# Use a string class name when lazy loading of the class is wanted.
|
399
|
+
#
|
400
|
+
# @overload to_instance(class_name, *args)
|
401
|
+
# @param class_name [String] the name of the class to instantiate
|
402
|
+
# @param args [Object] optional arguments to the constructor
|
403
|
+
# @overload to_instance(a_class)
|
404
|
+
# @param a_class [Class] the class to instantiate
|
405
|
+
# @param args [Object] optional arguments to the constructor
|
406
|
+
#
|
407
|
+
def to_instance(type, *args)
|
408
|
+
class_name = case type
|
409
|
+
when Class
|
410
|
+
type.name
|
411
|
+
when String
|
412
|
+
type
|
413
|
+
else
|
414
|
+
raise ArgumentError, "to_instance accepts String (a class name), or a Class.*args got: #{type.class}."
|
415
|
+
end
|
416
|
+
model.producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(class_name, *args)
|
417
|
+
end
|
418
|
+
|
419
|
+
# Sets the binding's producer to a singleton producer
|
420
|
+
# @overload to_producer(a_producer)
|
421
|
+
# Sets the producer to an instantiated producer. The resulting model can not be serialized as a consequence as there
|
422
|
+
# is no meta-model describing the specialized producer. Use this only in exceptional cases, or where there is never the
|
423
|
+
# need to serialize the model.
|
424
|
+
# @param a_producer [Puppet::Pops::Binder::Producers::Producer] an instantiated producer, not serializeable !
|
425
|
+
#
|
426
|
+
# @overload to_producer(a_class, *args)
|
427
|
+
# @param a_class [Class] the class to create an instance of
|
428
|
+
# @param args [Object] the arguments to the given class' new
|
429
|
+
#
|
430
|
+
# @overload to_producer(a_producer_descriptor)
|
431
|
+
# @param a_producer_descriptor [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a descriptor
|
432
|
+
# producing Puppet::Pops::Binder::Producers::Producer
|
433
|
+
#
|
434
|
+
# @api public
|
435
|
+
#
|
436
|
+
def to_producer(producer, *args)
|
437
|
+
case producer
|
438
|
+
when Class
|
439
|
+
producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(producer.name, *args)
|
440
|
+
when Puppet::Pops::Binder::Bindings::ProducerDescriptor
|
441
|
+
when Puppet::Pops::Binder::Producers::Producer
|
442
|
+
# a custom producer instance
|
443
|
+
producer = Puppet::Pops::Binder::BindingsFactory.literal_producer(producer)
|
444
|
+
else
|
445
|
+
raise ArgumentError, "Given producer argument is none of a producer descriptor, a class, or a producer"
|
446
|
+
end
|
447
|
+
metaproducer = Puppet::Pops::Binder::BindingsFactory.producer_producer(producer)
|
448
|
+
model.producer = metaproducer
|
449
|
+
self
|
450
|
+
end
|
451
|
+
|
452
|
+
# Sets the binding's producer to a series of producers.
|
453
|
+
# Use this when you want to produce a different producer on each request for a producer
|
454
|
+
#
|
455
|
+
# @overload to_producer(a_producer)
|
456
|
+
# Sets the producer to an instantiated producer. The resulting model can not be serialized as a consequence as there
|
457
|
+
# is no meta-model describing the specialized producer. Use this only in exceptional cases, or where there is never the
|
458
|
+
# need to serialize the model.
|
459
|
+
# @param a_producer [Puppet::Pops::Binder::Producers::Producer] an instantiated producer, not serializeable !
|
460
|
+
#
|
461
|
+
# @overload to_producer(a_class, *args)
|
462
|
+
# @param a_class [Class] the class to create an instance of
|
463
|
+
# @param args [Object] the arguments to the given class' new
|
464
|
+
#
|
465
|
+
# @overload to_producer(a_producer_descriptor)
|
466
|
+
# @param a_producer_descriptor [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a descriptor
|
467
|
+
# producing Puppet::Pops::Binder::Producers::Producer
|
468
|
+
#
|
469
|
+
# @api public
|
470
|
+
#
|
471
|
+
def to_producer_series(producer, *args)
|
472
|
+
case producer
|
473
|
+
when Class
|
474
|
+
producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(producer.name, *args)
|
475
|
+
when Puppet::Pops::Binder::Bindings::ProducerDescriptor
|
476
|
+
when Puppet::Pops::Binder::Producers::Producer
|
477
|
+
# a custom producer instance
|
478
|
+
producer = Puppet::Pops::Binder::BindingsFactory.literal_producer(producer)
|
479
|
+
else
|
480
|
+
raise ArgumentError, "Given producer argument is none of a producer descriptor, a class, or a producer"
|
481
|
+
end
|
482
|
+
non_caching = Puppet::Pops::Binder::Bindings::NonCachingProducerDescriptor.new()
|
483
|
+
non_caching.producer = producer
|
484
|
+
metaproducer = Puppet::Pops::Binder::BindingsFactory.producer_producer(non_caching)
|
485
|
+
|
486
|
+
non_caching = Puppet::Pops::Binder::Bindings::NonCachingProducerDescriptor.new()
|
487
|
+
non_caching.producer = metaproducer
|
488
|
+
|
489
|
+
model.producer = non_caching
|
490
|
+
self
|
491
|
+
end
|
492
|
+
|
493
|
+
# Sets the binding's producer to a "non singleton" producer (each call to produce produces a new instance/copy).
|
494
|
+
# @overload to_series_of(a_literal)
|
495
|
+
# a constant producer
|
496
|
+
# @overload to_series_of(a_class, *args)
|
497
|
+
# Instantiating producer
|
498
|
+
# @overload to_series_of(a_producer_descriptor)
|
499
|
+
# a given producer
|
500
|
+
#
|
501
|
+
# @api public
|
502
|
+
#
|
503
|
+
def to_series_of(producer, *args)
|
504
|
+
case producer
|
505
|
+
when Class
|
506
|
+
producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(producer.name, *args)
|
507
|
+
when Puppet::Pops::Binder::Bindings::ProducerDescriptor
|
508
|
+
else
|
509
|
+
# If given producer is not a producer, create a literal producer
|
510
|
+
producer = Puppet::Pops::Binder::BindingsFactory.literal_producer(producer)
|
511
|
+
end
|
512
|
+
non_caching = Puppet::Pops::Binder::Bindings::NonCachingProducerDescriptor.new()
|
513
|
+
non_caching.producer = producer
|
514
|
+
model.producer = non_caching
|
515
|
+
self
|
516
|
+
end
|
517
|
+
|
518
|
+
# Sets the binding's producer to one that performs a lookup of another key
|
519
|
+
# @overload to_lookup_of(type, name)
|
520
|
+
# @overload to_lookup_of(name)
|
521
|
+
# @api public
|
522
|
+
#
|
523
|
+
def to_lookup_of(type, name=nil)
|
524
|
+
unless name
|
525
|
+
name = type
|
526
|
+
type = Puppet::Pops::Types::TypeFactory.data()
|
527
|
+
end
|
528
|
+
model.producer = Puppet::Pops::Binder::BindingsFactory.lookup_producer(type, name)
|
529
|
+
self
|
530
|
+
end
|
531
|
+
|
532
|
+
# Sets the binding's producer to a one that performs a lookup of another key and they applies hash lookup on
|
533
|
+
# the result.
|
534
|
+
#
|
535
|
+
# @overload to_lookup_of(type, name)
|
536
|
+
# @overload to_lookup_of(name)
|
537
|
+
# @api public
|
538
|
+
#
|
539
|
+
def to_hash_lookup_of(type, name, key)
|
540
|
+
model.producer = Puppet::Pops::Binder::BindingsFactory.hash_lookup_producer(type, name, key)
|
541
|
+
self
|
542
|
+
end
|
543
|
+
|
544
|
+
# Sets the binding's producer to one that produces the first found lookup of another key
|
545
|
+
# @param list_of_lookups [Array] array of arrays [type name], or just name (implies data)
|
546
|
+
# @example
|
547
|
+
# binder.bind().name('foo').to_first_found('fee', 'fum', 'extended-bar')
|
548
|
+
# binder.bind().name('foo').to_first_found(
|
549
|
+
# [T.ruby(ThisClass), 'fee'],
|
550
|
+
# [T.ruby(ThatClass), 'fum'],
|
551
|
+
# 'extended-bar')
|
552
|
+
# @api public
|
553
|
+
#
|
554
|
+
def to_first_found(*list_of_lookups)
|
555
|
+
producers = list_of_lookups.collect do |entry|
|
556
|
+
if entry.is_a?(Array)
|
557
|
+
case entry.size
|
558
|
+
when 2
|
559
|
+
Puppet::Pops::Binder::BindingsFactory.lookup_producer(entry[0], entry[1])
|
560
|
+
when 1
|
561
|
+
Puppet::Pops::Binder::BindingsFactory.lookup_producer(Puppet::Pops::Types::TypeFactory.data(), entry[0])
|
562
|
+
else
|
563
|
+
raise ArgumentError, "Not an array of [type, name], name, or [name]"
|
564
|
+
end
|
565
|
+
else
|
566
|
+
Puppet::Pops::Binder::BindingsFactory.lookup_producer(T.data(), entry)
|
567
|
+
end
|
568
|
+
end
|
569
|
+
model.producer = Puppet::Pops::Binder::BindingsFactory.first_found_producer(*producers)
|
570
|
+
self
|
571
|
+
end
|
572
|
+
|
573
|
+
# Sets options to the producer.
|
574
|
+
# See the respective producer for the options it supports. All producers supports the option `:transformer`, a
|
575
|
+
# puppet or ruby lambda that is evaluated with the produced result as an argument. The ruby lambda gets scope and
|
576
|
+
# value as arguments.
|
577
|
+
# @note
|
578
|
+
# A Ruby lambda is not cross platform safe. Use a puppet lambda if you want a bindings model that is.
|
579
|
+
#
|
580
|
+
# @api public
|
581
|
+
def producer_options(options)
|
582
|
+
options.each do |k, v|
|
583
|
+
arg = Puppet::Pops::Binder::Bindings::NamedArgument.new()
|
584
|
+
arg.name = k.to_s
|
585
|
+
arg.value = v
|
586
|
+
model.addProducer_args(arg)
|
587
|
+
end
|
588
|
+
self
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
# A builder specialized for multibind - checks that type is Array or Hash based. A new builder sets the
|
593
|
+
# multibinding to be of type Hash[Data].
|
594
|
+
#
|
595
|
+
# @api public
|
596
|
+
class MultibindingsBuilder < BindingsBuilder
|
597
|
+
# Constraints type to be one of {Puppet::Pops::Types::PArrayType PArrayType}, or {Puppet::Pops::Types::PHashType PHashType}.
|
598
|
+
# @raise [ArgumentError] if type constraint is not met.
|
599
|
+
# @api public
|
600
|
+
def type(type)
|
601
|
+
unless type.class == Puppet::Pops::Types::PArrayType || type.class == Puppet::Pops::Types::PHashType
|
602
|
+
raise ArgumentError, "Wrong type; only PArrayType, or PHashType allowed, got '#{type.to_s}'"
|
603
|
+
end
|
604
|
+
model.type = type
|
605
|
+
self
|
606
|
+
end
|
607
|
+
|
608
|
+
# Overrides the default implementation that will raise an exception as a multibind requires a hash type.
|
609
|
+
# Thus, if nothing else is requested, a multibind will be configured as Hash[Data].
|
610
|
+
#
|
611
|
+
def data()
|
612
|
+
hash_of_data()
|
613
|
+
end
|
614
|
+
end
|
615
|
+
|
616
|
+
# Produces a ContributedBindings.
|
617
|
+
# A ContributedBindings is used by bindings providers to return a set of named bindings.
|
618
|
+
#
|
619
|
+
# @param name [String] the name of the contributed bindings (for human use in messages/logs only)
|
620
|
+
# @param named_bindings [Puppet::Pops::Binder::Bindings::NamedBindings, Array<Puppet::Pops::Binder::Bindings::NamedBindings>] the
|
621
|
+
# named bindings to include
|
622
|
+
# @param effective_categories [Puppet::Pops::Binder::Bindings::EffectiveCategories] the contributors opinion about categorization
|
623
|
+
# this is used to ensure consistent use of categories.
|
624
|
+
#
|
625
|
+
def self.contributed_bindings(name, named_bindings, effective_categories)
|
626
|
+
cb = Puppet::Pops::Binder::Bindings::ContributedBindings.new()
|
627
|
+
cb.name = name
|
628
|
+
named_bindings = [named_bindings] unless named_bindings.is_a?(Array)
|
629
|
+
named_bindings.each {|b| cb.addBindings(b) }
|
630
|
+
cb.effective_categories = effective_categories
|
631
|
+
cb
|
632
|
+
end
|
633
|
+
|
634
|
+
# Creates a named binding container, the top bindings model object.
|
635
|
+
# A NamedBindings is typically produced by a bindings provider.
|
636
|
+
#
|
637
|
+
# The created container is wrapped in a BindingsContainerBuilder for further detailing.
|
638
|
+
# Unwrap the built result when done.
|
639
|
+
# @api public
|
640
|
+
#
|
641
|
+
def self.named_bindings(name, &block)
|
642
|
+
binding = Puppet::Pops::Binder::Bindings::NamedBindings.new()
|
643
|
+
binding.name = name
|
644
|
+
builder = BindingsContainerBuilder.new(binding)
|
645
|
+
builder.instance_eval(&block) if block_given?
|
646
|
+
builder
|
647
|
+
end
|
648
|
+
|
649
|
+
# This variant of {named_bindings} evaluates the given block as a method on an anonymous class,
|
650
|
+
# thus, if the block defines methods or do something with the class itself, this does not pollute
|
651
|
+
# the base class (BindingsContainerBuilder).
|
652
|
+
# @api private
|
653
|
+
#
|
654
|
+
def self.safe_named_bindings(name, scope, &block)
|
655
|
+
binding = Puppet::Pops::Binder::Bindings::NamedBindings.new()
|
656
|
+
binding.name = name
|
657
|
+
anon = Class.new(BindingsContainerBuilder) do
|
658
|
+
def initialize(b)
|
659
|
+
super b
|
660
|
+
end
|
661
|
+
end
|
662
|
+
anon.send(:define_method, :_produce, block)
|
663
|
+
builder = anon.new(binding)
|
664
|
+
case block.arity
|
665
|
+
when 0
|
666
|
+
builder._produce()
|
667
|
+
when 1
|
668
|
+
builder._produce(scope)
|
669
|
+
end
|
670
|
+
builder
|
671
|
+
end
|
672
|
+
|
673
|
+
# Creates a literal/constant producer
|
674
|
+
# @param value [Object] the value to produce
|
675
|
+
# @return [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a producer description
|
676
|
+
# @api public
|
677
|
+
#
|
678
|
+
def self.literal_producer(value)
|
679
|
+
producer = Puppet::Pops::Binder::Bindings::ConstantProducerDescriptor.new()
|
680
|
+
producer.value = value
|
681
|
+
producer
|
682
|
+
end
|
683
|
+
|
684
|
+
# Creates a non caching producer
|
685
|
+
# @param producer [Puppet::Pops::Binder::Bindings::Producer] the producer to make non caching
|
686
|
+
# @return [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a producer description
|
687
|
+
# @api public
|
688
|
+
#
|
689
|
+
def self.non_caching_producer(producer)
|
690
|
+
p = Puppet::Pops::Binder::Bindings::NonCachingProducerDescriptor.new()
|
691
|
+
p.producer = producer
|
692
|
+
p
|
693
|
+
end
|
694
|
+
|
695
|
+
# Creates a producer producer
|
696
|
+
# @param producer [Puppet::Pops::Binder::Bindings::Producer] a producer producing a Producer.
|
697
|
+
# @return [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a producer description
|
698
|
+
# @api public
|
699
|
+
#
|
700
|
+
def self.producer_producer(producer)
|
701
|
+
p = Puppet::Pops::Binder::Bindings::ProducerProducerDescriptor.new()
|
702
|
+
p.producer = producer
|
703
|
+
p
|
704
|
+
end
|
705
|
+
|
706
|
+
# Creates an instance producer
|
707
|
+
# An instance producer creates a new instance of a class.
|
708
|
+
# If the class implements the class method `inject` this method is called instead of `new` to allow further lookups
|
709
|
+
# to take place. This is referred to as *assisted inject*. If the class method `inject` is missing, the regular `new` method
|
710
|
+
# is called.
|
711
|
+
#
|
712
|
+
# @param class_name [String] the name of the class
|
713
|
+
# @param args[Object] arguments to the class' `new` method.
|
714
|
+
# @return [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a producer description
|
715
|
+
# @api public
|
716
|
+
#
|
717
|
+
def self.instance_producer(class_name, *args)
|
718
|
+
p = Puppet::Pops::Binder::Bindings::InstanceProducerDescriptor.new()
|
719
|
+
p.class_name = class_name
|
720
|
+
args.each {|a| p.addArguments(a) }
|
721
|
+
p
|
722
|
+
end
|
723
|
+
|
724
|
+
# Creates a Producer that looks up a value.
|
725
|
+
# @param type [Puppet::Pops::Types::PObjectType] the type to lookup
|
726
|
+
# @param name [String] the name to lookup
|
727
|
+
# @return [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a producer description
|
728
|
+
# @api public
|
729
|
+
def self.lookup_producer(type, name)
|
730
|
+
p = Puppet::Pops::Binder::Bindings::LookupProducerDescriptor.new()
|
731
|
+
p.type = type
|
732
|
+
p.name = name
|
733
|
+
p
|
734
|
+
end
|
735
|
+
|
736
|
+
# Creates a Hash lookup producer that looks up a hash value, and then a key in the hash.
|
737
|
+
#
|
738
|
+
# @return [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a producer description
|
739
|
+
# @param type [Puppet::Pops::Types::PObjectType] the type to lookup (i.e. a Hash of some key/value type).
|
740
|
+
# @param name [String] the name to lookup
|
741
|
+
# @param key [Object] the key to lookup in the looked up hash (type should comply with given key type).
|
742
|
+
# @api public
|
743
|
+
#
|
744
|
+
def self.hash_lookup_producer(type, name, key)
|
745
|
+
p = Puppet::Pops::Binder::Bindings::HashLookupProducerDescriptor.new()
|
746
|
+
p.type = type
|
747
|
+
p.name = name
|
748
|
+
p.key = key
|
749
|
+
p
|
750
|
+
end
|
751
|
+
|
752
|
+
# Creates a first-found producer that looks up from a given series of keys. The first found looked up
|
753
|
+
# value will be produced.
|
754
|
+
# @param producers [Array<Puppet::Pops::Binder::Bindings::ProducerDescriptor>] the producers to consult in given order
|
755
|
+
# @return [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a producer descriptor
|
756
|
+
# @api public
|
757
|
+
def self.first_found_producer(*producers)
|
758
|
+
p = Puppet::Pops::Binder::Bindings::FirstFoundProducerDescriptor.new()
|
759
|
+
producers.each {|p2| p.addProducers(p2) }
|
760
|
+
p
|
761
|
+
end
|
762
|
+
|
763
|
+
# Creates an evaluating producer that evaluates a puppet expression.
|
764
|
+
# A puppet expression is most conveniently created by using the {Puppet::Pops::Parser::EvaluatingParser EvaluatingParser} as it performs
|
765
|
+
# all set up and validation of the parsed source. Two convenience methods are used to parse an expression, or parse a ruby string
|
766
|
+
# as a puppet string. See methods {puppet_expression}, {puppet_string} and {parser} for more information.
|
767
|
+
#
|
768
|
+
# @example producing a puppet expression
|
769
|
+
# expr = puppet_string("Interpolated $fqdn", __FILE__)
|
770
|
+
#
|
771
|
+
# @param expression [Puppet::Pops::Model::Expression] a puppet DSL expression as producer by the eparser.
|
772
|
+
# @return [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a producer descriptor
|
773
|
+
# @api public
|
774
|
+
#
|
775
|
+
def self.evaluating_producer(expression)
|
776
|
+
p = Puppet::Pops::Binder::Bindings::EvaluatingProducerDescriptor.new()
|
777
|
+
p.expression = expression
|
778
|
+
p
|
779
|
+
end
|
780
|
+
|
781
|
+
# Creates an EffectiveCategories from a list of tuples `[categorization category ...]`, or `[[categorization category] ...]`
|
782
|
+
# This method is used by backends to create a model of the effective categories.
|
783
|
+
# @api public
|
784
|
+
#
|
785
|
+
def self.categories(tuple_array)
|
786
|
+
result = Puppet::Pops::Binder::Bindings::EffectiveCategories.new()
|
787
|
+
tuple_array.flatten.each_slice(2) do |c|
|
788
|
+
cat = Puppet::Pops::Binder::Bindings::Category.new()
|
789
|
+
cat.categorization = c[0]
|
790
|
+
cat.value = c[1]
|
791
|
+
result.addCategories(cat)
|
792
|
+
end
|
793
|
+
result
|
794
|
+
end
|
795
|
+
|
796
|
+
# Creates a NamedLayer. This is used by the bindings system to create a model of the layers.
|
797
|
+
#
|
798
|
+
# @api public
|
799
|
+
#
|
800
|
+
def self.named_layer(name, *bindings)
|
801
|
+
result = Puppet::Pops::Binder::Bindings::NamedLayer.new()
|
802
|
+
result.name = name
|
803
|
+
bindings.each { |b| result.addBindings(b) }
|
804
|
+
result
|
805
|
+
end
|
806
|
+
|
807
|
+
# Create a LayeredBindings. This is used by the bindings system to create a model of all given layers.
|
808
|
+
# @param named_layers [Puppet::Pops::Binder::Bindings::NamedLayer] one or more named layers
|
809
|
+
# @return [Puppet::Pops::Binder::Bindings::LayeredBindings] the constructed layered bindings.
|
810
|
+
# @api public
|
811
|
+
#
|
812
|
+
def self.layered_bindings(*named_layers)
|
813
|
+
result = Puppet::Pops::Binder::Bindings::LayeredBindings.new()
|
814
|
+
named_layers.each {|b| result.addLayers(b) }
|
815
|
+
result
|
816
|
+
end
|
817
|
+
|
818
|
+
# @return [Puppet::Pops::Parser::EvaluatingParser] a parser for puppet expressions
|
819
|
+
def self.parser
|
820
|
+
@parser ||= Puppet::Pops::Parser::EvaluatingParser.new()
|
821
|
+
end
|
822
|
+
|
823
|
+
# Parses and produces a puppet expression from the given string.
|
824
|
+
# @param string [String] puppet source e.g. "1 + 2"
|
825
|
+
# @param source_file [String] the source location, typically `__File__`
|
826
|
+
# @return [Puppet::Pops::Model::Expression] an expression (that can be bound)
|
827
|
+
# @api public
|
828
|
+
#
|
829
|
+
def self.puppet_expression(string, source_file)
|
830
|
+
parser.parse_string(string, source_file).current
|
831
|
+
end
|
832
|
+
|
833
|
+
# Parses and produces a puppet string expression from the given string.
|
834
|
+
# The string will automatically be quoted and special characters escaped.
|
835
|
+
# As an example if given the (ruby) string "Hi\nMary" it is transformed to
|
836
|
+
# the puppet string (illustrated with a ruby string) "\"Hi\\nMary\”" before being
|
837
|
+
# parsed.
|
838
|
+
#
|
839
|
+
# @param string [String] puppet source e.g. "On node $!{fqdn}"
|
840
|
+
# @param source_file [String] the source location, typically `__File__`
|
841
|
+
# @return [Puppet::Pops::Model::Expression] an expression (that can be bound)
|
842
|
+
# @api public
|
843
|
+
#
|
844
|
+
def self.puppet_string(string, source_file)
|
845
|
+
parser.parse_string(parser.quote(string), source_file).current
|
846
|
+
end
|
847
|
+
end
|