Sha256: 06f707a9a57325b947a711057d1a367636ea6cb61d9c790cdb44d571aa4622c6

Contents?: true

Size: 1.92 KB

Versions: 94

Compression:

Stored size: 1.92 KB

Contents

require 'optparse'
require 'rbconfig'

options = { environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup }
code_or_file = nil

if ARGV.first.nil?
  ARGV.push "-h"
end

ARGV.clone.options do |opts|
  opts.banner = "Usage: rails runner [options] [<'Some.ruby(code)'> | <filename.rb>]"

  opts.separator ""

  opts.on("-e", "--environment=name", String,
          "Specifies the environment for the runner to operate under (test/development/production).",
          "Default: development") { |v| options[:environment] = v }

  opts.separator ""

  opts.on("-h", "--help",
          "Show this help message.") { $stdout.puts opts; exit }

    opts.separator ""
    opts.separator "Examples: "

    opts.separator "    rails runner 'puts Rails.env'"
    opts.separator "        This runs the code `puts Rails.env` after loading the app"
    opts.separator ""
    opts.separator "    rails runner path/to/filename.rb"
    opts.separator "        This runs the Ruby file located at `path/to/filename.rb` after loading the app"

  if RbConfig::CONFIG['host_os'] !~ /mswin|mingw/
    opts.separator ""
    opts.separator "You can also use runner as a shebang line for your executables:"
    opts.separator "    -------------------------------------------------------------"
    opts.separator "    #!/usr/bin/env #{File.expand_path($0)} runner"
    opts.separator ""
    opts.separator "    Product.all.each { |p| p.price *= 2 ; p.save! }"
    opts.separator "    -------------------------------------------------------------"
  end

  opts.order! { |o| code_or_file ||= o } rescue retry
end

ARGV.delete(code_or_file)

ENV["RAILS_ENV"] = options[:environment]

require APP_PATH
Rails.application.require_environment!
Rails.application.load_runner

if code_or_file.nil?
  $stderr.puts "Run '#{$0} -h' for help."
  exit 1
elsif File.exist?(code_or_file)
  $0 = code_or_file
  Kernel.load code_or_file
else
  eval(code_or_file, binding, __FILE__, __LINE__)
end

Version data entries

94 entries across 90 versions & 9 rubygems

Version Path
railties-4.1.15.rc1 lib/rails/commands/runner.rb
railties-4.2.6.rc1 lib/rails/commands/runner.rb
railties-4.1.14.2 lib/rails/commands/runner.rb
railties-4.2.5.2 lib/rails/commands/runner.rb
activejob-lock-0.0.2 rails/railties/lib/rails/commands/runner.rb
railties-4.2.5.1 lib/rails/commands/runner.rb
railties-4.1.14.1 lib/rails/commands/runner.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/railties-4.1.13/lib/rails/commands/runner.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/runner.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/railties-4.1.13/lib/rails/commands/runner.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/runner.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/railties-4.1.13/lib/rails/commands/runner.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/runner.rb
railties-4.1.14 lib/rails/commands/runner.rb
railties-4.2.5 lib/rails/commands/runner.rb
railties-4.2.5.rc2 lib/rails/commands/runner.rb
railties-4.1.14.rc2 lib/rails/commands/runner.rb
railties-4.2.5.rc1 lib/rails/commands/runner.rb
railties-4.1.14.rc1 lib/rails/commands/runner.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/runner.rb