Method: Puppet::Parser::Scope#exist?
- Defined in:
- lib/puppet/parser/scope.rb
#exist?(name) ⇒ Boolean
Returns true if the variable of the given name is set to any value (including nil)
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/puppet/parser/scope.rb', line 283 def exist?(name) # Note !! ensure the answer is boolean !!if name =~ /^(.*)::(.+)$/ class_name = ::Regexp.last_match(1) variable_name = ::Regexp.last_match(2) return true if class_name == '' && BUILT_IN_VARS.include?(variable_name) # lookup class, but do not care if it is not evaluated since that will result # in it not existing anyway. (Tests may run with just scopes and no evaluated classes which # will result in class_scope for "" not returning topscope). klass = find_hostclass(class_name) other_scope = klass.nil? ? nil : class_scope(klass) if other_scope.nil? class_name == '' ? compiler.topscope.exist?(variable_name) : false else other_scope.exist?(variable_name) end else # rubocop:disable Layout/ElseAlignment next_scope = inherited_scope || enclosing_scope effective_symtable(true).include?(name) || next_scope && next_scope.exist?(name) || BUILT_IN_VARS.include?(name) end # rubocop:disable Layout/EndAlignment end |