Class: Pandemic::ClientSide::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/pandemic/client_side/config.rb

Constant Summary collapse

@@load_mutex =
Mutex.new

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.config_pathObject

Returns the value of attribute config_path.



6
7
8
# File 'lib/pandemic/client_side/config.rb', line 6

def config_path
  @config_path
end

.connection_wait_timeoutObject

Returns the value of attribute connection_wait_timeout.



7
8
9
# File 'lib/pandemic/client_side/config.rb', line 7

def connection_wait_timeout
  @connection_wait_timeout
end

.loadedObject

Returns the value of attribute loaded.



6
7
8
# File 'lib/pandemic/client_side/config.rb', line 6

def loaded
  @loaded
end

.max_connections_per_serverObject

Returns the value of attribute max_connections_per_server.



7
8
9
# File 'lib/pandemic/client_side/config.rb', line 7

def max_connections_per_server
  @max_connections_per_server
end

.min_connections_per_serverObject

Returns the value of attribute min_connections_per_server.



7
8
9
# File 'lib/pandemic/client_side/config.rb', line 7

def min_connections_per_server
  @min_connections_per_server
end

.response_timeoutObject

Returns the value of attribute response_timeout.



7
8
9
# File 'lib/pandemic/client_side/config.rb', line 7

def response_timeout
  @response_timeout
end

.serversObject

Returns the value of attribute servers.



7
8
9
# File 'lib/pandemic/client_side/config.rb', line 7

def servers
  @servers
end

Class Method Details

.loadObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pandemic/client_side/config.rb', line 9

def load
  @@load_mutex.synchronize do
    return if self.loaded
    path = config_path
    yaml = YAML.load_file(path)

    @servers = yaml['servers'] || []
    # this is just so if we copy/paste from server's yml to client's yml, it will still work
    @servers = @servers.values if @servers.is_a?(Hash)
    @servers.sort! # so it's consistent across all clients

    @max_connections_per_server = (yaml['max_connections_per_server'] || 1).to_i
    @min_connections_per_server = (yaml['min_connections_per_server'] || 1).to_i
    @connection_wait_timeout = (yaml['connection_wait_timeout'] || 1).to_f
    @response_timeout = (yaml['response_timeout'] || 1).to_f
    self.loaded = true
  end
end