1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/lib/active_support/lazy_load_hooks.rb
wycats 4aded43b73 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
2010-03-29 17:08:50 -07:00

17 lines
No EOL
377 B
Ruby

module ActiveSupport
@load_hooks = Hash.new {|h,k| h[k] = [] }
@loaded = {}
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