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

root/tools/conductor/config/environment.rb

Revision 1050, 2.0 kB (checked in by bitsweat, 4 years ago)

Don't establish db connection if no configuration is provided.

Line 
1 RAILS_ROOT = File.dirname(__FILE__) + "/../"
2 RAILS_ENV  = ENV['RAILS_ENV'] || 'development'
3
4
5 # Mocks first.
6 ADDITIONAL_LOAD_PATHS = ["#{RAILS_ROOT}/test/mocks/#{RAILS_ENV}"]
7
8 # Then model subdirectories.
9 ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/app/models/[_a-z]*"])
10 ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/components/[_a-z]*"])
11
12 # Followed by the standard includes.
13 ADDITIONAL_LOAD_PATHS.concat %w(
14   app
15   app/models
16   app/controllers
17   app/helpers
18   app/apis
19   config
20   lib
21 ).map { |dir| "#{RAILS_ROOT}/#{dir}" }
22
23 # Prepend to $LOAD_PATH
24 ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) }
25
26
27 # Require Rails gems.
28 require 'rubygems'
29 require_gem 'activesupport'
30 require_gem 'activerecord'
31 require_gem 'actionpack'
32 require_gem 'actionmailer'
33 require_gem 'actionwebservice'
34 require_gem 'rails'
35
36
37 # Environment-specific configuration.
38 require_dependency "environments/#{RAILS_ENV}"
39 ActiveRecord::Base.configurations = YAML::load(File.open("#{RAILS_ROOT}/config/database.yml"))
40 if ActiveRecord::Base.configurations[RAILS_ENV]
41   ActiveRecord::Base.establish_connection
42 end
43
44
45 # Configure defaults if the included environment did not.
46 begin
47   RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
48 rescue StandardError
49   RAILS_DEFAULT_LOGGER = Logger.new(STDERR)
50   RAILS_DEFAULT_LOGGER.level = Logger::WARN
51   RAILS_DEFAULT_LOGGER.warn(
52     "Rails Error: Unable to access log file. Please ensure that log/#{RAILS_ENV}.log exists and is chmod 0666. " +
53     "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
54   )
55 end
56
57 [ActiveRecord, ActionController, ActionMailer].each { |mod| mod::Base.logger ||= RAILS_DEFAULT_LOGGER }
58 [ActionController, ActionMailer].each { |mod| mod::Base.template_root ||= "#{RAILS_ROOT}/app/views/" }
59 ActionController::Routing::Routes.reload
60
61 Controllers = Dependencies::LoadingModule.root(
62   File.join(RAILS_ROOT, 'app', 'controllers'),
63   File.join(RAILS_ROOT, 'components')
64 )
65
66 # Include your app's configuration here:
Note: See TracBrowser for help on using the browser.