Method: Puppet::Parser::Scope#lookupvar

Defined in:
lib/puppet/parser/scope.rb

#lookupvar(name, options = EMPTY_HASH) ⇒ Object

Lookup a variable within this scope using the Puppet language’s scoping rules. Variables can be qualified using just as in a manifest.



491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/puppet/parser/scope.rb', line 491

def lookupvar(name, options = EMPTY_HASH)
  unless name.is_a? String
    raise Puppet::ParseError, _("Scope variable name %{name} is a %{klass}, not a string") % { name: name.inspect, klass: name.class }
  end

  # If name has '::' in it, it is resolved as a qualified variable
  unless (idx = name.index('::')).nil?
    # Always drop leading '::' if present as that is how the values are keyed.
    return lookup_qualified_variable(idx == 0 ? name[2..] : name, options)
  end

  # At this point, search is for a non qualified (simple) name
  table = @ephemeral.last
  val = table[name]
  return val unless val.nil? && !table.include?(name)

  next_scope = inherited_scope || enclosing_scope
  if next_scope
    next_scope.lookupvar(name, options)
  else
    variable_not_found(name)
  end
end