Class: Puppet::Pops::Binder::SchemeHandler::ModuleHieraScheme
- Inherits:
-
Puppetx::Puppet::BindingsSchemeHandler
- Object
- Puppetx::Puppet::BindingsSchemeHandler
- Puppet::Pops::Binder::SchemeHandler::ModuleHieraScheme
- Defined in:
- lib/puppet/pops/binder/scheme_handler/module_hiera_scheme.rb
Overview
The module-hiera: scheme uses the path to denote a directory relative to a module root The path starts with the name of the module, or ‘*’ to denote *any module*.
Instance Method Summary collapse
-
#contributed_bindings(uri, scope, composer) ⇒ Object
(Puppetx::Puppet::BindingsSchemeHandler.contributed_bindings).
-
#expand_excluded(uri, composer) ⇒ Array<URI>
Expands URIs with wildcards and checks optionality.
-
#expand_included(uri, composer) ⇒ Array<URI>
Expands URIs with wildcards and checks optionality.
Methods inherited from Puppetx::Puppet::BindingsSchemeHandler
Instance Method Details
#contributed_bindings(uri, scope, composer) ⇒ Object
(Puppetx::Puppet::BindingsSchemeHandler.contributed_bindings)
13 14 15 16 17 18 19 |
# File 'lib/puppet/pops/binder/scheme_handler/module_hiera_scheme.rb', line 13 def contributed_bindings(uri, scope, composer) split_path = uri.path.split('/') name = split_path[1] mod = composer.name_to_module[name] provider = Puppet::Pops::Binder::Hiera2::BindingsProvider.new(uri.to_s, File.join(mod.path, split_path[ 2..-1 ]), composer.acceptor) provider.load_bindings(scope) end |
#expand_excluded(uri, composer) ⇒ Array<URI>
Expands URIs with wildcards and checks optionality.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/puppet/pops/binder/scheme_handler/module_hiera_scheme.rb', line 67 def (uri, composer) result = [] split_path = uri.path.split('/') if split_path.size > 1 && split_path[-1].empty? split_path.delete_at(-1) end # 0 = "", since a URI with a path must start with '/' # 1 = '*' or the module name case split_path[ 1 ] when '*' # create new URIs, one per module name that has a hiera.yaml file relative to its root composer.name_to_module.each_pair do | name, mod | path_parts =["", mod.name] + split_path[2..-1] result << URI.parse('module-hiera:'+File.join(path_parts)) end when nil raise ArgumentError, "Bad bindings uri, the #{uri} has neither module name or wildcard '*' in its first path position" else # create a clean copy (get rid of optional, fragments etc. and a trailing "/") result << URI.parse('module-hiera:' + File.join(split_path)) end result end |
#expand_included(uri, composer) ⇒ Array<URI>
Expands URIs with wildcards and checks optionality.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/puppet/pops/binder/scheme_handler/module_hiera_scheme.rb', line 26 def (uri, composer) result = [] split_path = uri.path.split('/') if split_path.size > 1 && split_path[-1].empty? split_path.delete_at(-1) end # 0 = "", since a URI with a path must start with '/' # 1 = '*' or the module name case split_path[ 1 ] when '*' # create new URIs, one per module name that has a hiera.yaml file relative to its root composer.name_to_module.each_pair do | name, mod | if Puppet::FileSystem::File.exist?(File.join(mod.path, split_path[ 2..-1 ], 'hiera.yaml' )) path_parts =["", name] + split_path[2..-1] result << URI.parse('module-hiera:'+File.join(path_parts)) end end when nil raise ArgumentError, "Bad bindings uri, the #{uri} has neither module name or wildcard '*' in its first path position" else # If uri has query that is empty, or the text 'optional' skip this uri if it does not exist if query = uri.query() if query == '' || query == 'optional' if Puppet::FileSystem::File.exist?(File.join(mod.path, split_path[ 2..-1 ], 'hiera.yaml' )) result << URI.parse('module-hiera:' + uri.path) end end else # assume it exists (do not give error since it may be excluded later) result << URI.parse('module-hiera:' + File.join(split_path)) end end result end |