module ActiveSupport
def self.execute_hook(base, options, block)
def self.execute_hook(base, options, block) if options[:yield] block.call(base) else base.instance_eval(&block) end end
def self.on_load(name, options = {}, &block)
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.run_load_hooks(name, base = Object)
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
def deprecate_methods(target_module, *method_names)
def deprecate_methods(target_module, *method_names) options = method_names.extract_options! method_names += options.keys method_names.each do |method_name| target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation| target_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1) def #{target}_with_deprecation#{punctuation}(*args, &block) ::ActiveSupport::Deprecation.warn( ::ActiveSupport::Deprecation.deprecated_method_warning( :#{method_name}, #{options[method_name].inspect}), caller ) send(:#{target}_without_deprecation#{punctuation}, *args, &block) end end_eval end end end
def load_all!; load_all_hooks.each { |hook| hook.call } end
def load_all!; load_all_hooks.each { |hook| hook.call } end
def on_load_all(&hook) load_all_hooks << hook end
def on_load_all(&hook) load_all_hooks << hook end