aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/app_rails_loader.rb55
-rw-r--r--railties/lib/rails/generators/app_base.rb26
2 files changed, 39 insertions, 42 deletions
diff --git a/railties/lib/rails/app_rails_loader.rb b/railties/lib/rails/app_rails_loader.rb
index aae628290d..4a17803f1c 100644
--- a/railties/lib/rails/app_rails_loader.rb
+++ b/railties/lib/rails/app_rails_loader.rb
@@ -4,28 +4,7 @@ module Rails
module AppRailsLoader
RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
EXECUTABLES = ['bin/rails', 'script/rails']
-
- def self.exec_app_rails
- original_cwd = Dir.pwd
-
- until exe = find_executable
- # If we exhaust the search there is no executable, this could be a
- # call to generate a new application, so restore the original cwd.
- Dir.chdir(original_cwd) and return if Pathname.new(Dir.pwd).root?
-
- # Otherwise keep moving upwards in search of a executable.
- Dir.chdir('..')
- end
-
- contents = File.read(exe)
-
- # This is the Rails executable, let's use it
- if contents =~ /(APP|ENGINE)_PATH/
- exec RUBY, exe, *ARGV
-
- # This is a Bundler binstub. Stop and explain how to upgrade.
- elsif exe =~ /bin\/rails$/ && contents =~ /This file was generated by Bundler/
- $stderr.puts <<-end_bin_upgrade_warning
+ BUNDLER_WARNING = <<EOS
Looks like your app's ./bin/rails is a stub that was generated by Bundler.
In Rails 4, your app's bin/ directory contains executables that are versioned
@@ -45,14 +24,34 @@ generate it and add it to source control:
bundle binstubs some-gem-name
git add bin/new-executable
- end_bin_upgrade_warning
+EOS
+
+ def self.exec_app_rails
+ original_cwd = Dir.pwd
+
+ loop do
+ if exe = find_executable
+ contents = File.read(exe)
+
+ if contents =~ /(APP|ENGINE)_PATH/
+ exec RUBY, exe, *ARGV
+ break # non reachable, hack to be able to stub exec in the test suite
+ elsif exe.end_with?('bin/rails') && contents.include?('This file was generated by Bundler')
+ $stderr.puts(BUNDLER_WARNING)
+ Object.const_set(:APP_PATH, File.expand_path('config/application', Dir.pwd))
+ require File.expand_path('../boot', APP_PATH)
+ require 'rails/commands'
+ break
+ end
+ end
- Object.const_set(:APP_PATH, File.expand_path('config/application', Dir.pwd))
- require File.expand_path('../boot', APP_PATH)
- require 'rails/commands'
+ # If we exhaust the search there is no executable, this could be a
+ # call to generate a new application, so restore the original cwd.
+ Dir.chdir(original_cwd) and return if Pathname.new(Dir.pwd).root?
+
+ # Otherwise keep moving upwards in search of a executable.
+ Dir.chdir('..')
end
- rescue SystemCallError
- # could not chdir, no problem just return
end
def self.find_executable
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index b62d1fff14..4fd1f00294 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -116,7 +116,7 @@ module Rails
def database_gemfile_entry
options[:skip_active_record] ? "" :
- <<-GEMFILE.gsub(/^ {12}/, '').strip
+ <<-GEMFILE.strip_heredoc.chomp
# Use #{options[:database]} as the database for ActiveRecord
gem '#{gem_for_database}'
GEMFILE
@@ -182,20 +182,20 @@ module Rails
return if options[:skip_sprockets]
gemfile = if options.dev? || options.edge?
- <<-GEMFILE.gsub(/^ {12}/, '')
+ <<-GEMFILE.strip_heredoc
# Use edge version of sprockets-rails
gem 'sprockets-rails', github: 'rails/sprockets-rails'
# Use SCSS for stylesheets
- gem 'sass-rails', github: 'rails/sass-rails'
+ gem 'sass-rails', github: 'rails/sass-rails'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '~> 1.3'
GEMFILE
else
- <<-GEMFILE.gsub(/^ {12}/, '')
+ <<-GEMFILE.strip_heredoc
# Use SCSS for stylesheets
- gem 'sass-rails', '~> 4.0.0.beta1'
+ gem 'sass-rails', '~> 4.0.0.beta1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '~> 1.3'
@@ -203,34 +203,32 @@ module Rails
end
if options[:skip_javascript]
- gemfile += <<-GEMFILE.gsub(/^ {12}/, '')
+ gemfile += <<-GEMFILE
#{coffee_gemfile_entry}
#{javascript_runtime_gemfile_entry}
GEMFILE
end
- gemfile.strip_heredoc.gsub(/^[ \t]*$/, '')
+ gemfile.gsub(/^[ \t]+/, '')
end
def coffee_gemfile_entry
- gemfile = if options.dev? || options.edge?
- <<-GEMFILE.gsub(/^ {12}/, '')
+ if options.dev? || options.edge?
+ <<-GEMFILE
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', github: 'rails/coffee-rails'
GEMFILE
else
- <<-GEMFILE.gsub(/^ {12}/, '')
+ <<-GEMFILE
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0.beta1'
GEMFILE
end
-
- gemfile.strip_heredoc.gsub(/^[ \t]*$/, '')
end
def javascript_gemfile_entry
unless options[:skip_javascript]
- <<-GEMFILE.gsub(/^ {12}/, '').strip_heredoc
+ <<-GEMFILE.gsub(/^[ \t]+/, '')
#{coffee_gemfile_entry}
#{javascript_runtime_gemfile_entry}
# Use #{options[:javascript]} as the JavaScript library
@@ -248,7 +246,7 @@ module Rails
else
"# gem 'therubyracer', platforms: :ruby"
end
- <<-GEMFILE.gsub(/^ {10}/, '')
+ <<-GEMFILE
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
#{runtime}
GEMFILE