045146707875a57df44186ba2f4c265503570127
[packages/precise/mcollective.git] / lib / mcollective / vendor.rb
1 module MCollective
2   # Simple module to manage vendored code.
3   #
4   # To vendor a library simply download its whole git repo or untar
5   # into vendor/libraryname and create a load_libraryname.rb file
6   # to add its libdir into the $:.
7   #
8   # Once you have that file, add a require line in vendor/require_vendored.rb
9   # which will run after all the load_* files.
10   #
11   # The intention is to not change vendored libraries and to eventually
12   # make adding them in optional so that distros can simply adjust their
13   # packaging to exclude this directory and the various load_xxx.rb scripts
14   # if they wish to install these gems as native packages.
15   class Vendor
16     class << self
17       def vendor_dir
18         File.join([File.dirname(File.expand_path(__FILE__)), "vendor"])
19       end
20
21       def load_entry(entry)
22         Log.debug("Loading vendored #{$1}")
23         load "#{vendor_dir}/#{entry}"
24       end
25
26       def require_libs
27         require 'mcollective/vendor/require_vendored'
28       end
29
30       def load_vendored
31         Dir.entries(vendor_dir).each do |entry|
32           if entry.match(/load_(\w+?)\.rb$/)
33             load_entry entry
34           end
35         end
36
37         require_libs
38       end
39     end
40   end
41 end