aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands/runner/runner_command.rb
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2016-09-26 20:28:40 +0200
committerGitHub <noreply@github.com>2016-09-26 20:28:40 +0200
commitc994a893c18c0456fd2a30efe4debfc2b18e2508 (patch)
tree0253b1343a1760dc4701f7d2ee2ff8cdd1d1b290 /railties/lib/rails/commands/runner/runner_command.rb
parenta6da7938017647dd6e19e23d3d47126cb7a3e1fe (diff)
parentc0c73738bd04c86fbcf6d22c961fec0d33aa2bf6 (diff)
downloadrails-c994a893c18c0456fd2a30efe4debfc2b18e2508.tar.gz
rails-c994a893c18c0456fd2a30efe4debfc2b18e2508.tar.bz2
rails-c994a893c18c0456fd2a30efe4debfc2b18e2508.zip
Merge pull request #26414 from rails/rails-commands
Initial Rails Commands Infrastructure
Diffstat (limited to 'railties/lib/rails/commands/runner/runner_command.rb')
-rw-r--r--railties/lib/rails/commands/runner/runner_command.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb
new file mode 100644
index 0000000000..8db6da8759
--- /dev/null
+++ b/railties/lib/rails/commands/runner/runner_command.rb
@@ -0,0 +1,45 @@
+module Rails
+ module Command
+ class RunnerCommand < Base
+ class_option :environment, aliases: "-e", type: :string,
+ default: Rails::Command.environment.dup,
+ desc: "The environment for the runner to operate under (test/development/production)"
+
+ def help
+ super
+ puts self.class.desc
+ end
+
+ def self.banner(*)
+ "#{super} [<'Some.ruby(code)'> | <filename.rb>]"
+ end
+
+ def perform(code_or_file = nil)
+ unless code_or_file
+ help
+ exit 1
+ end
+
+ ENV["RAILS_ENV"] = options[:environment]
+
+ require_application_and_environment!
+ Rails.application.load_runner
+
+ if File.exist?(code_or_file)
+ $0 = code_or_file
+ Kernel.load code_or_file
+ else
+ begin
+ eval(code_or_file, binding, __FILE__, __LINE__)
+ rescue SyntaxError, NameError => error
+ $stderr.puts "Please specify a valid ruby command or the path of a script to run."
+ $stderr.puts "Run '#{self.class.executable} -h' for help."
+ $stderr.puts
+ $stderr.puts error
+ exit 1
+ end
+ end
+ end
+ end
+ end
+end