Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/trunk/railties/lib/commands/console.rb

Revision 8431, 1.1 kB (checked in by bitsweat, 9 months ago)

Ruby 1.9 compatibility. References #1689.

Line 
1 irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
2
3 require 'optparse'
4 options = { :sandbox => false, :irb => irb }
5 OptionParser.new do |opt|
6   opt.banner = "Usage: console [environment] [options]"
7   opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v }
8   opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v }
9   opt.parse!(ARGV)
10 end
11
12 libs =  " -r irb/completion"
13 libs << %( -r "#{RAILS_ROOT}/config/environment")
14 libs << " -r console_app"
15 libs << " -r console_sandbox" if options[:sandbox]
16 libs << " -r console_with_helpers"
17
18 ENV['RAILS_ENV'] = case ARGV.first
19   when "p"; "production"
20   when "d"; "development"
21   when "t"; "test"
22   else
23     ARGV.first || ENV['RAILS_ENV'] || 'development'
24 end
25
26 if options[:sandbox]
27   puts "Loading #{ENV['RAILS_ENV']} environment in sandbox (Rails #{Rails::VERSION::STRING})"
28   puts "Any modifications you make will be rolled back on exit"
29 else
30   puts "Loading #{ENV['RAILS_ENV']} environment (Rails #{Rails::VERSION::STRING})"
31 end
32 exec "#{options[:irb]} #{libs} --simple-prompt"
Note: See TracBrowser for help on using the browser.