From 9e22cc9cde69e8da290b56ad3e99b3cec72ecad8 Mon Sep 17 00:00:00 2001 From: rohit Date: Fri, 28 Jan 2011 16:24:49 +0530 Subject: [PATCH] Add a wrapper for rails runner [#4249 state:committed] --- railties/lib/rails/commands/runner.rb | 5 ++++- .../generators/rails/app/templates/script/runner | 4 ++++ railties/test/application/runner_test.rb | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 railties/lib/rails/generators/rails/app/templates/script/runner diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index 1a91d47..f87c30d 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -23,10 +23,13 @@ ARGV.clone.options do |opts| opts.separator "" opts.separator "You can also use runner as a shebang line for your scripts like this:" opts.separator "-------------------------------------------------------------" - opts.separator "#!/usr/bin/env #{File.expand_path($0)} runner" + opts.separator "#!/usr/bin/env #{File.dirname(File.expand_path($0))}/runner" opts.separator "" opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }" opts.separator "-------------------------------------------------------------" + opts.separator "" + opts.separator "Note: You should use the wrapper provided in the script folder -- as" + opts.separator "suggested above -- to avoid issues with some platforms." end opts.order! { |o| code_or_file ||= o } rescue retry diff --git a/railties/lib/rails/generators/rails/app/templates/script/runner b/railties/lib/rails/generators/rails/app/templates/script/runner new file mode 100644 index 0000000..c70dc77 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/script/runner @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +path_to_rails = File.dirname(File.expand_path(__FILE__)) +exec("#{path_to_rails}/rails runner #{ARGV[0]}") \ No newline at end of file diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 292d1e2..51cd69e 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -19,7 +19,7 @@ module ApplicationTests end def test_should_include_runner_in_shebang_line_in_help - assert_match "/rails runner", Dir.chdir(app_path) { `bundle exec rails runner --help` } + assert_match "/runner", Dir.chdir(app_path) { `bundle exec rails runner --help` } end def test_should_run_ruby_statement -- 1.7.1