Created
July 12, 2012 18:10
-
-
Save curzonj/3099815 to your computer and use it in GitHub Desktop.
Allow chef to work inside a gem bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mixlib::ShellOut.class_eval do | |
def exec(*args) | |
Bundler.with_clean_env do | |
# we have to rerun this because bundler wiped it | |
set_environment | |
gem_home = ENV.delete('GEM_HOME') | |
paths = ENV['PATH'].split(':') | |
ENV['PATH'] = paths.delete_if {|n| n =~ /^#{Regexp.escape(gem_home)}/ }.join(':') | |
Kernel.exec(*args) | |
end | |
end | |
end | |
## Allow us to inspect specification indexes outside | |
## of the bundle | |
class AntiBundlerSpecificationProxy # wait until 1.9 < BasicObject | |
def initialize dirs | |
@bundler_specs = __spec._all | |
@bundler_dirs = __spec.dirs | |
@dirs = dirs | |
end | |
def method_missing(name, *args) | |
__reverse { __spec.send(name, *args) } | |
end | |
private | |
def __reverse | |
__spec.dirs = @dirs | |
__spec.all = nil | |
__spec._all | |
yield | |
ensure | |
__spec.dirs = @bundler_dirs | |
__spec.all = @bundler_specs | |
end | |
def __spec | |
Gem::Specification | |
end | |
end | |
Chef::Provider::Package::Rubygems::AlternateGemEnvironment.class_eval do | |
def gem_specification | |
@specification = AntiBundlerSpecificationProxy.new(gem_paths) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment