aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/app_rails_loader.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2013-04-11 13:18:16 +0200
committerXavier Noria <fxn@hashref.com>2013-04-11 13:19:16 +0200
commit85de18307127d740d32c42093d39b859a1335eb3 (patch)
tree7df4b86ecdfa3de440c97629334eaedfee9cb685 /railties/lib/rails/app_rails_loader.rb
parent2a07db716957bf1638a84aa3c1f69d26efdbdb7d (diff)
downloadrails-85de18307127d740d32c42093d39b859a1335eb3.tar.gz
rails-85de18307127d740d32c42093d39b859a1335eb3.tar.bz2
rails-85de18307127d740d32c42093d39b859a1335eb3.zip
application loader refactor and test suite complete rewrite
Diffstat (limited to 'railties/lib/rails/app_rails_loader.rb')
-rw-r--r--railties/lib/rails/app_rails_loader.rb55
1 files changed, 27 insertions, 28 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