summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/collector.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-18 06:01:18 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-18 06:01:18 +0000
commit3a6683ea720a53bd2ddb34b9215bdc676bdcdb2c (patch)
tree3865ab57a73d5b07554cda594eb9c5fff15b027a /lib/puppet/parser/collector.rb
parent05080ff50b73597f0a3f86242b63985a1e5e6003 (diff)
downloadpuppet-3a6683ea720a53bd2ddb34b9215bdc676bdcdb2c.tar.gz
puppet-3a6683ea720a53bd2ddb34b9215bdc676bdcdb2c.tar.xz
puppet-3a6683ea720a53bd2ddb34b9215bdc676bdcdb2c.zip
Changing the realize() function to be just syntactic sugar for a collection -- it literally creates a collector object now. The benefit of this is that it is late-binding, so file order does not affect whether a resource is available.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1810 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/collector.rb')
-rw-r--r--lib/puppet/parser/collector.rb31
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index 1fa314ae2..61807717d 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -1,7 +1,7 @@
# An object that collects stored objects from the central cache and returns
# them to the current host, yo.
class Puppet::Parser::Collector
- attr_accessor :type, :scope, :vquery, :rquery, :form
+ attr_accessor :type, :scope, :vquery, :rquery, :form, :resources
# Collect exported objects.
def collect_exported
@@ -48,6 +48,31 @@ class Puppet::Parser::Collector
return resources
end
+ def collect_resources
+ unless @resources.is_a?(Array)
+ @resources = [@resources]
+ end
+ method = "collect_#{form.to_s}_resources"
+ send(method)
+ end
+
+ def collect_exported_resources
+ raise Puppet::ParseError,
+ "realize() is not yet implemented for exported resources"
+ end
+
+ def collect_virtual_resources
+ @resources.collect do |ref|
+ if res = @scope.findresource(ref.to_s)
+ res
+ else
+ raise Puppet::ParseError, "Could not find resource %s" % ref
+ end
+ end.each do |res|
+ res.virtual = false
+ end
+ end
+
# Collect just virtual objects, from our local configuration.
def collect_virtual(exported = false)
if exported
@@ -63,6 +88,10 @@ class Puppet::Parser::Collector
# Call the collection method, mark all of the returned objects as non-virtual,
# and then delete this object from the list of collections to evaluate.
def evaluate
+ if self.resources
+ return collect_resources
+ end
+
method = "collect_#{@form.to_s}"
objects = send(method).each do |obj|
obj.virtual = false