Guest User

Load additional files when opening scripts/console

a guest
Nov 22nd, 2012
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #rails/railties/lib/commands/console.rb
  2.  
  3. # This file is patched by the madnificent.  The code between # and # has been added
  4. # Editor: madnificent
  5. # Date:   2008-05-19
  6. # Message:The system now loads all .rb files in console_scripts when script/console is loaded.  Here you go olafski :D
  7.  
  8. #
  9. require 'find'
  10. #
  11.  
  12. irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
  13.  
  14. #
  15. LOAD_HOOK_DIRECTORY = "#{RAILS_ROOT}/console_scripts"
  16. #
  17.  
  18. require 'optparse'
  19. options = { :sandbox => false, :irb => irb }
  20. OptionParser.new do |opt|
  21.   opt.banner = "Usage: console [environment] [options]"
  22.   opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v }
  23.   opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v }
  24.   opt.parse!(ARGV)
  25. end
  26.  
  27. libs =  " -r irb/completion"
  28. libs << %( -r "#{RAILS_ROOT}/config/environment")
  29. libs << " -r console_app"
  30. libs << " -r console_sandbox" if options[:sandbox]
  31. libs << " -r console_with_helpers"
  32.  
  33. #
  34. Find.find( LOAD_HOOK_DIRECTORY ) do |filename|
  35.   if filename =~ /\.rb$/
  36.     puts "Adding #{filename} to load-path"
  37.     libs << " -r #{filename}"
  38.   end
  39. end
  40. #
  41.  
  42. ENV['RAILS_ENV'] = case ARGV.first
  43.   when "p": "production"
  44.   when "d": "development"
  45.   when "t": "test"
  46.   else
  47.     ARGV.first || ENV['RAILS_ENV'] || 'development'
  48. end
  49.  
  50. if options[:sandbox]
  51.   puts "Loading #{ENV['RAILS_ENV']} environment in sandbox (Rails #{Rails::VERSION::STRING})"
  52.   puts "Any modifications you make will be rolled back on exit"
  53. else
  54.   puts "Loading #{ENV['RAILS_ENV']} environment (Rails #{Rails::VERSION::STRING})"
  55. end
  56. exec "#{options[:irb]} #{libs} --simple-prompt"
  57.  
  58. #{RAILS_ROOT}/console_scripts/enable_sql_logging.rb
  59.  
  60. def log_to(stream=STDOUT, colorize=true)
  61.   ActiveRecord::Base.logger = Logger.new(stream)
  62.   ActiveRecord::Base.clear_active_connections!
  63.   ActiveRecord::Base.colorize_logging = colorize
  64. end
  65. log_to
RAW Paste Data