123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #---
- # Excerpted from "Agile Web Development with Rails",
- # published by The Pragmatic Bookshelf.
- # Copyrights apply to this code. It may not be used to create training material,
- # courses, books, articles, and the like. Contact us if you are in doubt.
- # We make no guarantees that this code is fit for any purpose.
- # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
- #---
- #---
- # Excerpted from "Agile Web Development with Rails, 4rd Ed.",
- # published by The Pragmatic Bookshelf.
- # Copyrights apply to this code. It may not be used to create training material,
- # courses, books, articles, and the like. Contact us if you are in doubt.
- # We make no guarantees that this code is fit for any purpose.
- # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
- #---
- RAILS_ROOT = File.dirname(__FILE__) + "/../"
- RAILS_ENV = ENV['RAILS_ENV'] || 'development'
- # Mocks first.
- ADDITIONAL_LOAD_PATHS = ["#{RAILS_ROOT}/test/mocks/#{RAILS_ENV}"]
- # Then model subdirectories.
- ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/app/models/[_a-z]*"])
- ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/components/[_a-z]*"])
- # Followed by the standard includes.
- ADDITIONAL_LOAD_PATHS.concat %w(
- app
- app/models
- app/controllers
- app/helpers
- app/apis
- components
- config
- lib
- vendor
- vendor/rails/railties
- vendor/rails/railties/lib
- vendor/rails/actionpack/lib
- vendor/rails/activesupport/lib
- vendor/rails/activerecord/lib
- vendor/rails/actionmailer/lib
- vendor/rails/actionwebservice/lib
- ).map { |dir| "#{RAILS_ROOT}/#{dir}" }.select { |dir| File.directory?(dir) }
- # Prepend to $LOAD_PATH
- ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) }
- # Require Rails libraries.
- require 'rubygems' unless File.directory?("#{RAILS_ROOT}/vendor/rails")
- require 'active_support'
- require 'active_record'
- require 'action_controller'
- require 'action_mailer'
- require 'action_web_service'
- # Environment-specific configuration.
- require_dependency "environments/#{RAILS_ENV}"
- ActiveRecord::Base.configurations = File.open("#{RAILS_ROOT}/config/database.yml") { |f| YAML::load(f) }
- ActiveRecord::Base.establish_connection
- # Configure defaults if the included environment did not.
- begin
- RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
- rescue StandardError
- RAILS_DEFAULT_LOGGER = Logger.new(STDERR)
- RAILS_DEFAULT_LOGGER.level = Logger::WARN
- RAILS_DEFAULT_LOGGER.warn(
- "Rails Error: Unable to access log file. Please ensure that log/#{RAILS_ENV}.log exists and is chmod 0666. " +
- "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
- )
- end
- [ActiveRecord, ActionController, ActionMailer].each { |mod| mod::Base.logger ||= RAILS_DEFAULT_LOGGER }
- [ActionController, ActionMailer].each { |mod| mod::Base.template_root ||= "#{RAILS_ROOT}/app/views/" }
- ActionController::Routing::Routes.reload
- Controllers = Dependencies::LoadingModule.root(
- File.join(RAILS_ROOT, 'app', 'controllers'),
- File.join(RAILS_ROOT, 'components')
- )
- # Include your app's configuration here:
|