environment.rb 3.1 KB

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