diff options
Diffstat (limited to 'lib/puppet/parser/ast')
| -rw-r--r-- | lib/puppet/parser/ast/collection.rb | 49 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/function.rb | 7 |
2 files changed, 52 insertions, 4 deletions
diff --git a/lib/puppet/parser/ast/collection.rb b/lib/puppet/parser/ast/collection.rb new file mode 100644 index 000000000..e3afbbd8f --- /dev/null +++ b/lib/puppet/parser/ast/collection.rb @@ -0,0 +1,49 @@ +require 'puppet/rails' + +class Puppet::Parser::AST + # An object that collects stored objects from the central cache and returns + # them to the current host, yo. + class Collection < AST::Branch + attr_accessor :type + + def evaluate(hash) + scope = hash[:scope] + + type = @type.safeevaluate(:scope => scope) + + count = 0 + # Now perform the actual collection, yo. + Puppet::Rails::RailsObject.find_all_by_collectable(true).each do |obj| + count += 1 + trans = obj.to_trans + + args = { + :name => trans.name, + :type => trans.type, + } + + [:file, :line].each do |param| + if val = trans.send(param) + args[param] = val + end + end + + args[:arguments] = {} + trans.each do |p,v| args[:arguments][p] = v end + + # XXX Because the scopes don't expect objects to return values, + # we have to manually add our objects to the scope. This is + # uber-lame. + scope.setobject(args) + end + + scope.debug("Collected %s objects of type %s" % + [count, type]) + + # The return value is entirely ignored right now, unfortunately. + return nil + end + end +end + +# $Id$ diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb index 80cc5f09e..2c63c8b76 100644 --- a/lib/puppet/parser/ast/function.rb +++ b/lib/puppet/parser/ast/function.rb @@ -1,7 +1,5 @@ class Puppet::Parser::AST - # The code associated with a class. This is different from components - # in that each class is a singleton -- only one will exist for a given - # node. + # An AST object to call a function. class Function < AST::Branch attr_accessor :name, :arguments @@ -36,7 +34,8 @@ class Puppet::Parser::AST end when :statement: if Puppet::Parser::Functions.rvalue?(@name) - raise Puppet::ParseError, "Function '%s' must be the value of a statement" % + raise Puppet::ParseError, + "Function '%s' must be the value of a statement" % @name end else |
