mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
9cfeefb637
* before_configuration: this hook is run immediately after the Application class comes into existence, but before the user has added any configuration. This is the appropriate place to set configuration for your plugin * before_initialize: This is run after all of the user's configuration has completed, but before any initializers have begun (in other words, it runs right after config/environments/{development,production,test}.rb) * after_initialize: This is run after all of the initializers have run. It is an appropriate place for forking in a preforking setup Each of these hooks may be used via ActiveSupport.on_load(name) { }. In all these cases, the context inside the block will be the Application object. This means that for simple cases, you can use these hooks without needing to create a Railtie.
27 lines
No EOL
589 B
Ruby
27 lines
No EOL
589 B
Ruby
module ActiveSupport
|
|
@load_hooks = Hash.new {|h,k| h[k] = [] }
|
|
@loaded = {}
|
|
|
|
def self.on_load(name, options = {}, &block)
|
|
if base = @loaded[name]
|
|
execute_hook(base, options, block)
|
|
else
|
|
@load_hooks[name] << [block, options]
|
|
end
|
|
end
|
|
|
|
def self.execute_hook(base, options, block)
|
|
if options[:yield]
|
|
block.call(base)
|
|
else
|
|
base.instance_eval(&block)
|
|
end
|
|
end
|
|
|
|
def self.run_load_hooks(name, base = Object)
|
|
@loaded[name] = base
|
|
@load_hooks[name].each do |hook, options|
|
|
execute_hook(base, options, hook)
|
|
end
|
|
end
|
|
end |