Class: Ciclope::Ring

Inherits:
Object
  • Object
show all
Defined in:
lib/ciclope/ring.rb

Defined Under Namespace

Classes: NotEnoughConnections

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Ring

Returns a new instance of Ring.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ciclope/ring.rb', line 11

def initialize(*args)
  options = args.pop if args.last.is_a? Hash
  options ||= {}
  connections = Array(args).flatten.compact.uniq
  
  @hosts = []

  connections.each do |c|
    config = Rails.configuration.database_configuration[c.to_s]
    next unless config && config['adapter'] == 'mysql'
    @hosts << Host.new(ActiveRecord::Base.mysql_connection(config))
  end

  raise NotEnoughConnections if connections.size < 2
  @hosts = @hosts.sort if options[:sort_hosts] && @hosts.count > 2
end

Instance Attribute Details

#hostsObject (readonly)

Returns the value of attribute hosts.



9
10
11
# File 'lib/ciclope/ring.rb', line 9

def hosts
  @hosts
end