Class: AMQP::Failover::Config
- Inherits:
-
Hash
- Object
- Hash
- AMQP::Failover::Config
- Defined in:
- lib/amqp/failover/config.rb
Instance Attribute Summary collapse
-
#last_fail ⇒ Object
Returns the value of attribute last_fail.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
order by latest fail, potentially useful if random config selection is used.
- #defaults ⇒ Object
-
#initialize(hash = {}, last_fail_date = nil) ⇒ Config
constructor
A new instance of Config.
- #symbolize_keys(hash = {}) ⇒ Object
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_fail ⇒ Object
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 |
#defaults ⇒ Object
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 |