Moved more configuration away from bootstrap.

This commit is contained in:
José Valim 2010-01-22 20:44:29 +01:00
parent 4ae7936727
commit c8cc8a9872
9 changed files with 81 additions and 95 deletions

View File

@ -18,10 +18,5 @@ module ActionMailer
initializer "action_mailer.logger" do
ActionMailer::Base.logger ||= Rails.logger
end
initializer "action_mailer.view_paths" do |app|
# TODO: this should be combined with the logic for default config.action_mailer.view_paths
ActionMailer::Base.template_root = [] if ActionMailer::Base.view_paths.blank?
end
end
end

View File

@ -22,15 +22,5 @@ module ActionController
initializer "action_controller.initialize_framework_caches" do
ActionController::Base.cache_store ||= RAILS_CACHE
end
# Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
# (but only for those frameworks that are to be loaded). If the framework's
# paths have already been set, it is not changed, otherwise it is
# set to use Configuration#view_path.
initializer "action_controller.initialize_framework_views" do |app|
# TODO: this should be combined with the logic for default config.action_controller.view_paths
ActionController::Base.view_paths = [] if ActionController::Base.view_paths.blank?
end
end
end

View File

@ -18,6 +18,11 @@ module ActiveRecord
require "active_record/railties/subscriber"
subscriber ActiveRecord::Railties::Subscriber.new
initializer "active_record.initialize_timezone" do
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
end
initializer "active_record.set_configs" do |app|
app.config.active_record.each do |k,v|
ActiveRecord::Base.send "#{k}=", v
@ -31,11 +36,6 @@ module ActiveRecord
ActiveRecord::Base.establish_connection
end
initializer "active_record.initialize_timezone" do
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
end
# Expose database runtime to controller for logging.
initializer "active_record.log_runtime" do |app|
require "active_record/railties/controller_runtime"

View File

@ -7,5 +7,11 @@ module ActiveResource
require "active_resource/railties/subscriber"
subscriber ActiveResource::Railties::Subscriber.new
initializer "active_resource.set_configs" do |app|
app.config.active_resource.each do |k,v|
ActiveResource::Base.send "#{k}=", v
end
end
end
end

View File

@ -0,0 +1,29 @@
require "active_support"
require "rails"
module ActiveSupport
class Railtie < Rails::Railtie
plugin_name :active_support
# Loads support for "whiny nil" (noisy warnings when methods are invoked
# on +nil+ values) if Configuration#whiny_nils is true.
initializer :initialize_whiny_nils do |app|
require 'active_support/whiny_nil' if app.config.whiny_nils
end
# Sets the default value for Time.zone
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
initializer :initialize_time_zone do |app|
require 'active_support/core_ext/time/zones'
zone_default = Time.__send__(:get_zone, app.config.time_zone)
unless zone_default
raise \
'Value assigned to config.time_zone not recognized.' +
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
end
Time.zone_default = zone_default
end
end
end

View File

@ -1,6 +1,7 @@
require "rails"
%w(
active_support
active_model
active_record
action_controller

View File

@ -137,6 +137,45 @@ module Rails
end
end
# Set the i18n configuration from config.i18n but special-case for the load_path which should be
# appended to what's already set instead of overwritten.
initializer :initialize_i18n do
require 'active_support/i18n'
config.i18n.each do |setting, value|
if setting == :load_path
I18n.load_path += value
else
I18n.send("#{setting}=", value)
end
end
ActionDispatch::Callbacks.to_prepare do
I18n.reload!
end
end
initializer :set_clear_dependencies_hook do
unless config.cache_classes
ActionDispatch::Callbacks.after do
ActiveSupport::Dependencies.clear
end
end
end
initializer :initialize_notifications do
require 'active_support/notifications'
if config.colorize_logging == false
Rails::Subscriber.colorize_logging = false
config.generators.colorize_logging = false
end
ActiveSupport::Notifications.subscribe do |*args|
Rails::Subscriber.dispatch(args)
end
end
# Disable dependency loading during request cycle
initializer :disable_dependency_loading do
if config.cache_classes && !config.dependency_loading

View File

@ -33,13 +33,6 @@ module Rails
# FIXME This is just a dumb initializer used as hook
end
# Create tmp directories
initializer :ensure_tmp_directories_exist do
%w(cache pids sessions sockets).each do |dir_to_make|
FileUtils.mkdir_p(File.join(root, 'tmp', dir_to_make))
end
end
# Preload all frameworks specified by the Configuration#frameworks.
# Used by Passenger to ensure everything's loaded before forking and
# to avoid autoload race conditions in JRuby.
@ -64,70 +57,5 @@ module Rails
# TODO: Remove files from the $" and always use require
ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load
end
# Loads support for "whiny nil" (noisy warnings when methods are invoked
# on +nil+ values) if Configuration#whiny_nils is true.
initializer :initialize_whiny_nils do
require 'active_support/whiny_nil' if config.whiny_nils
end
# Sets the default value for Time.zone
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
initializer :initialize_time_zone do
require 'active_support/core_ext/time/zones'
zone_default = Time.__send__(:get_zone, config.time_zone)
unless zone_default
raise \
'Value assigned to config.time_zone not recognized.' +
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
end
Time.zone_default = zone_default
end
# Set the i18n configuration from config.i18n but special-case for the load_path which should be
# appended to what's already set instead of overwritten.
initializer :initialize_i18n do
require 'active_support/i18n'
config.i18n.each do |setting, value|
if setting == :load_path
I18n.load_path += value
else
I18n.send("#{setting}=", value)
end
end
ActionDispatch::Callbacks.to_prepare do
I18n.reload!
end
end
initializer :set_clear_dependencies_hook do
unless config.cache_classes
ActionDispatch::Callbacks.after do
ActiveSupport::Dependencies.clear
end
end
end
initializer :initialize_notifications do
require 'active_support/notifications'
if config.colorize_logging == false
Rails::Subscriber.colorize_logging = false
config.generators.colorize_logging = false
end
ActiveSupport::Notifications.subscribe do |*args|
Rails::Subscriber.dispatch(args)
end
end
private
def expand_load_path(load_paths)
load_paths.map { |path| Dir.glob(path.to_s) }.flatten.uniq
end
end
end

View File

@ -62,10 +62,8 @@ module Rails
/^(#{bits})(?:=)?$/
end
# TODO Remove :active_support as special case by adding a railtie
# for it and for I18n
def config_keys
([:active_support] + Railtie.plugin_names).map { |n| n.to_s }.uniq
Railtie.plugin_names.map { |n| n.to_s }.uniq
end
end