summaryrefslogtreecommitdiffstats
path: root/lib/puppet/module.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/module.rb')
-rw-r--r--lib/puppet/module.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 01459d7aa..5ae3f3121 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -7,6 +7,28 @@ class Puppet::Module
PLUGINS = "plugins"
FILETYPES = [MANIFESTS, FILES, TEMPLATES, PLUGINS]
+
+ # Search through a list of paths, yielding each found module in turn.
+ def self.each_module(*paths)
+ paths = paths.flatten.collect { |p| p.split(File::PATH_SEPARATOR) }.flatten
+
+ yielded = {}
+ paths.each do |dir|
+ next unless FileTest.directory?(dir)
+
+ Dir.entries(dir).each do |name|
+ next if name =~ /^\./
+ next if yielded.include?(name)
+
+ module_path = File.join(dir, name)
+ next unless FileTest.directory?(module_path)
+
+ yielded[name] = true
+
+ yield Puppet::Module.new(name, module_path)
+ end
+ end
+ end
# Return an array of paths by splitting the +modulepath+ config
# parameter. Only consider paths that are absolute and existing