summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/type.rb38
-rwxr-xr-xlib/puppet/type/exec.rb16
2 files changed, 40 insertions, 14 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 2b228c678..af74e76c1 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -391,6 +391,22 @@ class Type < Puppet::Element
return s
end
+ # Specify a block for generating a list of objects to autorequire. This
+ # makes it so that you don't have to manually specify things that you clearly
+ # require.
+ def self.autorequire(name, &block)
+ @autorequires ||= {}
+ @autorequires[name] = block
+ end
+
+ # Yield each of those autorequires in turn, yo.
+ def self.eachautorequire
+ @autorequires ||= {}
+ @autorequires.each { |type, block|
+ yield(type, block)
+ }
+ end
+
# Return the parameter names
def self.parameters
@parameters.collect { |klass| klass.name }
@@ -1017,6 +1033,28 @@ class Type < Puppet::Element
if self.respond_to?(:validate)
self.validate
end
+
+ self.autorequire
+ end
+
+ # Figure out of there are any objects we can automatically add as
+ # dependencies.
+ def autorequire
+ self.class.eachautorequire { |type, block|
+ # Ignore any types we can't find, although that would be a bit odd.
+ next unless typeobj = Puppet.type(type)
+
+ # Retrieve the list of names from the block.
+ next unless list = self.instance_eval(&block)
+ list.each { |dep|
+ if obj = typeobj[dep]
+ unless self.requires?(obj)
+ self.info "Auto-requiring %s" % obj.name
+ self[:require] = [type, dep]
+ end
+ end
+ }
+ }
end
# Is the specified parameter set?
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 04be7f62a..5d96dabd7 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -264,21 +264,9 @@ module Puppet
end
end
- def initialize(*args)
- super
-
- # If the command is fully qualified and we're managing it, let's go
- # ahead and auto-require it.
+ autorequire(:file) do
if self[:command] =~ /^#{File::SEPARATOR}/
- cmd = self[:command].sub(/\s.+/,'')
- if file = Puppet.type(:file)[cmd]
- unless self.requires?(file)
- self.info "Auto-requiring %s" % cmd
- self[:require] = [:file, cmd]
- #else
- # self.info "Already require %s" % cmd
- end
- end
+ self[:command].sub(/\s.+/,'')
end
end