Module: RConfig::Reload
- Included in:
- RConfig
- Defined in:
- lib/rconfig/reload.rb
Instance Method Summary collapse
- #auto_check?(name) ⇒ Boolean
-
#enable_reload=(reload) ⇒ Object
Sets the flag indicating whether or not reload should be executed.
-
#reload(force = false) ⇒ Object
Flushes cached config data, so that it can be reloaded from disk.
-
#reload? ⇒ Boolean
Flag indicating whether or not reload should be executed.
- #reload_disabled? ⇒ Boolean
-
#reload_interval=(interval) ⇒ Object
Sets the number of seconds between reloading of config files and automatic reload checks.
-
#without_reload(&block) ⇒ Object
Executes given block, without reloading any config.
Instance Method Details
#auto_check?(name) ⇒ Boolean
65 66 67 68 69 70 71 72 |
# 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) ⇒ Object
Sets the flag indicating whether or not reload should be executed.
16 17 18 19 |
# 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) ⇒ Object
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.
36 37 38 39 40 41 42 43 |
# 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? ⇒ Boolean
Flag indicating whether or not reload should be executed.
6 7 8 |
# File 'lib/rconfig/reload.rb', line 6 def reload? self.enable_reload end |
#reload_disabled? ⇒ Boolean
10 11 12 |
# File 'lib/rconfig/reload.rb', line 10 def reload_disabled? not reload? end |
#reload_interval=(interval) ⇒ Object
Sets the number of seconds between reloading of config files and automatic reload checks. Defaults to 5 minutes. Setting
25 26 27 28 29 |
# 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(&block) ⇒ Object
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
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 |