mirror of
https://github.com/jimeh/amqp-failover.git
synced 2026-02-19 10:56:44 +00:00
Failover::Configs specs pass
This commit is contained in:
@@ -7,10 +7,14 @@ module AMQP
|
||||
attr_accessor :last_fail
|
||||
|
||||
def initialize(hash = {}, last_fail_date = nil)
|
||||
self.replace(symbolize_keys(hash))
|
||||
self.replace(symbolize_keys(defaults.merge(hash)))
|
||||
self.last_fail = last_fail_date if last_fail_date
|
||||
end
|
||||
|
||||
def defaults
|
||||
AMQP.settings
|
||||
end
|
||||
|
||||
def symbolize_keys(hash = {})
|
||||
hash.inject({}) do |result, (key, value)|
|
||||
result[key.is_a?(String) ? key.to_sym : key] = value
|
||||
@@ -30,7 +34,7 @@ module AMQP
|
||||
end
|
||||
return other.last_fail <=> self.last_fail
|
||||
end
|
||||
return 0
|
||||
super(other)
|
||||
end
|
||||
|
||||
end # Config
|
||||
|
||||
@@ -46,7 +46,7 @@ module AMQP
|
||||
end
|
||||
|
||||
def set(conf = {}, ref = nil)
|
||||
conf = Config.new(default_config.merge(conf))
|
||||
conf = Failover::Config.new(conf) if !conf.is_a?(Failover::Config)
|
||||
self << conf if (index = self.index(conf)).nil?
|
||||
if ref
|
||||
refs[ref] = (index || self.index(conf))
|
||||
@@ -75,7 +75,7 @@ module AMQP
|
||||
end
|
||||
end
|
||||
|
||||
def self.load_array(confs = [])
|
||||
def load_array(confs = [])
|
||||
self.clear
|
||||
confs.each do |conf|
|
||||
conf = AMQP::Client.parse_amqp_url(conf) if conf.is_a?(::String)
|
||||
@@ -84,11 +84,7 @@ module AMQP
|
||||
end
|
||||
|
||||
def load_hash(conf = {})
|
||||
set(Config.new(conf))
|
||||
end
|
||||
|
||||
def default_config
|
||||
AMQP.settings
|
||||
set(conf)
|
||||
end
|
||||
|
||||
end # Config
|
||||
|
||||
Reference in New Issue
Block a user