summaryrefslogtreecommitdiffstats
path: root/lib/puppet/modules.rb
diff options
context:
space:
mode:
authorlutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-09 00:47:27 +0000
committerlutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-09 00:47:27 +0000
commitba6257c02ef5e4bd32d58d40087f84dda95141c3 (patch)
treeb5f4556465f7b48a2cf0858dc3c3510cf9943a33 /lib/puppet/modules.rb
parent10d68915c513ca9aa69862d17111acbf9ff87164 (diff)
downloadpuppet-ba6257c02ef5e4bd32d58d40087f84dda95141c3.tar.gz
puppet-ba6257c02ef5e4bd32d58d40087f84dda95141c3.tar.xz
puppet-ba6257c02ef5e4bd32d58d40087f84dda95141c3.zip
The basic plumbing for modules: a modulepath config parameter, and a new
class Puppet::Module that will contain the module-related functionality. The modulepath can be extended by setting the environment variable PUPPETLIB git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2276 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/modules.rb')
-rw-r--r--lib/puppet/modules.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/puppet/modules.rb b/lib/puppet/modules.rb
new file mode 100644
index 000000000..cf611b82c
--- /dev/null
+++ b/lib/puppet/modules.rb
@@ -0,0 +1,42 @@
+# Support for modules
+class Puppet::Module
+
+ # Return an array of paths by splitting the +modulepath+ config
+ # parameter. Only consider paths that are absolute and existing
+ # directories
+ def self.modulepath
+ dirs = ENV["PUPPETLIB"].split(":") + Puppet[:modulepath].split(":")
+ dirs.select do |p|
+ p =~ /^#{File::SEPARATOR}/ && File::directory?(p)
+ end
+ end
+
+ # Find and return the +module+ that +path+ belongs to. If +path+ is
+ # absolute, or if there is no module whose name is the first component
+ # of +path+, return +nil+
+ def self.find(path)
+ if path =~ %r/^#{File::SEPARATOR}/
+ return nil
+ end
+
+ modname, rest = path.split(File::SEPARATOR, 2)
+ return nil if modname.nil? || modname.empty?
+
+ modpath = modulepath.collect { |p|
+ File::join(p, modname)
+ }.find { |f| File::directory?(f) }
+ return nil unless modpath
+
+ return self.new(modname, modpath)
+ end
+
+ # Instance methods
+
+ attr_reader :name, :path
+ def initialize(name, path)
+ @name = name
+ @path = path
+ end
+
+ private :initialize
+end