3 options
= { :environment => (ENV['RAILS_ENV'] || "development").dup
}
6 ARGV.clone
.options
do |opts
|
7 script_name
= File
.basename($0)
8 opts
.banner
= "Usage: #{$0} [options] ('Some.ruby(code)' or a filename)"
12 opts
.on("-e", "--environment=name", String
,
13 "Specifies the environment for the runner to operate under (test/development/production).",
14 "Default: development") { |v
| options
[:environment] = v
}
18 opts
.on("-h", "--help",
19 "Show this help message.") { $stderr.puts opts
; exit
}
21 if RUBY_PLATFORM !~
/mswin/
23 opts
.separator
"You can also use runner as a shebang line for your scripts like this:"
24 opts
.separator
"-------------------------------------------------------------"
25 opts
.separator
"#!/usr/bin/env #{File.expand_path($0)}"
27 opts
.separator
"Product.find(:all).each { |p| p.price *= 2 ; p.save! }"
28 opts
.separator
"-------------------------------------------------------------"
31 opts
.order
! { |o
| code_or_file
||= o
} rescue retry
34 ARGV.delete(code_or_file
)
36 ENV["RAILS_ENV"] = options
[:environment]
37 RAILS_ENV
.replace(options
[:environment]) if defined?(RAILS_ENV
)
39 require RAILS_ROOT
+ '/config/environment'
42 $stderr.puts
"Run '#{$0} -h' for help."
44 elsif File
.exist
?(code_or_file
)
45 eval(File
.read(code_or_file
), nil, code_or_file
)