Module: Regurgitator::ServerSettings
- Included in:
- Device
- Defined in:
- lib/regurgitator/server_settings.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
-
#refresh_zone(force = false) ⇒ Object
:nodoc:.
- #refresh_zone_unlocked(force) ⇒ Object
- #server_settings_init ⇒ Object
-
#zone_for(addr, skip_local = false) ⇒ Object
If
skip_local
is true, it may return:local
ifaddr
is the address of the host this method is running on Returns the zone (a String) for a givenaddr
, if there is one Returnsnil
if zone information is unknown.
Class Method Details
.extended(obj) ⇒ Object
13 14 15 |
# File 'lib/regurgitator/server_settings.rb', line 13 def self.extended(obj) obj.server_settings_init end |
Instance Method Details
#refresh_zone(force = false) ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/regurgitator/server_settings.rb', line 17 def refresh_zone(force = false) # :nodoc: @zone_cache_lock.synchronize { refresh_zone_unlocked(force) } end |
#refresh_zone_unlocked(force) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/regurgitator/server_settings.rb', line 21 def refresh_zone_unlocked(force) return @zone_cache if !force && ((Regurgitator.now-@zone_cache_mtime) < 60) tmp = Patricia.new sql = 'SELECT value FROM server_settings WHERE field = ? LIMIT 1'.freeze begin row = @db[sql, 'network_zones'.freeze].first or return tmp row[:value].split(/\s*,\s*/).each do |zone| row = @db[sql, "zone_#{zone}"].first or next begin tmp.add(row[:value], zone) rescue ArgumentError end end ensure @zone_cache_mtime = Regurgitator.now return @zone_cache = tmp end end |
#server_settings_init ⇒ Object
7 8 9 10 11 |
# File 'lib/regurgitator/server_settings.rb', line 7 def server_settings_init @zone_cache_mtime = 0 @zone_cache = nil @zone_cache_lock = Mutex.new end |
#zone_for(addr, skip_local = false) ⇒ Object
If skip_local
is true, it may return :local
if addr
is the address of the host this method is running on Returns the zone (a String) for a given addr
, if there is one Returns nil
if zone information is unknown.
45 46 47 48 49 |
# File 'lib/regurgitator/server_settings.rb', line 45 def zone_for(addr, skip_local = false) return :local if skip_local && Regurgitator::Local.include?(addr) zone = refresh_zone.search_best(addr) and return zone.data # String nil end |