diff options
Diffstat (limited to 'lib/puppet/parser/ast/asthash.rb')
-rw-r--r-- | lib/puppet/parser/ast/asthash.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/asthash.rb b/lib/puppet/parser/ast/asthash.rb new file mode 100644 index 000000000..2860657e0 --- /dev/null +++ b/lib/puppet/parser/ast/asthash.rb @@ -0,0 +1,34 @@ +require 'puppet/parser/ast/leaf' + +class Puppet::Parser::AST + class ASTHash < Leaf + include Enumerable + + def [](index) + end + + # Evaluate our children. + def evaluate(scope) + items = {} + + @value.each_pair do |k,v| + items.merge!({ k => v.safeevaluate(scope) }) + end + + return items + end + + def merge(hash) + case hash + when ASTHash + @value = @value.merge(hash.value) + when Hash + @value = @value.merge(hash) + end + end + + def to_s + "{" + @value.collect { |v| v.collect { |a| a.to_s }.join(' => ') }.join(', ') + "}" + end + end +end |