Files

RConfig::Callbacks

Public Instance Methods

fire_on_load(name) click to toggle source

Executes all of the reload callbacks registered to the specified config name, and all of the callbacks registered to run on any config, as specified by the :ANY symbol.

    # File lib/rconfig/callbacks.rb, line 38
38:     def fire_on_load(name)
39:       procs = (self.callbacks['ANY'] || RConfig::EMPTY_ARRAY) + (self.callbacks[name] || RConfig::EMPTY_ARRAY)
40:       procs.uniq!
41:       logger.debug "fire_on_load(#{name.inspect}): callbacks[#{procs.inspect}]" unless procs.empty?
42:       procs.each { |proc| proc.call() }
43:     end
on_load(*args, &blk) click to toggle source

Register a callback when a config has been reloaded. If no config name is specified, the callback will be registered under the name :ANY. The name :ANY will register a callback for any config file change.

Example:

  class MyClass
    self.my_config = { }
    RConfig.on_load(:cache) do
      self.my_config = { }
    end
    def my_config
      self.my_config ||= something_expensive_thing_on_config(RConfig.cache.memory_limit)
    end
  end
    # File lib/rconfig/callbacks.rb, line 21
21:     def on_load(*args, &blk)
22:       args << :ANY if args.empty?
23:       proc = blk.to_proc
24: 
25:       # Call proc on registration.
26:       proc.call()
27: 
28:       # Register callback proc.
29:       args.each do |name|
30:         (self.callbacks[name.to_s] ||= []) << proc
31:       end
32:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.