summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/collection.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-05-13 20:01:12 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-05-13 20:01:12 +0000
commit637cc71296f96fd1d5f2ca83aa7e20c73757f8dd (patch)
treef3b055bf75d7df6cbabafb24334710071f2ef8ec /lib/puppet/parser/ast/collection.rb
parent9e9ef1acc6231254e52b96257ed1e81475d2d1bc (diff)
downloadpuppet-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/collection.rb')
-rw-r--r--lib/puppet/parser/ast/collection.rb49
1 files changed, 49 insertions, 0 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$