diff options
| author | Luke Kanies <luke@madstop.com> | 2009-02-17 16:20:34 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2009-02-18 22:38:44 -0600 |
| commit | bdf3a80e29313008367d83f5a1ec6e4121e4ec74 (patch) | |
| tree | cb096f05b24eee0cd8cb93e1d0a3c879da038b29 /lib | |
| parent | a7be174d249ca581d9ae849ba3823abc2c006b08 (diff) | |
| download | puppet-bdf3a80e29313008367d83f5a1ec6e4121e4ec74.tar.gz puppet-bdf3a80e29313008367d83f5a1ec6e4121e4ec74.tar.xz puppet-bdf3a80e29313008367d83f5a1ec6e4121e4ec74.zip | |
Adding new methods to Puppet::Module.
There are now boolean methods to test whether a given kind
of file is present in a given module. E.g, you can do:
Puppet::Module.new("mod", "/my/path").plugins?
There are also accessor-style methods that return the
full path for a given kind of file.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/module.rb | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb index b9a8b7d79..01459d7aa 100644 --- a/lib/puppet/module.rb +++ b/lib/puppet/module.rb @@ -4,6 +4,9 @@ class Puppet::Module TEMPLATES = "templates" FILES = "files" MANIFESTS = "manifests" + PLUGINS = "plugins" + + FILETYPES = [MANIFESTS, FILES, TEMPLATES, PLUGINS] # Return an array of paths by splitting the +modulepath+ config # parameter. Only consider paths that are absolute and existing @@ -148,14 +151,24 @@ class Puppet::Module @path = path end - def template(file) - full_path = File::join(path, TEMPLATES, file) - return nil unless full_path - return full_path - end + FILETYPES.each do |type| + # Create a method for returning the full path to a given + # file type's directory. + define_method(type.to_s) do + File.join(path, type.to_s) + end + # Create a boolean method for testing whether our module has + # files of a given type. + define_method(type.to_s + "?") do + FileTest.exist?(send(type)) + end - def files - return File::join(path, FILES) + # Finally, a method for returning an individual file + define_method(type.to_s.sub(/s$/, '')) do |file| + path = File.join(send(type), file) + return nil unless FileTest.exist?(path) + return path + end end # Return the list of manifests matching the given glob pattern, |
