Class: AMQP::Failover::Configurations
- Inherits:
-
Array
- Object
- Array
- AMQP::Failover::Configurations
- Defined in:
- lib/amqp/failover/configurations.rb
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #[]=(*args) ⇒ Object
- #find_next(conf = {}) ⇒ Object
- #get(ref = nil) ⇒ Object
-
#initialize(confs = nil) ⇒ Configurations
constructor
A new instance of Configurations.
- #load(conf) ⇒ Object
- #load_array(confs = []) ⇒ Object
- #load_hash(conf = {}) ⇒ Object
- #primary ⇒ Object
- #primary=(conf = {}) ⇒ Object
- #primary_ref ⇒ Object
- #primary_ref=(ref) ⇒ Object
- #refs ⇒ Object
- #set(conf = {}, ref = nil) ⇒ Object
Constructor Details
#initialize(confs = nil) ⇒ Configurations
Returns a new instance of Configurations.
7 8 9 |
# File 'lib/amqp/failover/configurations.rb', line 7 def initialize(confs = nil) load(confs) end |
Instance Method Details
#[](*args) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/amqp/failover/configurations.rb', line 11 def [](*args) if args[0].is_a?(Symbol) return primary if args[0] == :primary get(args[0]) else super(*args) end end |
#[]=(*args) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/amqp/failover/configurations.rb', line 20 def []=(*args) if args[0].is_a?(Symbol) return primary = args.last if args[0] == :primary set(args.last, args[0]) end super(*args) end |
#find_next(conf = {}) ⇒ Object
64 65 66 67 |
# File 'lib/amqp/failover/configurations.rb', line 64 def find_next(conf = {}) current = self.index(conf) self[(current+1 == self.size) ? 0 : current+1] if current end |
#get(ref = nil) ⇒ Object
48 49 50 51 |
# File 'lib/amqp/failover/configurations.rb', line 48 def get(ref = nil) return self[ref] if ref.is_a?(Fixnum) self[refs[ref]] if refs[ref] end |
#load(conf) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/amqp/failover/configurations.rb', line 69 def load(conf) if conf.is_a?(Array) load_array(conf) elsif conf.is_a?(Hash) load_hash(conf) end end |
#load_array(confs = []) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/amqp/failover/configurations.rb', line 77 def load_array(confs = []) self.clear refs = {} confs.each do |conf| conf = AMQP::Client.parse_amqp_url(conf) if conf.is_a?(String) load_hash(conf) end end |
#load_hash(conf = {}) ⇒ Object
86 87 88 |
# File 'lib/amqp/failover/configurations.rb', line 86 def load_hash(conf = {}) set(conf) end |
#primary ⇒ Object
40 41 42 |
# File 'lib/amqp/failover/configurations.rb', line 40 def primary get(primary_ref) || AMQP.settings end |
#primary=(conf = {}) ⇒ Object
44 45 46 |
# File 'lib/amqp/failover/configurations.rb', line 44 def primary=(conf = {}) set(conf, primary_ref) end |
#primary_ref ⇒ Object
32 33 34 |
# File 'lib/amqp/failover/configurations.rb', line 32 def primary_ref @primary_ref ||= 0 end |
#primary_ref=(ref) ⇒ Object
36 37 38 |
# File 'lib/amqp/failover/configurations.rb', line 36 def primary_ref=(ref) @primary_ref = ref end |
#refs ⇒ Object
28 29 30 |
# File 'lib/amqp/failover/configurations.rb', line 28 def refs @refs ||= {} end |
#set(conf = {}, ref = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/amqp/failover/configurations.rb', line 53 def set(conf = {}, ref = nil) conf = Failover::Config.new(conf) if !conf.is_a?(Failover::Config) if (index = self.index(conf)).nil? self << conf else conf = self[index] end refs[ref] = (index || self.index(conf)) if ref conf end |