Method: Puppet::Parser::Scope#setvar
- Defined in:
- lib/vendor/puppet/parser/scope.rb
#setvar(name, value, options = {}) ⇒ Object
Set a variable in the current scope. This will override settings in scopes above, but will not allow variables in the current scope to be reassigned.
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/vendor/puppet/parser/scope.rb', line 351 def setvar(name,value, = {}) table = [:ephemeral] ? @ephemeral.last : @symtable if table.include?(name) unless [:append] error = Puppet::ParseError.new("Cannot reassign variable #{name}") else error = Puppet::ParseError.new("Cannot append, variable #{name} is defined in this scope") end error.file = [:file] if [:file] error.line = [:line] if [:line] raise error end unless [:append] table[name] = value else # append case # lookup the value in the scope if it exists and insert the var table[name] = undef_as('',lookupvar(name)) # concatenate if string, append if array, nothing for other types case value when Array table[name] += value when Hash raise ArgumentError, "Trying to append to a hash with something which is not a hash is unsupported" unless value.is_a?(Hash) table[name].merge!(value) else table[name] << value end end end |