Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Created March 19, 2010 20:51
Show Gist options
  • Save rsutphin/338169 to your computer and use it in GitHub Desktop.
Save rsutphin/338169 to your computer and use it in GitHub Desktop.
A rails 2.3 template which adds bundler 0.9.12 support to a new rails app
file 'config/preinitializer.rb', <<-PRE
# Use bundled gems
begin
require File.expand_path('../../.bundle/environment', __FILE__)
rescue LoadError
# This setup deliberately requires that the application be locked.
# For an alternative, see http://gist.github.com/302406#file_preinitializer.rb
if File.exist?(File.expand_path('../../Gemfile.lock', __FILE__))
raise "Application is locked but not installed. Run `bundle install` and then try again."
else
raise "Application is not locked. Run `bundle install --relock` and then try again."
end
end
PRE
file 'Gemfile', <<-GEMFILE
source :gemcutter
gem 'rails', '2.3.5', :require => nil
# Switch to the appropriate gem for your database
gem 'sqlite3-ruby'
GEMFILE
gsub_file 'config/boot.rb', "# All that for this:\nRails.boot!" do |match|
<<-BOOT
# Use 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 :default, Rails.env
old_load.bind(self).call
end
end
end
end
# end bundler support
#{match}
BOOT
end
run "bundle install --relock"
if $? != 0
log "FAILURE", "bundle is not on the path. Install bundler and then run `bundle install --relock`."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment