From 20e3cfe52d294893ad46307440e4acf1f02165ea Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 20 Mar 2005 22:41:35 +0000 Subject: 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 --- railties/CHANGELOG | 2 + railties/Rakefile | 13 ++-- railties/environments/environment.rb | 64 +++++++++++++++++++ railties/environments/shared.rb | 71 ---------------------- railties/environments/shared_for_gem.rb | 66 -------------------- .../generators/applications/app/app_generator.rb | 6 +- 6 files changed, 73 insertions(+), 149 deletions(-) create mode 100644 railties/environments/environment.rb delete mode 100644 railties/environments/shared.rb delete mode 100644 railties/environments/shared_for_gem.rb diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 99a86a00bc..c92fcb6760 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* 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] + * Changed .htaccess to allow dispatch.* to be called from a sub-directory as part of the push with Action Pack to make Rails work on non-vhost setups #826 [Nicholas Seckar/Tobias Luetke] * Added script/runner which can be used to run code inside the environment by eval'ing the first parameter. Examples: diff --git a/railties/Rakefile b/railties/Rakefile index 1399242205..90fddb3b4a 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -90,16 +90,15 @@ end desc "Copy in all the Rails packages to vendor" task :copy_vendor_libraries do + mkdir File.join(PKG_DESTINATION, 'vendor', 'rails') cp_r VENDOR_LIBS.map { |dir| File.join('..', dir) }, - File.join(PKG_DESTINATION, 'vendor') + File.join(PKG_DESTINATION, 'vendor', 'rails') end desc "Link in all the Rails packages to vendor" task :link_vendor_libraries do - return_dir = File.dirname(File.expand_path(__FILE__)) - cd File.join(PKG_DESTINATION, 'vendor') - VENDOR_LIBS.each { |dir| ln_s File.dirname(__FILE__) + "/../../#{dir}", "." } - cd return_dir + branch_root = File.dirname(File.dirname(File.expand_path(__FILE__))) + ln_s branch_root, File.join(PKG_DESTINATION, 'vendor', 'rails') end @@ -138,7 +137,7 @@ task :copy_configs do cp "configs/apache.conf", "#{PKG_DESTINATION}/public/.htaccess" - cp "environments/shared.rb", "#{PKG_DESTINATION}/config/environment.rb" + cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb" cp "environments/production.rb", "#{PKG_DESTINATION}/config/environments/production.rb" cp "environments/development.rb", "#{PKG_DESTINATION}/config/environments/development.rb" cp "environments/test.rb", "#{PKG_DESTINATION}/config/environments/test.rb" @@ -207,7 +206,7 @@ end # Generate GEM ---------------------------------------------------------------------------- task :copy_gem_environment do - cp "environments/shared_for_gem.rb", "#{PKG_DESTINATION}/config/environment.rb" + cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb" dest_file = File.join(PKG_DESTINATION, 'script', 'breakpointer') copy_with_rewritten_ruby_path(File.join('bin', 'breakpointer_for_gem'), dest_file) chmod 0755, dest_file 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: diff --git a/railties/environments/shared.rb b/railties/environments/shared.rb deleted file mode 100644 index fa729bbe60..0000000000 --- a/railties/environments/shared.rb +++ /dev/null @@ -1,71 +0,0 @@ -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 - vendor/railties - vendor/railties/lib - vendor/activesupport/lib - vendor/activerecord/lib - vendor/actionpack/lib - vendor/actionmailer/lib - vendor/actionwebservice/lib -).map { |dir| "#{RAILS_ROOT}/#{dir}" } - -# Prepend to $LOAD_PATH -ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } - - -# Require Rails libraries. -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: diff --git a/railties/environments/shared_for_gem.rb b/railties/environments/shared_for_gem.rb deleted file mode 100644 index beac2e31e0..0000000000 --- a/railties/environments/shared_for_gem.rb +++ /dev/null @@ -1,66 +0,0 @@ -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}" } - -# Prepend to $LOAD_PATH -ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } - - -# Require Rails gems. -require 'rubygems' -require_gem 'activesupport' -require_gem 'activerecord' -require_gem 'actionpack' -require_gem 'actionmailer' -require_gem 'actionwebservice' -require_gem 'rails' - - -# 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: diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 3916d6905f..56f82f360f 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -37,11 +37,7 @@ class AppGenerator < Rails::Generator::Base m.template "configs/apache.conf", "public/.htaccess" # Environments - if options[:gem] - m.file "environments/shared_for_gem.rb", "config/environment.rb" - else - m.file "environments/shared.rb", "config/environment.rb" - end + m.file "environments/environment.rb", "config/environment.rb" m.file "environments/production.rb", "config/environments/production.rb" m.file "environments/development.rb", "config/environments/development.rb" m.file "environments/test.rb", "config/environments/test.rb" -- cgit v1.2.3