Sha256: e9d71bf612fd3eed74ac808079fe8382c8cf809c012905ab7d8b4047d51eb079

Contents?: true

Size: 1.51 KB

Versions: 141

Compression:

Stored size: 1.51 KB

Contents

require 'optparse'
require 'rbconfig'

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

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

ARGV.clone.options do |opts|
  script_name = File.basename($0)
  opts.banner = "Usage: runner [options] ('Some.ruby(code)' or a filename)"

  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 }

  if RbConfig::CONFIG['host_os'] !~ /mswin|mingw/
    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 ""
    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!

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

Version data entries

141 entries across 102 versions & 19 rubygems

Version Path
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/railties-3.2.12/lib/rails/commands/runner.rb
swipe-rails-0.0.5 vendor/bundle/gems/railties-3.2.13/lib/rails/commands/runner.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/railties-3.2.12/lib/rails/commands/runner.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/runner.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/railties-3.2.12/lib/rails/commands/runner.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/runner.rb
challah-1.0.0.beta3 vendor/bundle/gems/railties-3.2.13/lib/rails/commands/runner.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/runner.rb
challah-1.0.0.beta2 vendor/bundle/gems/railties-3.2.13/lib/rails/commands/runner.rb
challah-1.0.0.beta vendor/bundle/gems/railties-3.2.11/lib/rails/commands/runner.rb
challah-1.0.0.beta vendor/bundle/gems/railties-3.2.13/lib/rails/commands/runner.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/runner.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/runner.rb