Sha256: ae1d6a4a78f3019114c381975393ed5f3949a506833dc734beb58a55749467e5

Contents?: true

Size: 1.92 KB

Versions: 33

Compression:

Stored size: 1.92 KB

Contents

require 'pathname'

module Rails
  module AppRailsLoader # :nodoc:
    extend self

    RUBY = Gem.ruby
    EXECUTABLES = ['bin/rails', 'script/rails']
    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
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

EOS

    def 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

        # 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 an executable.
        Dir.chdir('..')
      end
    end

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

Version data entries

33 entries across 33 versions & 6 rubygems

Version Path
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/railties-4.2.4/lib/rails/app_rails_loader.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/railties-4.2.4/lib/rails/app_rails_loader.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/railties-4.2.4/lib/rails/app_rails_loader.rb
railties-4.2.5 lib/rails/app_rails_loader.rb
railties-4.2.5.rc2 lib/rails/app_rails_loader.rb
railties-4.2.5.rc1 lib/rails/app_rails_loader.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/app_rails_loader.rb
railties-4.2.4 lib/rails/app_rails_loader.rb
railties-4.2.4.rc1 lib/rails/app_rails_loader.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/railties-4.2.3/lib/rails/app_rails_loader.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/railties-4.2.3/lib/rails/app_rails_loader.rb
railties-4.2.3 lib/rails/app_rails_loader.rb
railties-4.2.3.rc1 lib/rails/app_rails_loader.rb