aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--railties/CHANGELOG.md5
-rw-r--r--railties/lib/rails/commands/runner/USAGE3
-rw-r--r--railties/lib/rails/commands/runner/runner_command.rb6
-rw-r--r--railties/test/application/configuration_test.rb28
-rw-r--r--railties/test/application/runner_test.rb8
6 files changed, 36 insertions, 16 deletions
diff --git a/README.md b/README.md
index 7e25a0c8f1..8bd066cb27 100644
--- a/README.md
+++ b/README.md
@@ -75,6 +75,8 @@ and may also be used independently outside Rails.
## Contributing
+[![Code Triage Badge](https://www.codetriage.com/rails/rails/badges/users.svg)](https://www.codetriage.com/rails/rails)
+
We encourage you to contribute to Ruby on Rails! Please check out the
[Contributing to Ruby on Rails guide](http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html) for guidelines about how to proceed. [Join us!](http://contributors.rubyonrails.org)
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index f720b7caab..45e1f5f3ea 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Support `-` as a platform-agnostic way to run a script from stdin with
+ `rails runner`
+
+ *Cody Cutrer*
+
* Add `bootsnap` to default `Gemfile`.
*Burke Libbey*
diff --git a/railties/lib/rails/commands/runner/USAGE b/railties/lib/rails/commands/runner/USAGE
index b2a6e8493d..24b60037f0 100644
--- a/railties/lib/rails/commands/runner/USAGE
+++ b/railties/lib/rails/commands/runner/USAGE
@@ -8,6 +8,9 @@ Run the Ruby file located at `path/to/filename.rb` after loading the app:
<%= executable %> path/to/filename.rb
+Run the Ruby script read from stdin after loading the app:
+ <%= executable %> -
+
<% unless Gem.win_platform? %>
You can also use the runner command as a shebang line for your executables:
diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb
index 6864a9726b..c931fc2152 100644
--- a/railties/lib/rails/commands/runner/runner_command.rb
+++ b/railties/lib/rails/commands/runner/runner_command.rb
@@ -13,7 +13,7 @@ module Rails
end
def self.banner(*)
- "#{super} [<'Some.ruby(code)'> | <filename.rb>]"
+ "#{super} [<'Some.ruby(code)'> | <filename.rb> | -]"
end
def perform(code_or_file = nil, *command_argv)
@@ -29,7 +29,9 @@ module Rails
ARGV.replace(command_argv)
- if File.exist?(code_or_file)
+ if code_or_file == "-"
+ eval($stdin.read, binding, "stdin")
+ elsif File.exist?(code_or_file)
$0 = code_or_file
Kernel.load code_or_file
else
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 47bb806f84..9f62ca8eb8 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -1130,7 +1130,7 @@ module ApplicationTests
app "development"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters
@@ -1141,7 +1141,7 @@ module ApplicationTests
test "config.action_controller.always_permitted_parameters are: controller, action by default" do
app "development"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal %w(controller action), ActionController::Parameters.always_permitted_parameters
end
@@ -1153,7 +1153,7 @@ module ApplicationTests
app "development"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal %w( controller action format ), ActionController::Parameters.always_permitted_parameters
end
@@ -1177,7 +1177,7 @@ module ApplicationTests
app "development"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters
@@ -1188,7 +1188,7 @@ module ApplicationTests
test "config.action_controller.action_on_unpermitted_parameters is :log by default on development" do
app "development"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters
end
@@ -1196,7 +1196,7 @@ module ApplicationTests
test "config.action_controller.action_on_unpermitted_parameters is :log by default on test" do
app "test"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters
end
@@ -1204,7 +1204,7 @@ module ApplicationTests
test "config.action_controller.action_on_unpermitted_parameters is false by default on production" do
app "production"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal false, ActionController::Parameters.action_on_unpermitted_parameters
end
@@ -1223,7 +1223,7 @@ module ApplicationTests
app "development"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal true, ActionController::Parameters.permit_all_parameters
end
@@ -1234,7 +1234,7 @@ module ApplicationTests
app "development"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal [], ActionController::Parameters.always_permitted_parameters
end
@@ -1245,7 +1245,7 @@ module ApplicationTests
app "development"
- lazy_load { ActionController::Base }
+ force_lazy_load_hooks { ActionController::Base }
assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters
end
@@ -1596,7 +1596,7 @@ module ApplicationTests
RUBY
app "development"
- lazy_load { Post }
+ force_lazy_load_hooks { Post }
assert_not ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer
end
@@ -1608,7 +1608,7 @@ module ApplicationTests
RUBY
app "development"
- lazy_load { Post }
+ force_lazy_load_hooks { Post }
assert ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer
end
@@ -1626,7 +1626,7 @@ module ApplicationTests
RUBY
app "development"
- lazy_load { Post }
+ force_lazy_load_hooks { Post }
assert ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer
end
@@ -1739,7 +1739,7 @@ module ApplicationTests
end
private
- def lazy_load
+ def force_lazy_load_hooks
yield # Tasty clarifying sugar, homie! We only need to reference a constant to load it.
end
end
diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb
index 0c45bc398a..81f717b2c3 100644
--- a/railties/test/application/runner_test.rb
+++ b/railties/test/application/runner_test.rb
@@ -84,6 +84,14 @@ module ApplicationTests
assert_match %w( a b ).to_s, Dir.chdir(app_path) { `bin/rails runner "bin/program_name.rb" a b` }
end
+ def test_should_run_stdin
+ app_file "bin/count_users.rb", <<-SCRIPT
+ puts User.count
+ SCRIPT
+
+ assert_match "42", Dir.chdir(app_path) { `cat bin/count_users.rb | bin/rails runner -` }
+ end
+
def test_with_hook
add_to_config <<-RUBY
runner do |app|