environment.rb 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #---
  2. # Excerpted from "Agile Web Development with Rails",
  3. # published by The Pragmatic Bookshelf.
  4. # Copyrights apply to this code. It may not be used to create training material,
  5. # courses, books, articles, and the like. Contact us if you are in doubt.
  6. # We make no guarantees that this code is fit for any purpose.
  7. # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
  8. #---
  9. RAILS_ROOT = File.dirname(__FILE__) + "/../"
  10. RAILS_ENV = ENV['RAILS_ENV'] || 'development'
  11. # Mocks first.
  12. ADDITIONAL_LOAD_PATHS = ["#{RAILS_ROOT}/test/mocks/#{RAILS_ENV}"]
  13. # Then model subdirectories.
  14. ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/app/models/[_a-z]*"])
  15. ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/components/[_a-z]*"])
  16. # Followed by the standard includes.
  17. ADDITIONAL_LOAD_PATHS.concat %w(
  18. app
  19. app/models
  20. app/controllers
  21. app/helpers
  22. app/apis
  23. components
  24. config
  25. lib
  26. vendor
  27. vendor/rails/railties
  28. vendor/rails/railties/lib
  29. vendor/rails/actionpack/lib
  30. vendor/rails/activesupport/lib
  31. vendor/rails/activerecord/lib
  32. vendor/rails/actionmailer/lib
  33. vendor/rails/actionwebservice/lib
  34. ).map { |dir| "#{RAILS_ROOT}/#{dir}" }.select { |dir| File.directory?(dir) }
  35. # Prepend to $LOAD_PATH
  36. ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) }
  37. # Require Rails libraries.
  38. require 'rubygems' unless File.directory?("#{RAILS_ROOT}/vendor/rails")
  39. require 'active_support'
  40. require 'active_record'
  41. require 'action_controller'
  42. require 'action_mailer'
  43. require 'action_web_service'
  44. # Environment-specific configuration.
  45. require_dependency "environments/#{RAILS_ENV}"
  46. ActiveRecord::Base.configurations = File.open("#{RAILS_ROOT}/config/database.yml") { |f| YAML::load(f) }
  47. ActiveRecord::Base.establish_connection
  48. # Configure defaults if the included environment did not.
  49. begin
  50. RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
  51. rescue StandardError
  52. RAILS_DEFAULT_LOGGER = Logger.new(STDERR)
  53. RAILS_DEFAULT_LOGGER.level = Logger::WARN
  54. RAILS_DEFAULT_LOGGER.warn(
  55. "Rails Error: Unable to access log file. Please ensure that log/#{RAILS_ENV}.log exists and is chmod 0666. " +
  56. "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
  57. )
  58. end
  59. [ActiveRecord, ActionController, ActionMailer].each { |mod| mod::Base.logger ||= RAILS_DEFAULT_LOGGER }
  60. [ActionController, ActionMailer].each { |mod| mod::Base.template_root ||= "#{RAILS_ROOT}/app/views/" }
  61. ActionController::Routing::Routes.reload
  62. Controllers = Dependencies::LoadingModule.root(
  63. File.join(RAILS_ROOT, 'app', 'controllers'),
  64. File.join(RAILS_ROOT, 'components')
  65. )
  66. # Include your app's configuration here: