diff options
| author | Luke Kanies <luke@madstop.com> | 2009-02-17 17:50:46 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2009-02-18 22:38:44 -0600 |
| commit | 9c18d5aa4214f565b81b6cac07736fe072954bb1 (patch) | |
| tree | 7ea6f06b2d94319935221da32241f7f939d1f5d2 /lib | |
| parent | 4b5ec82d32babdf3ccc935748eb80bca30b379ff (diff) | |
Adding support for finding all modules in a given path.
This 'each_module' method will be used by environments
to find all or a given module, and will likely eventually
be used internally, too.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/module.rb | 22 |
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 |
