Class: AMQP::Failover::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/amqp/failover/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}, last_fail_date = nil) ⇒ Config

Returns a new instance of Config.



9
10
11
12
# File 'lib/amqp/failover/config.rb', line 9

def initialize(hash = {}, last_fail_date = nil)
  self.replace(defaults.merge(symbolize_keys(hash)))
  self.last_fail = last_fail_date if last_fail_date
end

Instance Attribute Details

#last_failObject

Returns the value of attribute last_fail.



7
8
9
# File 'lib/amqp/failover/config.rb', line 7

def last_fail
  @last_fail
end

Instance Method Details

#<=>(other) ⇒ Object

order by latest fail, potentially useful if random config selection is used



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/amqp/failover/config.rb', line 26

def <=>(other)
  if self.respond_to?(:last_fail) && other.respond_to?(:last_fail)
    if self.last_fail.nil? && other.last_fail.nil?
      return 0
    elsif self.last_fail.nil? && !other.last_fail.nil?
      return 1
    elsif !self.last_fail.nil? && other.last_fail.nil?
      return -1
    end
    return other.last_fail <=> self.last_fail
  end
  return 0
end

#defaultsObject



14
15
16
# File 'lib/amqp/failover/config.rb', line 14

def defaults
  AMQP.settings
end

#symbolize_keys(hash = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/amqp/failover/config.rb', line 18

def symbolize_keys(hash = {})
  hash.inject({}) do |result, (key, value)|
    result[key.is_a?(String) ? key.to_sym : key] = value
    result
  end
end