Module: Puppet::Pops::Lookup::LocationResolver Private

Includes:
Interpolation
Included in:
HieraConfig
Defined in:
lib/puppet/pops/lookup/location_resolver.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helper methods to resolve interpolated locations

Constant Summary

Constants included from SubLookup

SubLookup::SPECIAL

Instance Method Summary collapse

Methods included from Interpolation

#interpolate

Methods included from SubLookup

#split_key, #sub_lookup

Instance Method Details

#expand_globs(datadir, declared_globs, lookup_invocation) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


41
42
43
44
45
46
# File 'lib/puppet/pops/lookup/location_resolver.rb', line 41

def expand_globs(datadir, declared_globs, lookup_invocation)
  declared_globs.map do |declared_glob|
    glob = datadir + interpolate(declared_glob, lookup_invocation, false)
    Pathname.glob(glob).reject { |path| path.directory? }.map { |path| ResolvedLocation.new(glob.to_s, path, true) }
  end.flatten
end

#expand_mapped_paths(datadir, mapped_path_triplet, lookup_invocation) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/puppet/pops/lookup/location_resolver.rb', line 76

def expand_mapped_paths(datadir, mapped_path_triplet, lookup_invocation)
  # The scope interpolation method is used directly to avoid unnecessary parsing of the string that otherwise
  # would need to be generated
  mapped_vars = interpolate_method(:scope).call(mapped_path_triplet[0], lookup_invocation, 'mapped_path[0]')

  # No paths here unless the scope lookup returned something
  return EMPTY_ARRAY if mapped_vars.nil? || mapped_vars.empty?

  mapped_vars = [mapped_vars] if mapped_vars.is_a?(String)
  var_key = mapped_path_triplet[1]
  template = mapped_path_triplet[2]
  scope = lookup_invocation.scope
  lookup_invocation.with_local_memory_eluding(var_key) do
    mapped_vars.map do |var|
      # Need to use parent lookup invocation to avoid adding 'var' to the set of variables to track for changes. The
      # variable that 'var' stems from is added above.
      path = scope.with_local_scope(var_key => var) {  datadir + interpolate(template, lookup_invocation, false) }
      ResolvedLocation.new(template, path, path.exist?)
    end
  end
end

#expand_uris(declared_uris, lookup_invocation) ⇒ Array<ResolvedLocation>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Array of resolved paths


69
70
71
72
73
74
# File 'lib/puppet/pops/lookup/location_resolver.rb', line 69

def expand_uris(declared_uris, lookup_invocation)
  declared_uris.map do |declared_uri|
    uri = URI(interpolate(declared_uri, lookup_invocation, false))
    ResolvedLocation.new(declared_uri, uri, true)
  end
end

#resolve_paths(datadir, declared_paths, lookup_invocation, is_default_config, extension = nil) ⇒ Array<ResolvedLocation>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Array of resolved paths


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/puppet/pops/lookup/location_resolver.rb', line 54

def resolve_paths(datadir, declared_paths, lookup_invocation, is_default_config, extension = nil)
  result = []
  declared_paths.each do |declared_path|
    path = interpolate(declared_path, lookup_invocation, false)
    path += extension unless extension.nil? || path.end_with?(extension)
    path = datadir + path
    path_exists = path.exist?
    result << ResolvedLocation.new(declared_path, path, path_exists) unless is_default_config && !path_exists
  end
  result
end