aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-03-29 17:08:08 -0700
committerwycats <wycats@gmail.com>2010-03-29 17:08:50 -0700
commit4aded43b73ff94dbf06b4a2d2075651ce454e1d5 (patch)
tree6bac5b0c25e5186b6e92c04fb6e19550630bbe8a /activesupport
parent331327d3919a633679dd3f434d13173fa8df010f (diff)
downloadrails-4aded43b73ff94dbf06b4a2d2075651ce454e1d5.tar.gz
rails-4aded43b73ff94dbf06b4a2d2075651ce454e1d5.tar.bz2
rails-4aded43b73ff94dbf06b4a2d2075651ce454e1d5.zip
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
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/dependencies/autoload.rb4
-rw-r--r--activesupport/lib/active_support/i18n.rb2
-rw-r--r--activesupport/lib/active_support/lazy_load_hooks.rb30
-rw-r--r--activesupport/lib/active_support/railtie.rb2
4 files changed, 13 insertions, 25 deletions
diff --git a/activesupport/lib/active_support/dependencies/autoload.rb b/activesupport/lib/active_support/dependencies/autoload.rb
index f669f4a77e..4c771da096 100644
--- a/activesupport/lib/active_support/dependencies/autoload.rb
+++ b/activesupport/lib/active_support/dependencies/autoload.rb
@@ -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
diff --git a/activesupport/lib/active_support/i18n.rb b/activesupport/lib/active_support/i18n.rb
index 034d7d8ddc..11af48d67e 100644
--- a/activesupport/lib/active_support/i18n.rb
+++ b/activesupport/lib/active_support/i18n.rb
@@ -1,3 +1,3 @@
require 'i18n'
I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
-ActiveSupport.run_base_hooks(:i18n) \ No newline at end of file
+ActiveSupport.run_load_hooks(:i18n) \ No newline at end of file
diff --git a/activesupport/lib/active_support/lazy_load_hooks.rb b/activesupport/lib/active_support/lazy_load_hooks.rb
index 36acfda524..642a4c105c 100644
--- a/activesupport/lib/active_support/lazy_load_hooks.rb
+++ b/activesupport/lib/active_support/lazy_load_hooks.rb
@@ -1,25 +1,17 @@
module ActiveSupport
- module LazyLoadHooks
- def _setup_base_hooks
- @base_hooks ||= Hash.new {|h,k| h[k] = [] }
- @base ||= {}
- end
-
- def base_hook(name = nil, &block)
- _setup_base_hooks
+ @load_hooks = Hash.new {|h,k| h[k] = [] }
+ @loaded = {}
- if base = @base[name]
- base.instance_eval(&block)
- else
- @base_hooks[name] << block
- end
+ def self.on_load(name, &block)
+ if base = @loaded[name]
+ base.instance_eval(&block)
+ else
+ @load_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
- end
+ def self.run_load_hooks(name, base = Object)
+ @load_hooks[name].each { |hook| base.instance_eval(&hook) }
+ @loaded[name] = base
end
end \ No newline at end of file
diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb
index e45d16ee96..b8d54ff839 100644
--- a/activesupport/lib/active_support/railtie.rb
+++ b/activesupport/lib/active_support/railtie.rb
@@ -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