mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Replace the placeholder base_hook API with on_load. To specify some code that
should run during framework load do: ActiveSupport.on_load(:action_controller) do # Code run in the context of AC::Base end
This commit is contained in:
parent
331327d391
commit
4aded43b73
17 changed files with 49 additions and 57 deletions
|
@ -291,7 +291,7 @@ module ActionMailer #:nodoc:
|
|||
:parts_order => [ "text/plain", "text/enriched", "text/html" ]
|
||||
}.freeze
|
||||
|
||||
ActionMailer.run_base_hooks(self)
|
||||
ActiveSupport.run_load_hooks(:action_mailer, self)
|
||||
|
||||
class << self
|
||||
|
||||
|
|
|
@ -6,18 +6,18 @@ module ActionMailer
|
|||
config.action_mailer = ActiveSupport::OrderedOptions.new
|
||||
|
||||
initializer "action_mailer.url_for", :before => :load_environment_config do |app|
|
||||
ActionMailer.base_hook { include app.routes.url_helpers }
|
||||
ActiveSupport.on_load(:action_mailer) { include app.routes.url_helpers }
|
||||
end
|
||||
|
||||
require "action_mailer/railties/log_subscriber"
|
||||
log_subscriber :action_mailer, ActionMailer::Railties::LogSubscriber.new
|
||||
|
||||
initializer "action_mailer.logger" do
|
||||
ActionMailer.base_hook { self.logger ||= Rails.logger }
|
||||
ActiveSupport.on_load(:action_mailer) { self.logger ||= Rails.logger }
|
||||
end
|
||||
|
||||
initializer "action_mailer.set_configs" do |app|
|
||||
ActionMailer.base_hook do
|
||||
ActiveSupport.on_load(:action_mailer) do
|
||||
app.config.action_mailer.each do |k,v|
|
||||
send "#{k}=", v
|
||||
end
|
||||
|
|
|
@ -64,8 +64,7 @@ module ActionController
|
|||
filter
|
||||
end
|
||||
|
||||
ActionController.run_base_hooks(self)
|
||||
|
||||
ActiveSupport.run_load_hooks(:action_controller, self)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ module ActionController
|
|||
log_subscriber :action_controller, ActionController::Railties::LogSubscriber.new
|
||||
|
||||
initializer "action_controller.logger" do
|
||||
ActionController.base_hook { self.logger ||= Rails.logger }
|
||||
ActiveSupport.on_load(:action_controller) { self.logger ||= Rails.logger }
|
||||
end
|
||||
|
||||
initializer "action_controller.set_configs" do |app|
|
||||
|
@ -53,23 +53,23 @@ module ActionController
|
|||
ac.stylesheets_dir = paths.public.stylesheets.to_a.first
|
||||
ac.secret = app.config.cookie_secret
|
||||
|
||||
ActionController.base_hook do
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
self.config.merge!(ac)
|
||||
end
|
||||
end
|
||||
|
||||
initializer "action_controller.initialize_framework_caches" do
|
||||
ActionController.base_hook { self.cache_store ||= RAILS_CACHE }
|
||||
ActiveSupport.on_load(:action_controller) { self.cache_store ||= RAILS_CACHE }
|
||||
end
|
||||
|
||||
initializer "action_controller.set_helpers_path" do |app|
|
||||
ActionController.base_hook do
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
self.helpers_path = app.config.paths.app.helpers.to_a
|
||||
end
|
||||
end
|
||||
|
||||
initializer "action_controller.url_helpers" do |app|
|
||||
ActionController.base_hook do
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
extend ::ActionController::Railties::UrlHelpers.with(app.routes)
|
||||
end
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ module ActionView #:nodoc:
|
|||
delegate :logger, :to => 'ActionController::Base', :allow_nil => true
|
||||
end
|
||||
|
||||
ActionView.run_base_hooks(self)
|
||||
ActiveSupport.run_load_hooks(:action_view, self)
|
||||
|
||||
attr_accessor :base_path, :assigns, :template_extension, :lookup_context
|
||||
attr_internal :captures, :request, :controller, :template, :config
|
||||
|
|
|
@ -6,7 +6,7 @@ require 'active_support/core_ext/kernel/reporting'
|
|||
require 'active_support/core_ext/object/blank'
|
||||
|
||||
module ActionView
|
||||
ActionView.base_hook do
|
||||
ActiveSupport.on_load(:action_view) do
|
||||
class ActionView::Base
|
||||
@@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag}</div>".html_safe }
|
||||
cattr_accessor :field_error_proc
|
||||
|
|
|
@ -1221,7 +1221,7 @@ module ActionView
|
|||
end
|
||||
end
|
||||
|
||||
ActionView.base_hook do
|
||||
ActiveSupport.on_load(:action_view) do
|
||||
class ActionView::Base
|
||||
cattr_accessor :default_form_builder
|
||||
@@default_form_builder = ::ActionView::Helpers::FormBuilder
|
||||
|
|
|
@ -10,14 +10,14 @@ module ActionView
|
|||
|
||||
initializer "action_view.cache_asset_timestamps" do |app|
|
||||
unless app.config.cache_classes
|
||||
ActionView.base_hook do
|
||||
ActiveSupport.on_load(:action_view) do
|
||||
ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
initializer "action_view.set_configs" do |app|
|
||||
ActionView.base_hook do
|
||||
ActiveSupport.on_load(:action_view) do
|
||||
app.config.action_view.each do |k,v|
|
||||
send "#{k}=", v
|
||||
end
|
||||
|
|
|
@ -111,10 +111,10 @@ module ActiveRecord
|
|||
|
||||
autoload :TestCase
|
||||
autoload :TestFixtures, 'active_record/fixtures'
|
||||
end
|
||||
|
||||
base_hook do
|
||||
Arel::Table.engine = Arel::Sql::Engine.new(self)
|
||||
end
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
Arel::Table.engine = Arel::Sql::Engine.new(self)
|
||||
end
|
||||
|
||||
I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
|
|
@ -2245,4 +2245,4 @@ end
|
|||
|
||||
# TODO: Remove this and make it work with LAZY flag
|
||||
require 'active_record/connection_adapters/abstract_adapter'
|
||||
ActiveRecord.run_base_hooks(ActiveRecord::Base)
|
||||
ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
|
||||
|
|
|
@ -23,18 +23,18 @@ module ActiveRecord
|
|||
log_subscriber :active_record, ActiveRecord::Railties::LogSubscriber.new
|
||||
|
||||
initializer "active_record.initialize_timezone" do
|
||||
ActiveRecord.base_hook do
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
self.time_zone_aware_attributes = true
|
||||
self.default_timezone = :utc
|
||||
end
|
||||
end
|
||||
|
||||
initializer "active_record.logger" do
|
||||
ActiveRecord.base_hook { self.logger ||= ::Rails.logger }
|
||||
ActiveSupport.on_load(:active_record) { self.logger ||= ::Rails.logger }
|
||||
end
|
||||
|
||||
initializer "active_record.set_configs" do |app|
|
||||
ActiveRecord.base_hook do
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
app.config.active_record.each do |k,v|
|
||||
send "#{k}=", v
|
||||
end
|
||||
|
@ -44,7 +44,7 @@ module ActiveRecord
|
|||
# This sets the database configuration from Configuration#database_configuration
|
||||
# and then establishes the connection.
|
||||
initializer "active_record.initialize_database" do |app|
|
||||
ActiveRecord.base_hook do
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
self.configurations = app.config.database_configuration
|
||||
establish_connection
|
||||
end
|
||||
|
@ -53,7 +53,7 @@ module ActiveRecord
|
|||
# Expose database runtime to controller for logging.
|
||||
initializer "active_record.log_runtime" do |app|
|
||||
require "active_record/railties/controller_runtime"
|
||||
ActionController.base_hook do
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
include ActiveRecord::Railties::ControllerRuntime
|
||||
end
|
||||
end
|
||||
|
@ -71,9 +71,9 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
initializer "active_record.load_observers" do
|
||||
ActiveRecord.base_hook { instantiate_observers }
|
||||
ActiveSupport.on_load(:active_record) { instantiate_observers }
|
||||
|
||||
ActiveRecord.base_hook do
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
ActionDispatch::Callbacks.to_prepare(:activerecord_instantiate_observers) do
|
||||
ActiveRecord::Base.instantiate_observers
|
||||
end
|
||||
|
@ -81,7 +81,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
initializer "active_record.set_dispatch_hooks", :before => :set_clear_dependencies_hook do |app|
|
||||
ActiveRecord.base_hook do
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
unless app.config.cache_classes
|
||||
ActionDispatch::Callbacks.after do
|
||||
ActiveRecord::Base.reset_subclasses
|
||||
|
|
|
@ -3,10 +3,6 @@ require "active_support/lazy_load_hooks"
|
|||
|
||||
module ActiveSupport
|
||||
module Autoload
|
||||
def self.extended(base)
|
||||
base.extend(LazyLoadHooks)
|
||||
end
|
||||
|
||||
@@autoloads = {}
|
||||
@@under_path = nil
|
||||
@@at_path = nil
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
require 'i18n'
|
||||
I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
|
||||
ActiveSupport.run_base_hooks(:i18n)
|
||||
ActiveSupport.run_load_hooks(:i18n)
|
|
@ -1,25 +1,17 @@
|
|||
module ActiveSupport
|
||||
module LazyLoadHooks
|
||||
def _setup_base_hooks
|
||||
@base_hooks ||= Hash.new {|h,k| h[k] = [] }
|
||||
@base ||= {}
|
||||
end
|
||||
@load_hooks = Hash.new {|h,k| h[k] = [] }
|
||||
@loaded = {}
|
||||
|
||||
def base_hook(name = nil, &block)
|
||||
_setup_base_hooks
|
||||
|
||||
if base = @base[name]
|
||||
base.instance_eval(&block)
|
||||
else
|
||||
@base_hooks[name] << block
|
||||
end
|
||||
end
|
||||
|
||||
def run_base_hooks(base, name = nil)
|
||||
_setup_base_hooks
|
||||
|
||||
@base_hooks[name].each { |hook| base.instance_eval(&hook) } if @base_hooks
|
||||
@base[name] = base
|
||||
def self.on_load(name, &block)
|
||||
if base = @loaded[name]
|
||||
base.instance_eval(&block)
|
||||
else
|
||||
@load_hooks[name] << block
|
||||
end
|
||||
end
|
||||
|
||||
def self.run_load_hooks(name, base = Object)
|
||||
@load_hooks[name].each { |hook| base.instance_eval(&hook) }
|
||||
@loaded[name] = base
|
||||
end
|
||||
end
|
|
@ -35,7 +35,7 @@ module I18n
|
|||
config.i18n.load_path = []
|
||||
|
||||
initializer "i18n.initialize" do
|
||||
ActiveSupport.base_hook(:i18n) do
|
||||
ActiveSupport.on_load(:i18n) do
|
||||
I18n.reload!
|
||||
|
||||
ActionDispatch::Callbacks.to_prepare do
|
||||
|
|
|
@ -27,7 +27,7 @@ module Rails
|
|||
|
||||
routes.clear!
|
||||
paths.each { |path| load(path) }
|
||||
ActionController.base_hook { routes.finalize! }
|
||||
ActiveSupport.on_load(:action_controller) { routes.finalize! }
|
||||
|
||||
nil
|
||||
ensure
|
||||
|
|
|
@ -180,8 +180,13 @@ module Rails
|
|||
|
||||
initializer :add_view_paths do
|
||||
views = paths.app.views.to_a
|
||||
ActionController.base_hook { prepend_view_path(views) } if defined?(ActionController)
|
||||
ActionMailer.base_hook { prepend_view_path(views) } if defined?(ActionMailer)
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
prepend_view_path(views)
|
||||
end
|
||||
|
||||
ActiveSupport.on_load(:action_mailer) do
|
||||
prepend_view_path(views)
|
||||
end
|
||||
end
|
||||
|
||||
initializer :add_metals do |app|
|
||||
|
|
Loading…
Reference in a new issue