From 87d8634b04ee38d6b1541889600905ee0d9fb9c1 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Fri, 18 Mar 2011 21:25:45 +0100 Subject: [PATCH] [#290] using bundler * following setup instructions from http://gembundler.com/rails23.html * adding generated files to .gitignore and .hgignore * removing config.gem calls * adding Gemfile that should work with all supported dbs and interpreters * removing work-around for rubygems 1.5 deprecation. this seems to be fixed since now bundler handles the gem loading --- .gitignore | 2 ++ .hgignore | 3 ++ Gemfile | 64 +++++++++++++++++++++++++++++++++++++ config/boot.rb | 9 ++++++ config/environment.rb | 5 +-- config/environments/test.rb | 4 --- config/preinitializer.rb | 20 ++++++++++++ 7 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 Gemfile create mode 100644 config/preinitializer.rb diff --git a/.gitignore b/.gitignore index f4461f60..1b6527d6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ /vendor/rails *.rbc doc/app +/.bundle +/Gemfile.lock diff --git a/.hgignore b/.hgignore index e407dd69..bfe73cfc 100644 --- a/.hgignore +++ b/.hgignore @@ -27,3 +27,6 @@ vendor/rails *.rbc .svn/ .git/ +doc/app +/.bundle +/Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..eb961436 --- /dev/null +++ b/Gemfile @@ -0,0 +1,64 @@ +source :rubygems + +gem "rails", "2.3.11" + +gem "coderay", "~> 0.9.7" +gem "i18n", "< 0.5" # explicit version 0.4.2 is used in config! +gem "ruby-openid" +gem "rubytree", "~> 0.5.2", :require => 'tree' + +group :development, :test do + gem 'edavis10-object_daddy', :require => 'object_daddy' + gem 'mocha' + gem 'shoulda', '~> 2.10.3' +end + + +# Use the commented pure ruby gems, if you have not the needed prerequisites on +# board to compile the native ones. Note, that their use is discouraged, since +# their integration is propbably not that well tested and their are slower in +# orders of magnitude compared to their native counterparts. You have been +# warned. +# +platforms :mri do + group :mysql do + gem "mysql" + # gem "ruby-mysql" + end + + group :mysql2 do + gem "mysql2" + end + + group :postgres do + gem "pg", "~> 0.9.0" + # gem "postgres-pr" + end + + group :sqlite do + gem "sqlite3-ruby", "< 1.3", :require => "sqlite3" + # please tell me, if you are fond of a pure ruby sqlite3 binding + end +end + +platforms :jruby do + gem "jruby-openssl" + + group :mysql do + gem "activerecord-jdbcmysql-adapter" + end + + group :postgres do + gem "activerecord-jdbcpostgresql-adapter" + end + + group :sqlite do + gem "activerecord-jdbcsqlite3-adapter" + end +end + +# Load plugins' Gemfiles +Dir.glob File.expand_path("../vendor/plugins/*/Gemfile", __FILE__) do |file| + puts "Loading #{file} ..." + instance_eval File.read(file) +end diff --git a/config/boot.rb b/config/boot.rb index 6686664c..b5869a8c 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -36,6 +36,15 @@ module Rails class Boot def run load_initializer + + # This block was added for bundler support while following setup + # instructions from http://gembundler.com/rails23.html + Rails::Initializer.class_eval do + def load_gems + @bundler_loaded ||= Bundler.require :default, Rails.env + end + end + Rails::Initializer.run(:set_load_path) end end diff --git a/config/environment.rb b/config/environment.rb index 00e81517..0fa17409 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -50,11 +50,8 @@ Rails::Initializer.run do |config| # It will automatically turn deliveries on config.action_mailer.perform_deliveries = false - config.gem 'rubytree', :lib => 'tree' - config.gem 'coderay', :version => '~>0.9.7' - # Load any local configuration that is kept out of source control - # (e.g. gems, patches). + # (e.g. patches). if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb')) instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb')) end diff --git a/config/environments/test.rb b/config/environments/test.rb index 79ee6af9..4ce45527 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -23,7 +23,3 @@ config.action_controller.session = { # Skip protect_from_forgery in requests http://m.onkey.org/2007/9/28/csrf-protection-for-your-existing-rails-application config.action_controller.allow_forgery_protection = false - -config.gem "shoulda", :version => "~> 2.10.3" -config.gem "edavis10-object_daddy", :lib => "object_daddy" -config.gem "mocha" diff --git a/config/preinitializer.rb b/config/preinitializer.rb new file mode 100644 index 00000000..3ad02415 --- /dev/null +++ b/config/preinitializer.rb @@ -0,0 +1,20 @@ +begin + require "rubygems" + require "bundler" +rescue LoadError + raise "Could not load the bundler gem. Install it with `gem install bundler`." +end + +if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24") + raise RuntimeError, "Your bundler version is too old for Rails 2.3." + + "Run `gem install bundler` to upgrade." +end + +begin + # Set up load paths for all bundled gems + ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__) + Bundler.setup +rescue Bundler::GemNotFound + raise RuntimeError, "Bundler couldn't find some gems." + + "Did you run `bundle install`?" +end