Module: ConnectionManager::Replication

Defined in:
lib/connection_manager/replication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#replication_connectionsObject

Replication methods (replication_method_name, which is the option for the #replication method) and all their associated connections. The key is the replication_method_name and the value is an array of all the replication_classes the replication_method has access to.

EX: replication_methods => [‘Slave1Connection’,Slave2Connection]



10
11
12
# File 'lib/connection_manager/replication.rb', line 10

def replication_connections
  @replication_connections
end

Instance Method Details

#replicated(*connections) ⇒ Object

Builds a class method that returns an ActiveRecord::Relation for use with in ActiveRecord method chaining.

EX: class MyClass < ActiveRecord::Base

replicated :my_readonly_db, "FooConnection",
end

end

Options:

  • :name - name of class method to call to access replication, default to slaves

  • :type - the type of replication; :slaves or :masters, defaults to :slaves



32
33
34
35
36
# File 'lib/connection_manager/replication.rb', line 32

def replicated(*connections)
  options = {:slaves => [], :masters => [], :type => :slaves}.merge(connections.extract_options!.symbolize_keys)
  options[options[:type]] = connections unless connections.empty?
  set_replications_connections(options)
end

#replicated?Boolean

Is this class replicated

Returns:

  • (Boolean)


16
17
18
# File 'lib/connection_manager/replication.rb', line 16

def replicated?
  (@replication_connections && (!replication_connections[:slaves].empty? || !replication_connections[:masters].empty?))
end