Skip to content

Instantly share code, notes, and snippets.

@curzonj
Created July 12, 2012 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curzonj/3099815 to your computer and use it in GitHub Desktop.
Save curzonj/3099815 to your computer and use it in GitHub Desktop.
Allow chef to work inside a gem bundle
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