module Puppet::Pops::Lookup::LocationResolver
Helper methods to resolve interpolated locations
@api private
Public Instance Methods
# File lib/puppet/pops/lookup/location_resolver.rb 41 def expand_globs(datadir, declared_globs, lookup_invocation) 42 declared_globs.map do |declared_glob| 43 glob = datadir + interpolate(declared_glob, lookup_invocation, false) 44 Pathname.glob(glob).reject { |path| path.directory? }.map { |path| ResolvedLocation.new(glob.to_s, path, true) } 45 end.flatten 46 end
# File lib/puppet/pops/lookup/location_resolver.rb 76 def expand_mapped_paths(datadir, mapped_path_triplet, lookup_invocation) 77 # The scope interpolation method is used directly to avoid unnecessary parsing of the string that otherwise 78 # would need to be generated 79 mapped_vars = interpolate_method(:scope).call(mapped_path_triplet[0], lookup_invocation, 'mapped_path[0]') 80 81 # No paths here unless the scope lookup returned something 82 return EMPTY_ARRAY if mapped_vars.nil? || mapped_vars.empty? 83 84 mapped_vars = [mapped_vars] if mapped_vars.is_a?(String) 85 var_key = mapped_path_triplet[1] 86 template = mapped_path_triplet[2] 87 scope = lookup_invocation.scope 88 lookup_invocation.with_local_memory_eluding(var_key) do 89 mapped_vars.map do |var| 90 # Need to use parent lookup invocation to avoid adding 'var' to the set of variables to track for changes. The 91 # variable that 'var' stems from is added above. 92 path = scope.with_local_scope(var_key => var) { datadir + interpolate(template, lookup_invocation, false) } 93 ResolvedLocation.new(template, path, path.exist?) 94 end 95 end 96 end
@param declared_uris [Array<String>] paths as found in declaration. May contain interpolation expressions @param lookup_invocation [Puppet::Pops::Lookup::Invocation] The current lookup invocation @return [Array<ResolvedLocation>] Array of resolved paths
# File lib/puppet/pops/lookup/location_resolver.rb 69 def expand_uris(declared_uris, lookup_invocation) 70 declared_uris.map do |declared_uri| 71 uri = URI(interpolate(declared_uri, lookup_invocation, false)) 72 ResolvedLocation.new(declared_uri, uri, true) 73 end 74 end
@param datadir [Pathname] The base when creating absolute paths @param declared_paths [Array<String>] paths as found in declaration. May contain interpolation expressions @param lookup_invocation [Puppet::Pops::Lookup::Invocation] The current lookup invocation @param is_default_config [Boolean] `true` if this is the default config and non-existent paths should be excluded @param extension [String] Required extension such as '.yaml' or '.json'. Use only if paths without extension can be expected @return [Array<ResolvedLocation>] Array of resolved paths
# File lib/puppet/pops/lookup/location_resolver.rb 54 def resolve_paths(datadir, declared_paths, lookup_invocation, is_default_config, extension = nil) 55 result = [] 56 declared_paths.each do |declared_path| 57 path = interpolate(declared_path, lookup_invocation, false) 58 path += extension unless extension.nil? || path.end_with?(extension) 59 path = datadir + path 60 path_exists = path.exist? 61 result << ResolvedLocation.new(declared_path, path, path_exists) unless is_default_config && !path_exists 62 end 63 result 64 end