mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
4aded43b73
should run during framework load do: ActiveSupport.on_load(:action_controller) do # Code run in the context of AC::Base end
17 lines
No EOL
377 B
Ruby
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 |