aboutsummaryrefslogtreecommitdiffstats
path: root/railties/bin
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2010-02-25 08:32:37 -0800
committerDavid Heinemeier Hansson <david@loudthinking.com>2010-02-25 08:32:37 -0800
commitbf0f14579aa793f2ab29ec092c517d04e702dbe3 (patch)
treec8166659b1239a8b70823b36d140418f66749830 /railties/bin
parenta524d42acc8f8340b68c3f67fba1ca754057b261 (diff)
downloadrails-bf0f14579aa793f2ab29ec092c517d04e702dbe3.tar.gz
rails-bf0f14579aa793f2ab29ec092c517d04e702dbe3.tar.bz2
rails-bf0f14579aa793f2ab29ec092c517d04e702dbe3.zip
let the rails command recurse upwards looking for script/rails, and exec ruby on it for better portability [Xavier Noria] (Closes #4008)
Diffstat (limited to 'railties/bin')
-rwxr-xr-xrailties/bin/rails37
1 files changed, 28 insertions, 9 deletions
diff --git a/railties/bin/rails b/railties/bin/rails
index 72c47b533f..173f122445 100755
--- a/railties/bin/rails
+++ b/railties/bin/rails
@@ -1,11 +1,30 @@
-if File.exists?(Dir.getwd + '/script/rails')
- exec(Dir.getwd + '/script/rails', *ARGV)
-else
- railties_path = File.expand_path('../../lib', __FILE__)
- $:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(railties_path)
+require 'rbconfig'
- require 'rails/ruby_version_check'
- Signal.trap("INT") { puts; exit }
+module Rails
+ module ScriptRailsLoader
+ RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
+ SCRIPT_RAILS = File.join('script', 'rails')
- require 'rails/commands/application'
-end \ No newline at end of file
+ def self.exec_script_rails!
+ cwd = Dir.pwd
+ exec RUBY, SCRIPT_RAILS, *ARGV if File.exists?(SCRIPT_RAILS)
+ Dir.chdir("..") do
+ # Recurse in a chdir block: if the search fails we want to be sure
+ # the application is generated in the original working directory.
+ exec_script_rails! unless cwd == Dir.pwd
+ end
+ rescue SystemCallError
+ # could not chdir, no problem just return
+ end
+ end
+end
+
+Rails::ScriptRailsLoader.exec_script_rails!
+
+railties_path = File.expand_path('../../lib', __FILE__)
+$:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(railties_path)
+
+require 'rails/ruby_version_check'
+Signal.trap("INT") { puts; exit }
+
+require 'rails/commands/application'