Refactor to not generate explicit resources and to not bail out if
one of a set can not be ensured absend.

Signed-off-by: Markus Roberts <[email protected]>
---
 lib/puppet/type/resources.rb |   34 +++++++++++++++++-----------------
 1 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb
index ab564a1..87bde97 100644
--- a/lib/puppet/type/resources.rb
+++ b/lib/puppet/type/resources.rb
@@ -85,33 +85,33 @@ Puppet::Type.newtype(:resources) do
         end
     end
 
+    def able_to_ensure_absent?(resource)
+        begin
+            resource[:ensure] = :absent
+        rescue ArgumentError, Puppet::Error => detail
+            err "The 'ensure' attribute on #{self[:name]} resources does not 
accept 'absent' as a value"
+            false
+        end
+    end
+
     # Generate any new resources we need to manage.  This is pretty hackish
     # right now, because it only supports purging.
     def generate
         return [] unless self.purge?
-        hascheck = false
-        method =
-        resource_type.instances.find_all do |resource|
-            ! resource.managed?
-        end.find_all do |resource|
-            check(resource)
-        end.each do |resource|
-            begin
-                resource[:ensure] = :absent
-            rescue ArgumentError, Puppet::Error => detail
-                err "The 'ensure' attribute on %s resources does not accept 
'absent' as a value" %
-                    [self[:name]]
-                return []
-            end
+        resource_type.instances.
+          reject { |r| managed? }.
+          reject { |r| catalog.resources.include? r.ref }.
+          select { |r| check(r) }.
+          select { |r| able_to_ensure_absent?(r) }.
+          each { |resource|
             @parameters.each do |name, param|
-                next unless param.metaparam?
-                resource[name] = param.value
+                resource[name] = param.value if param.metaparam?
             end
 
             # Mark that we're purging, so transactions can handle relationships
             # correctly
             resource.purging
-        end
+          }
     end
 
     def resource_type
-- 
1.6.4


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to