Skip to content

Commit eb4da76

Browse files
committed
Extract rails gem loading into shared Gemfile.
When the example app is generated it puts a Rails version that is defined by currently installed version. This works great in most situtations, except `master` or other edge branches. The version listed is the current version of Rails, so they diverge. Move how we load rails into a custom Gemfile, which we eval ourselves. We then remove the rails version put into the gemfile and share our custom version. Due to when `rake` and other shell processes fork, the RAILS_VERSION environment variable is properly passed through.
1 parent ce4ceaf commit eb4da76

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

Gemfile

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,5 @@ end
3636
custom_gemfile = File.expand_path("../Gemfile-custom", __FILE__)
3737
eval_gemfile custom_gemfile if File.exist?(custom_gemfile)
3838

39-
version_file = File.expand_path("../.rails-version", __FILE__)
40-
case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp)
41-
when /master/
42-
gem "rails", :git => "git://github.com/rails/rails.git"
43-
gem "arel", :git => "git://github.com/rails/arel.git"
44-
gem "journey", :git => "git://github.com/rails/journey.git"
45-
gem "activerecord-deprecated_finders", :git => "git://github.com/rails/activerecord-deprecated_finders.git"
46-
gem "rails-observers", :git => "git://github.com/rails/rails-observers"
47-
gem 'sass-rails', :git => "git://github.com/rails/sass-rails.git"
48-
gem 'coffee-rails', :git => "git://github.com/rails/coffee-rails.git"
49-
when /stable$/
50-
gem "rails", :git => "git://github.com/rails/rails.git", :branch => version
51-
when nil, false, ""
52-
if RUBY_VERSION < '1.9.3'
53-
# Rails 4+ requires 1.9.3+, so on earlier versions default to the last 3.x release.
54-
gem "rails", "~> 3.2.17"
55-
else
56-
gem "rails", "~> 4.0.4"
57-
end
58-
else
59-
gem "rails", version
60-
end
39+
rails_dependencies_gemfile = File.expand_path("../Gemfile-rails-dependencies", __FILE__)
40+
eval_gemfile rails_dependencies_gemfile

Gemfile-rails-dependencies

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version_file = File.expand_path("../.rails-version", __FILE__)
2+
case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp)
3+
when /master/
4+
gem "rails", :git => "git://github.com/rails/rails.git"
5+
gem "arel", :git => "git://github.com/rails/arel.git"
6+
gem "journey", :git => "git://github.com/rails/journey.git"
7+
gem "activerecord-deprecated_finders", :git => "git://github.com/rails/activerecord-deprecated_finders.git"
8+
gem "rails-observers", :git => "git://github.com/rails/rails-observers"
9+
gem 'sass-rails', :git => "git://github.com/rails/sass-rails.git"
10+
gem 'coffee-rails', :git => "git://github.com/rails/coffee-rails.git"
11+
when /stable$/
12+
gem "rails", :git => "git://github.com/rails/rails.git", :branch => version
13+
when nil, false, ""
14+
if RUBY_VERSION < '1.9.3'
15+
# Rails 4+ requires 1.9.3+, so on earlier versions default to the last 3.x release.
16+
gem "rails", "~> 3.2.17"
17+
else
18+
gem "rails", "~> 4.0.4"
19+
end
20+
else
21+
gem "rails", version
22+
end

templates/generate_app.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
rspec_rails_repo_path = File.expand_path("../../", __FILE__)
22
rspec_dependencies_gemfile = File.join(rspec_rails_repo_path, 'Gemfile-rspec-dependencies')
3+
rails_dependencies_gemfile = File.join(rspec_rails_repo_path, 'Gemfile-rails-dependencies')
34
in_root do
5+
# Remove the existing rails version so we can properly use master or other
6+
# edge branches
7+
gsub_file 'Gemfile', /^.*\bgem 'rails.*$/, ''
8+
9+
# Use our version of RSpec and Rails
410
append_to_file 'Gemfile', <<-EOT.gsub(/^ +\|/, '')
511
|gem 'rspec-rails',
612
| :path => '#{rspec_rails_repo_path}',
713
| :groups => [:development, :test]
814
|eval_gemfile '#{rspec_dependencies_gemfile}'
15+
|eval_gemfile '#{rails_dependencies_gemfile}'
916
EOT
1017
end

0 commit comments

Comments
 (0)