module RConfig::Reload
Public Instance Methods
auto_check?(name)
click to toggle source
# File lib/rconfig/reload.rb, line 65 def auto_check?(name) now = Time.now if (!self.last_auto_check[name]) || (now - self.last_auto_check[name]) > self.reload_interval self.last_auto_check[name] = now return true end return false end
enable_reload=(reload)
click to toggle source
Sets the flag indicating whether or not reload should be executed.
# File lib/rconfig/reload.rb, line 16 def enable_reload=(reload) raise ArgumentError, 'Argument must be true or false.' unless [true, false].include?(reload) self.enable_reload = reload end
reload(force=false)
click to toggle source
Flushes cached config data, so that it can be reloaded from disk. It is recommended that this should be used with caution, and any need to reload in a production setting should minimized or completely avoided if possible.
# File lib/rconfig/reload.rb, line 36 def reload(force=false) raise ArgumentError, 'Argument must be true or false.' unless [true, false].include?(force) if force || reload? flush_cache return true end false end
reload?()
click to toggle source
Flag indicating whether or not reload should be executed.
# File lib/rconfig/reload.rb, line 6 def reload? self.enable_reload end
reload_disabled?()
click to toggle source
# File lib/rconfig/reload.rb, line 10 def reload_disabled? not reload? end
reload_interval=(interval)
click to toggle source
Sets the number of seconds between reloading of config files and automatic reload checks. Defaults to 5 minutes. Setting
# File lib/rconfig/reload.rb, line 25 def reload_interval=(interval) raise ArgumentError, 'Argument must be Integer.' unless interval.kind_of?(Integer) self.enable_reload = false if interval == 0 # Sett self.reload_interval = interval end
without_reload() { || ... }
click to toggle source
Executes given block, without reloading any config. Meant to run configuration-sensitive code that may otherwise trigger a reload of any/all config files. If reload is disabled then it makes no difference if this wrapper is used or not. Returns result of the block
# File lib/rconfig/reload.rb, line 51 def without_reload(&block) return unless block_given? result = nil enable_reload_cache = self.enable_reload begin self.enable_reload result = yield ensure self.enable_reload = enable_reload_cache check_config_changed if reload? end result end