Class: Puppet::Bindings
- Extended by:
- Enumerable
- Defined in:
- lib/puppet/bindings.rb
Overview
This class allows registration of named bindings that are later contributed to a layer via a binding scheme.
The intended use is for a .rb file to be placed in confdir’s or module’s ‘lib/bindings` directory structure, with a name corresponding to the symbolic bindings name.
Here are two equivalent examples, the first using chained methods (which is compact for simple cases), and the second which uses a block.
If access is needed to the scope, this can be declared as a block parameter. If late evaluation is wanted, this can be achieved by binding a puppet expression. It is allowed to define methods in the block given to ‘newbindings`, these can be used when producing bindings. (Care should naturally be taken to not override any of the already defined methods). For all details see Pops::Binder::BindingsFactory, which is used behind the scenes.
Defined Under Namespace
Classes: NamedBindingsAdapter
Constant Summary collapse
- Environment =
Puppet::Node::Environment
Class Method Summary collapse
- .[](name) ⇒ Object
-
.each ⇒ Object
Supports Enumerable iteration (k,v) over the named bindings hash.
-
.get(name) ⇒ Proc, Puppet::Pops::Binder::Bindings::NamedBindings
Returns the named bindings with the given name, or nil if no such bindings have been registered.
-
.newbindings(name, &block) ⇒ Object
Constructs and registers a NamedBindings that later can be contributed to a bindings layer in a bindings configuration via a URI.
-
.register(named_bindings) ⇒ Object
Registers a named_binding under its name.
- .register_proc(name, block) ⇒ Object
- .resolve(scope, name) ⇒ Object
Methods included from Enumerable
Class Method Details
.[](name) ⇒ Object
109 110 111 |
# File 'lib/puppet/bindings.rb', line 109 def self.[](name) get(name) end |
.each ⇒ Object
Supports Enumerable iteration (k,v) over the named bindings hash.
114 115 116 117 |
# File 'lib/puppet/bindings.rb', line 114 def self.each adapter = NamedBindingsAdapter.adapt(Puppet.lookup(:current_environment)) adapter.each_pair {|k,v| yield k,v } end |
.get(name) ⇒ Proc, Puppet::Pops::Binder::Bindings::NamedBindings
Returns the named bindings with the given name, or nil if no such bindings have been registered.
104 105 106 107 |
# File 'lib/puppet/bindings.rb', line 104 def self.get(name) adapter = NamedBindingsAdapter.adapt(Puppet.lookup(:current_environment)) adapter[name] end |
.newbindings(name, &block) ⇒ Object
Constructs and registers a NamedBindings that later can be contributed to a bindings layer in a bindings configuration via a URI. The name is symbolic, fully qualified with module name, and at least one more qualifying name (where the name ‘default` is used in the default bindings configuration.
The given block is called with a ‘self` bound to an instance of Pops::Binder::BindingsFactory::BindingsContainerBuilder which most notably has a `#bind` method which it turn calls a block bound to an instance of Pops::Binder::BindingsFactory::BindingsBuilder. Depending on the use-case a direct chaining method calls or nested blocks may be used.
The block form is more suitable for longer, more complex forms of bindings.
72 73 74 |
# File 'lib/puppet/bindings.rb', line 72 def self.newbindings(name, &block) register_proc(name, block) end |
.register(named_bindings) ⇒ Object
Registers a named_binding under its name
85 86 87 88 |
# File 'lib/puppet/bindings.rb', line 85 def self.register(named_bindings) adapter = NamedBindingsAdapter.adapt(Puppet.lookup(:current_environment)) adapter[named_bindings.name] = named_bindings end |
.register_proc(name, block) ⇒ Object
76 77 78 79 |
# File 'lib/puppet/bindings.rb', line 76 def self.register_proc(name, block) adapter = NamedBindingsAdapter.adapt(Puppet.lookup(:current_environment)) adapter[name] = block end |
.resolve(scope, name) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/puppet/bindings.rb', line 90 def self.resolve(scope, name) entry = get(name) return entry unless entry.is_a?(Proc) named_bindings = Puppet::Pops::Binder::BindingsFactory.safe_named_bindings(name, scope, &entry).model adapter = NamedBindingsAdapter.adapt(Puppet.lookup(:current_environment)) adapter[named_bindings.name] = named_bindings named_bindings end |