Sha256: ac49949b53845cdf165f2d983126cb2eb1397908850a093600671c3f2d635563

Contents?: true

Size: 589 Bytes

Versions: 9

Compression:

Stored size: 589 Bytes

Contents

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

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
activesupport-3.0.0.rc lib/active_support/lazy_load_hooks.rb
csd-0.1.5 lib/active_support/lazy_load_hooks.rb
csd-0.1.4 lib/active_support/lazy_load_hooks.rb
csd-0.1.3 lib/active_support/lazy_load_hooks.rb
csd-0.1.2 lib/active_support/lazy_load_hooks.rb
csd-0.1.1 lib/active_support/lazy_load_hooks.rb
csd-0.1.0 lib/active_support/lazy_load_hooks.rb
csd-0.0.16 lib/active_support/lazy_load_hooks.rb
activesupport-3.0.0.beta4 lib/active_support/lazy_load_hooks.rb