提交 c8cc8a98 编写于 作者: J José Valim

Moved more configuration away from bootstrap.

上级 4ae79367
......@@ -18,10 +18,5 @@ class Railtie < Rails::Railtie
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
\ No newline at end of file
......@@ -22,15 +22,5 @@ class Railtie < Rails::Railtie
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
......@@ -18,6 +18,11 @@ class Railtie < Rails::Railtie
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 @@ class Railtie < Rails::Railtie
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"
......
......@@ -7,5 +7,11 @@ class Railtie < Rails::Railtie
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
\ No newline at end of file
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
\ No newline at end of file
require "rails"
%w(
active_support
active_model
active_record
action_controller
......
......@@ -137,6 +137,45 @@ def call(env)
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
......
......@@ -33,13 +33,6 @@ def initialize(application)
# 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 @@ def initialize(application)
# 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
......@@ -62,10 +62,8 @@ def config_key_regexp
/^(#{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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册