diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-13 20:01:12 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-13 20:01:12 +0000 |
| commit | 637cc71296f96fd1d5f2ca83aa7e20c73757f8dd (patch) | |
| tree | f3b055bf75d7df6cbabafb24334710071f2ef8ec /lib/puppet/parser/ast | |
| parent | 9e9ef1acc6231254e52b96257ed1e81475d2d1bc (diff) | |
| download | puppet-637cc71296f96fd1d5f2ca83aa7e20c73757f8dd.tar.gz puppet-637cc71296f96fd1d5f2ca83aa7e20c73757f8dd.tar.xz puppet-637cc71296f96fd1d5f2ca83aa7e20c73757f8dd.zip | |
I appear to have object collection working, incredibly. This commit does the collection from the database up to adding the objects to the current scope, which is what sends it to the client.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1190 980ebf18-57e1-0310-9a29-db15c13687c0
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 |
