Skip to content

Instantly share code, notes, and snippets.

@AquaGeek
Created May 14, 2011 02:18
Show Gist options
  • Save AquaGeek/971661 to your computer and use it in GitHub Desktop.
Save AquaGeek/971661 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #4249
From 9e22cc9cde69e8da290b56ad3e99b3cec72ecad8 Mon Sep 17 00:00:00 2001
From: rohit <[email protected]>
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
From 6c3fc3fe41381348ca737b3d4d7c688a91642af6 Mon Sep 17 00:00:00 2001
From: rohit <[email protected]>
Date: Thu, 16 Sep 2010 09:32:33 +0530
Subject: [PATCH] Fix output of 'rails runner --help' [#4249 state:open]
---
railties/lib/rails/commands/runner.rb | 2 +-
railties/test/application/runner_test.rb | 5 +++++
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index 54a9e6e..8100186 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -23,7 +23,7 @@ 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)}"
+ opts.separator "#!/usr/bin/env #{File.expand_path($0)} runner"
opts.separator ""
opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }"
opts.separator "-------------------------------------------------------------"
diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb
index 07a3d94..7e99ff6 100644
--- a/railties/test/application/runner_test.rb
+++ b/railties/test/application/runner_test.rb
@@ -18,6 +18,11 @@ module ApplicationTests
MODEL
end
+ def test_should_include_runner_in_shebang_line_in_help
+ # redirect stderr to stdout as backticks don't capture stderr
+ assert_match "/rails runner", Dir.chdir(app_path) { `bundle exec rails runner --help 2>&1` }
+ end
+
def test_should_run_ruby_statement
assert_match "42", Dir.chdir(app_path) { `bundle exec rails runner "puts User.count"` }
end
--
1.7.2.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment