Skip to content

Instantly share code, notes, and snippets.

@darrenboyd
Created February 5, 2010 23:31
Show Gist options
  • Save darrenboyd/296383 to your computer and use it in GitHub Desktop.
Save darrenboyd/296383 to your computer and use it in GitHub Desktop.
# ... at the end of the original boot.rb
# for bundler
class Rails::Boot
def run
load_initializer
extend_environment
Rails::Initializer.run(:set_load_path)
end
def extend_environment
Rails::Initializer.class_eval do
old_load = instance_method(:load_environment)
define_method(:load_environment) do
Bundler.require
old_load.bind(self).call
end
end
end
end
# All that for this:
Rails.boot!
namespace :bundler do
%w(install update uninstall).each do |cmd|
task cmd, :except => { :no_release => true } do
opts = cmd == 'uninstall' ? '--all' : '--source=http://gemcutter.org --no-rdoc --no-ri'
run("sudo gem #{cmd} bundler #{opts}")
end
end
task :symlink_vendor do
run %Q{ rm -fr #{release_path}/vendor/bundler_gems}
run %Q{ mkdir -p #{shared_path}/bundler_gems}
run %Q{ ln -nfs #{shared_path}/bundler_gems #{release_path}/vendor/bundler_gems}
end
task :bundle_new_release do
bundler.symlink_vendor
run("cd #{release_path} && bundle install vendor/bundler_gems && bundle lock")
end
end
after 'deploy:update_code', 'bundler:bundle_new_release'
# I found I had to do this in my Gemfile to get Bundler to load Rails 2.3.5
gem 'rails', '2.3.5', :require => nil
gem 'builder', '2.1.2'
gem 'tzinfo', '0.3.16'
gem 'i18n', '0.3.3'
gem 'tmail', '1.2.6'
class Pathname
def empty?
to_s.empty?
end
end
begin
# Require the preresolved locked set of gems.
require File.expand_path('../../.bundle/environment', __FILE__)
rescue LoadError
# Fallback on doing the resolve at runtime.
require "rubygems"
require "bundler"
Bundler.setup
end
Bundler.require(:test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment