Skip to content
Browse files

Detect rbenv and update the shebang

  • Loading branch information...
1 parent f34c27a commit 7173c4f931c9026bd3bc0b644d93dae744433f09 @wycats wycats committed Dec 22, 2012
Showing with 18 additions and 1 deletion.
  1. +8 −1 railties/lib/rails/generators/app_base.rb
  2. +10 −0 railties/test/generators/shared_generator_tests.rb
View
9 railties/lib/rails/generators/app_base.rb
@@ -261,7 +261,14 @@ def bundle_command(command)
end
def run_bundle
- bundle_command('install --binstubs') unless options[:skip_gemfile] || options[:skip_bundle] || options[:pretend]
+ command = "install --binstubs"
+ command << " --shebang ruby-local-exec" if detect_ruby_local_exec
+
+ bundle_command(command) unless options[:skip_gemfile] || options[:skip_bundle] || options[:pretend]
+ end
+
+ def detect_ruby_local_exec
+ ENV["PATH"].split(":").find { |path| File.file?(File.join(path, "ruby-local-exec")) }
end
def empty_directory_with_keep_file(destination, config = {})
View
10 railties/test/generators/shared_generator_tests.rb
@@ -31,6 +31,16 @@ def test_generation_runs_bundle_install
quietly { generator.invoke_all }
end
+ def test_generation_runs_bundle_install_with_shebang_if_needed
+ original_path = ENV["PATH"]
+ ENV["PATH"] = ENV["PATH"] + ":" + File.expand_path("../../fixtures/path", __FILE__)
+
+ generator([destination_root]).expects(:bundle_command).with('install --binstubs --shebang ruby-local-exec').once
+ quietly { generator.invoke_all }
+ ensure
+ ENV["PATH"] = original_path
+ end
+
def test_plugin_new_generate_pretend
run_generator ["testapp", "--pretend"]
default_files.each{ |path| assert_no_file File.join("testapp",path) }

2 comments on commit 7173c4f

@mislav
Ruby on Rails member
mislav commented on 7173c4f Dec 26, 2012

Sam has spoken; I think we can safely revert this and a562f9f

@jeremy
Ruby on Rails member
jeremy commented on 7173c4f Dec 27, 2012

This commit wasn't meant to fix #!/usr/bin/env ruby shebangs; they weren't broken. It's so app executables needn't depend on the current working dir. Having to change to the app dir to do anything is a hassle for cron jobs, process supervisors, ad hoc script invocations - everything! /cc @sstephenson

Please sign in to comment.
Something went wrong with that request. Please try again.