diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-20 22:41:35 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-20 22:41:35 +0000 |
commit | 20e3cfe52d294893ad46307440e4acf1f02165ea (patch) | |
tree | b555bce70a9841d06b731eb8fe76697cd8c708d7 /railties/environments/environment.rb | |
parent | a61360688cd0e1f43f523866384d0d0796a4ea73 (diff) | |
download | rails-20e3cfe52d294893ad46307440e4acf1f02165ea.tar.gz rails-20e3cfe52d294893ad46307440e4acf1f02165ea.tar.bz2 rails-20e3cfe52d294893ad46307440e4acf1f02165ea.zip |
Combined the script/environment.rb used for gems and regular files version. If vendor/rails/* has all the frameworks, then files version is used, otherwise gems #878 [Nicholas Seckar]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@946 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/environments/environment.rb')
-rw-r--r-- | railties/environments/environment.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/railties/environments/environment.rb b/railties/environments/environment.rb new file mode 100644 index 0000000000..0f047c3323 --- /dev/null +++ b/railties/environments/environment.rb @@ -0,0 +1,64 @@ +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 config components lib vendor +).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. +rails_files = %w( + actionpack/lib/action_controller + actionpack/lib/action_view + activesupport/lib/active_support + activerecord/lib/active_record + actionmailer/lib/action_mailer + actionwebservice/lib/action_web_service +).collect { |p| File.join(RAILS_ROOT, 'vendor', 'rails', "#{p}.rb") } + +if rails_files.all? { |f| File.file?(f) } + rails_files.each { |f| require f } +else + require 'rubygems' + %w( activesupport activerecord actionpack actionmailer actionwebservice rails ).each { |gem| require_gem(gem) } +end + +# 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: |