Module: Rails::AppLoader

Extended by:
AppLoader
Included in:
AppLoader
Defined in:
lib/rails/app_loader.rb

Overview

:nodoc:

Constant Summary collapse

RUBY =
Gem.ruby
EXECUTABLES =
["bin/rails", "script/rails"]
BUNDLER_WARNING =
"Looks like your app's ./bin/rails is a stub that was generated by Bundler.\n\nIn Rails \#{Rails::VERSION::MAJOR}, your app's bin/ directory contains executables that are versioned\nlike any other source code, rather than stubs that are generated on demand.\n\nHere's how to upgrade:\n\n  bundle config --delete bin    # Turn off Bundler's stub generator\n  rails app:update:bin          # Use the new Rails 5 executables\n  git add bin                   # Add bin/ to source control\n\nYou may need to remove bin/ from your .gitignore as well.\n\nWhen you install a gem whose executable you want to use in your app,\ngenerate it and add it to source control:\n\n  bundle binstubs some-gem-name\n  git add bin/new-executable\n\n"

Instance Method Summary collapse

Instance Method Details

#exec_appObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rails/app_loader.rb', line 32

def exec_app
  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

    # 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) && return if Pathname.new(Dir.pwd).root?

    # Otherwise keep moving upwards in search of an executable.
    Dir.chdir("..")
  end
end

#find_executableObject



60
61
62
# File 'lib/rails/app_loader.rb', line 60

def find_executable
  EXECUTABLES.find { |exe| File.file?(exe) }
end