Sha256: 7ad805f029eff6be88702dbec0ef67121bf10226d888aa7d731b00c02b33d36c

Contents?: true

Size: 1.58 KB

Versions: 25

Compression:

Stored size: 1.58 KB

Contents

require 'optparse'

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

ARGV.clone.options do |opts|
  script_name = File.basename($0)
  opts.banner = "Usage: #{$0} [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.") { $stderr.puts opts; exit }

  if RUBY_PLATFORM !~ /(:?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)}"
    opts.separator ""
    opts.separator "Product.find(: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]
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)

require RAILS_ROOT + '/config/environment'

begin
  if code_or_file.nil?
    $stderr.puts "Run '#{$0} -h' for help."
    exit 1
  elsif File.exist?(code_or_file)
    eval(File.read(code_or_file), nil, code_or_file)
  else
    eval(code_or_file)
  end
ensure
  if defined? Rails
    Rails.logger.flush if Rails.logger.respond_to?(:flush)
  end
end

Version data entries

25 entries across 25 versions & 5 rubygems

Version Path
rails-2.3.18 lib/commands/runner.rb
rails-2.3.17 lib/commands/runner.rb
rails-2.3.16 lib/commands/runner.rb
rails-2.3.15 lib/commands/runner.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rails-2.3.14/lib/commands/runner.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/rails-2.3.12/lib/commands/runner.rb
rails-2.3.14 lib/commands/runner.rb
kajam-1.0.3.rc2 vendor/rails/railties/lib/commands/runner.rb
rails-2.3.12 lib/commands/runner.rb
radiant-1.0.0.rc2 vendor/rails/railties/lib/commands/runner.rb
radiant-1.0.0.rc1 vendor/rails/railties/lib/commands/runner.rb
rails-2.3.11 lib/commands/runner.rb
radiantcms-couchrest_model-0.1.4 vendor/rails/railties/lib/commands/runner.rb
radiantcms-couchrest_model-0.1.3 vendor/rails/railties/lib/commands/runner.rb
radiantcms-couchrest_model-0.1.2 vendor/rails/railties/lib/commands/runner.rb
radiantcms-couchrest_model-0.1.1 vendor/rails/railties/lib/commands/runner.rb
radiantcms-couchrest_model-0.1 vendor/rails/railties/lib/commands/runner.rb
rails-2.3.10 lib/commands/runner.rb
rails-2.3.9 lib/commands/runner.rb
rails-2.3.9.pre lib/commands/runner.rb