2010-06-10 14:00:58 -04:00
|
|
|
require 'pathname'
|
|
|
|
|
|
|
|
module Rails
|
|
|
|
module ScriptRailsLoader
|
|
|
|
RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
|
|
|
|
SCRIPT_RAILS = File.join('script', 'rails')
|
|
|
|
|
|
|
|
def self.exec_script_rails!
|
|
|
|
cwd = Dir.pwd
|
2010-07-26 17:35:54 -04:00
|
|
|
return unless in_rails_application? || in_rails_application_subdirectory?
|
2010-06-10 14:00:58 -04:00
|
|
|
exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application?
|
|
|
|
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
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-06-10 14:00:58 -04:00
|
|
|
def self.in_rails_application?
|
2010-07-26 17:35:54 -04:00
|
|
|
File.exists?(SCRIPT_RAILS)
|
2010-06-10 14:00:58 -04:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-06-10 14:00:58 -04:00
|
|
|
def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
|
|
|
|
File.exists?(File.join(path, SCRIPT_RAILS)) || !path.root? && in_rails_application_subdirectory?(path.parent)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|