module Puppet::Pops::Lookup::LocationResolver

Helper methods to resolve interpolated locations

@api private

Public Instance Methods

expand_globs(datadir, declared_globs, lookup_invocation) click to toggle source
   # File lib/puppet/pops/lookup/location_resolver.rb
42 def expand_globs(datadir, declared_globs, lookup_invocation)
43   declared_globs.map do |declared_glob|
44     glob = datadir + interpolate(declared_glob, lookup_invocation, false)
45     Pathname.glob(glob).reject { |path| path.directory? }.map { |path| ResolvedLocation.new(glob.to_s, path, true) }
46   end.flatten
47 end
expand_mapped_paths(datadir, mapped_path_triplet, lookup_invocation) click to toggle source
   # File lib/puppet/pops/lookup/location_resolver.rb
77 def expand_mapped_paths(datadir, mapped_path_triplet, lookup_invocation)
78   # The scope interpolation method is used directly to avoid unnecessary parsing of the string that otherwise
79   # would need to be generated
80   mapped_vars = interpolate_method(:scope).call(mapped_path_triplet[0], lookup_invocation, 'mapped_path[0]')
81 
82   # No paths here unless the scope lookup returned something
83   return EMPTY_ARRAY if mapped_vars.nil? || mapped_vars.empty?
84 
85   mapped_vars = [mapped_vars] if mapped_vars.is_a?(String)
86   var_key = mapped_path_triplet[1]
87   template = mapped_path_triplet[2]
88   scope = lookup_invocation.scope
89   lookup_invocation.with_local_memory_eluding(var_key) do
90     mapped_vars.map do |var|
91       # Need to use parent lookup invocation to avoid adding 'var' to the set of variables to track for changes. The
92       # variable that 'var' stems from is added above.
93       path = scope.with_local_scope(var_key => var) {  datadir + interpolate(template, lookup_invocation, false) }
94       ResolvedLocation.new(template, path, path.exist?)
95     end
96   end
97 end
expand_uris(declared_uris, lookup_invocation) click to toggle source

@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
70 def expand_uris(declared_uris, lookup_invocation)
71   declared_uris.map do |declared_uri|
72     uri = URI(interpolate(declared_uri, lookup_invocation, false))
73     ResolvedLocation.new(declared_uri, uri, true)
74   end
75 end
resolve_paths(datadir, declared_paths, lookup_invocation, is_default_config, extension = nil) click to toggle source

@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
55 def resolve_paths(datadir, declared_paths, lookup_invocation, is_default_config, extension = nil)
56   result = []
57   declared_paths.each do |declared_path|
58     path = interpolate(declared_path, lookup_invocation, false)
59     path += extension unless extension.nil? || path.end_with?(extension)
60     path = datadir + path
61     path_exists = path.exist?
62     result << ResolvedLocation.new(declared_path, path, path_exists) unless is_default_config && !path_exists
63   end
64   result
65 end