Class: Puppet::Vendor
Overview
Simple module to manage vendored code.
To vendor a library:
-
Download its whole git repo or untar into ‘lib/puppet/vendor/<libname>`
-
Create a lib/puppetload_libraryname.rb file to add its libdir into the $:. (Look at existing load_xxx files, they should all follow the same pattern).
-
To load the vendored lib upfront, add a ‘require ’<vendorlib>‘`line to
vendor/require_vendored.rb. -
To load the vendored lib on demand, add a comment to
vendor/require_vendored.rbto make it clear it should not be loaded upfront.
At runtime, the #load_vendored method should be called. It will ensure all vendored libraries are added to the global ‘$:` path, and will then call execute the up-front loading specified in vendor/require_vendored.rb.
The intention is to not change vendored libraries and to eventually make adding them in optional so that distros can simply adjust their packaging to exclude this directory and the various load_xxx.rb scripts if they wish to install these gems as native packages.
Class Method Summary collapse
- .load_entry(entry) ⇒ Object private
-
.load_vendored ⇒ Object
Configures the path for all vendored libraries and loads required libraries.
- .require_libs ⇒ Object private
- .vendor_dir ⇒ Object private
Class Method Details
.load_entry(entry) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 |
# File 'lib/puppet/vendor.rb', line 31 def load_entry(entry) Puppet.debug("Loading vendored #{$1}") load "#{vendor_dir}/#{entry}" end |
.load_vendored ⇒ Object
Configures the path for all vendored libraries and loads required libraries. (This is the entry point for loading vendored libraries).
44 45 46 47 48 49 50 51 52 |
# File 'lib/puppet/vendor.rb', line 44 def load_vendored Dir.entries(vendor_dir).each do |entry| if entry.match(/load_(\w+?)\.rb$/) load_entry entry end end require_libs end |
.require_libs ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 |
# File 'lib/puppet/vendor.rb', line 37 def require_libs require 'puppet/vendor/require_vendored' end |
.vendor_dir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/puppet/vendor.rb', line 26 def vendor_dir File.join([File.dirname(File.(__FILE__)), "vendor"]) end |