diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/app_rails_loader.rb | 64 | ||||
-rw-r--r-- | railties/lib/rails/generators/app_base.rb | 12 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/Gemfile | 6 |
3 files changed, 55 insertions, 27 deletions
diff --git a/railties/lib/rails/app_rails_loader.rb b/railties/lib/rails/app_rails_loader.rb index 44f4d3dabc..4a17803f1c 100644 --- a/railties/lib/rails/app_rails_loader.rb +++ b/railties/lib/rails/app_rails_loader.rb @@ -4,34 +4,58 @@ module Rails module AppRailsLoader RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"] 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 self.exec_app_rails - cwd = Dir.pwd + original_cwd = Dir.pwd - exe = find_executable - exe ||= find_executable_in_parent_path - return unless exe + loop do + if exe = find_executable + contents = File.read(exe) - exec RUBY, exe, *ARGV if find_executable - 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_app_rails unless cwd == Dir.pwd - end - rescue SystemCallError - # could not chdir, no problem just return - end + 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 - def self.find_executable - EXECUTABLES.find do |exe| - File.exists?(exe) && File.read(exe) =~ /(APP|ENGINE)_PATH/ + # 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 a executable. + Dir.chdir('..') end end - def self.find_executable_in_parent_path(path = Pathname.new(Dir.pwd)) - EXECUTABLES.find do |exe| - File.exists?(File.join(path, exe)) || !path.root? && find_executable_in_parent_path(path.parent) - end + def self.find_executable + EXECUTABLES.find { |exe| File.exists?(exe) } end end end diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index b53142d20c..b62d1fff14 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -115,7 +115,11 @@ module Rails end def database_gemfile_entry - options[:skip_active_record] ? "" : "gem '#{gem_for_database}'" + options[:skip_active_record] ? "" : + <<-GEMFILE.gsub(/^ {12}/, '').strip + # Use #{options[:database]} as the database for ActiveRecord + gem '#{gem_for_database}' + GEMFILE end def include_all_railties? @@ -185,7 +189,7 @@ module Rails # Use SCSS for stylesheets gem 'sass-rails', github: 'rails/sass-rails' - # To use Uglifier as compressor for JavaScript assets + # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '~> 1.3' GEMFILE else @@ -193,7 +197,7 @@ module Rails # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.0.beta1' - # To use Uglifier as compressor for JavaScript assets + # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '~> 1.3' GEMFILE end @@ -229,7 +233,7 @@ module Rails <<-GEMFILE.gsub(/^ {12}/, '').strip_heredoc #{coffee_gemfile_entry} #{javascript_runtime_gemfile_entry} - + # Use #{options[:javascript]} as the JavaScript library gem '#{options[:javascript]}-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 07cf31dd83..1842e09bae 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -17,16 +17,16 @@ end # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 1.0.1' -# To use ActiveModel has_secure_password +# Use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' # Use unicorn as the app server # gem 'unicorn' -# Deploy with Capistrano +# Use Capistrano for deployment # gem 'capistrano', group: :development <% unless defined?(JRUBY_VERSION) -%> -# To use debugger +# Use debugger # gem 'debugger', group: [:development, :test] <% end -%> |