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

API:

  • private

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.

API:

  • private



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

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(&: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.

API:

  • private



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

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.

Parameters:

  • paths as found in declaration. May contain interpolation expressions

  • The current lookup invocation

Returns:

  • Array of resolved paths

API:

  • private



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

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.

Parameters:

  • The base when creating absolute paths

  • paths as found in declaration. May contain interpolation expressions

  • The current lookup invocation

  • true if this is the default config and non-existent paths should be excluded

  • (defaults to: nil)

    Required extension such as ‘.yaml’ or ‘.json’. Use only if paths without extension can be expected

Returns:

  • Array of resolved paths

API:

  • private



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

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