Sha256: 262219c07eb2834672754cab041bd093c1dcbc151124a5d994fc86b063c84824
Contents?: true
Size: 1.04 KB
Versions: 3
Compression:
Stored size: 1.04 KB
Contents
module EbisuConnection class Slave attr_reader :hostname, :weight def initialize(conf, slave_group) case conf when String host, weight = conf.split(/\s*,\s*/) @hostname, port = host.split(/\s*:\s*/) when Hash @hostname = conf["host"] || conf[:host] weight = conf["weight"] || conf[:weight] port = conf["port"] || conf[:port] else raise ArgumentError, "slaves config is invalid" end spec = modify_spec(port) @connection_factory = FreshConnection::ConnectionFactory.new(slave_group, spec) @weight = (weight || 1).to_i end def connection @connection ||= @connection_factory.new_connection end def disconnect! if @connection @connection.disconnect! @connection = nil end rescue end def modify_spec(port) modify_spec = {"host" => @hostname} return modify_spec unless port modify_spec["port"] = port.to_i if port.is_a?(Integer) || !port.empty? modify_spec end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ebisu_connection-1.0.0 | lib/ebisu_connection/slave.rb |
ebisu_connection-0.3.1 | lib/ebisu_connection/slave.rb |
ebisu_connection-0.3.0 | lib/ebisu_connection/slave.rb |