2013-01-06 18:13:47 -05:00
|
|
|
require 'pathname'
|
|
|
|
|
|
|
|
module Rails
|
|
|
|
module AppRailsLoader
|
2014-07-07 21:05:30 -04:00
|
|
|
extend self
|
|
|
|
|
2013-09-09 11:06:02 -04:00
|
|
|
RUBY = Gem.ruby
|
2013-02-22 14:09:43 -05:00
|
|
|
EXECUTABLES = ['bin/rails', 'script/rails']
|
2013-04-11 07:18:16 -04:00
|
|
|
BUNDLER_WARNING = <<EOS
|
2013-04-09 19:49:01 -04:00
|
|
|
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
|
|
|
|
like any other source code, rather than stubs that are generated on demand.
|
|
|
|
|
|
|
|
Here's how to upgrade:
|
|
|
|
|
|
|
|
bundle config --delete bin # Turn off Bundler's stub generator
|
|
|
|
rake rails:update:bin # Use the new Rails 4 executables
|
|
|
|
git add bin # Add bin/ to source control
|
|
|
|
|
|
|
|
You may need to remove bin/ from your .gitignore as well.
|
|
|
|
|
|
|
|
When you install a gem whose executable you want to use in your app,
|
|
|
|
generate it and add it to source control:
|
|
|
|
|
|
|
|
bundle binstubs some-gem-name
|
|
|
|
git add bin/new-executable
|
|
|
|
|
2013-04-11 07:18:16 -04:00
|
|
|
EOS
|
|
|
|
|
2014-07-07 21:05:30 -04:00
|
|
|
def exec_app_rails
|
2013-04-11 07:18:16 -04:00
|
|
|
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
|
2013-04-09 19:49:01 -04:00
|
|
|
|
2013-04-11 07:18:16 -04:00
|
|
|
# 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?
|
|
|
|
|
2013-09-13 04:44:35 -04:00
|
|
|
# Otherwise keep moving upwards in search of an executable.
|
2013-04-11 07:18:16 -04:00
|
|
|
Dir.chdir('..')
|
2013-01-06 18:13:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-07 21:05:30 -04:00
|
|
|
def find_executable
|
2014-01-24 13:00:31 -05:00
|
|
|
EXECUTABLES.find { |exe| File.file?(exe) }
|
2013-01-06 18:13:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|