lib/puppet/parser/ast/leaf.rb in puppet-3.2.4 vs lib/puppet/parser/ast/leaf.rb in puppet-3.3.0.rc2
- old
+ new
@@ -129,11 +129,17 @@
class HashOrArrayAccess < AST::Leaf
attr_accessor :variable, :key
def evaluate_container(scope)
container = variable.respond_to?(:evaluate) ? variable.safeevaluate(scope) : variable
- (container.is_a?(Hash) or container.is_a?(Array)) ? container : scope[container, {:file => file, :line => line}]
+ if container.is_a?(Hash) || container.is_a?(Array)
+ container
+ elsif container.is_a?(::String)
+ scope[container, {:file => file, :line => line}]
+ else
+ raise Puppet::ParseError, "#{variable} is #{container.inspect}, not a hash or array"
+ end
end
def evaluate_key(scope)
key.respond_to?(:evaluate) ? key.safeevaluate(scope) : key
end
@@ -146,12 +152,13 @@
end
def evaluate(scope)
object = evaluate_container(scope)
accesskey = evaluate_key(scope)
- raise Puppet::ParseError, "#{variable} is not an hash or array when accessing it with #{accesskey}" unless object.is_a?(Hash) or object.is_a?(Array)
+ raise Puppet::ParseError, "#{variable} is not a hash or array when accessing it with #{accesskey}" unless object.is_a?(Hash) or object.is_a?(Array)
- object[array_index_or_key(object, accesskey)] || :undef
+ result = object[array_index_or_key(object, accesskey)]
+ result.nil? ? :undef : result
end
# Assign value to this hashkey or array index
def assign(scope, value)
object = evaluate_container(scope)