summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser/ast')
-rw-r--r--lib/puppet/parser/ast/collection.rb47
1 files changed, 37 insertions, 10 deletions
diff --git a/lib/puppet/parser/ast/collection.rb b/lib/puppet/parser/ast/collection.rb
index 030f1c239..8e9acce57 100644
--- a/lib/puppet/parser/ast/collection.rb
+++ b/lib/puppet/parser/ast/collection.rb
@@ -6,29 +6,58 @@ class Puppet::Parser::AST
class Collection < AST::Branch
attr_accessor :type
+ # We cannot evaluate directly here; instead we need to store a
+ # CollectType object, which will do the collection. This is
+ # the only way to find certain exported types in the current
+ # configuration.
def evaluate(hash)
scope = hash[:scope]
- type = @type.safeevaluate(:scope => scope)
+ @convertedtype = @type.safeevaluate(:scope => scope)
- count = 0
- # Now perform the actual collection, yo.
+ scope.newcollection(self)
+ end
+ # Now perform the actual collection, yo.
+ def perform(scope)
# First get everything from the export table.
# FIXME This will only find objects that are before us in the tree,
# which is a problem.
- objects = scope.exported(type)
+ objects = scope.exported(@convertedtype)
+ # We want to return all of these objects, and then whichever objects
+ # we find in the db.
array = objects.values
+ # Mark all of these objects as collected, so that they also get
+ # returned to the client. We don't store them in our scope
+ # or anything, which is a little odd, but eh.
+ array.each do |obj|
+ obj.collected = true
+ end
+
+ count = array.length
+
+ # Now we also have to see if there are any exported objects
+ # in our own scope.
+ scope.lookupexported(@convertedtype).each do |obj|
+ objects[obj.name] = obj
+ obj.collected = true
+ end
+
+ bucket = Puppet::TransBucket.new
+
Puppet::Rails::RailsObject.find_all_by_collectable(true).each do |obj|
+ # FIXME This should check that the source of the object is the
+ # host we're running on, else it's a bad conflict.
if objects.include?(obj.name)
- debug("%s[%s] is already exported" % [type, obj.name])
+ scope.debug("%s[%s] is already exported" % [@convertedtype, obj.name])
next
end
count += 1
trans = obj.to_trans
+ bucket.push(trans)
args = {
:name => trans.name,
@@ -43,6 +72,7 @@ class Puppet::Parser::AST
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
@@ -50,13 +80,10 @@ class Puppet::Parser::AST
scope.setobject(args)
end
-
-
scope.debug("Collected %s objects of type %s" %
- [count, type])
+ [count, @convertedtype])
- # The return value is entirely ignored right now, unfortunately.
- return nil
+ return bucket
end
end
end