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

#fetch_master_connectionObject



43
44
45
# File 'lib/connection_manager/replication.rb', line 43

def fetch_master_connection
  fetch_replication_connection(:masters)
end

#fetch_slave_connectionObject



39
40
41
# File 'lib/connection_manager/replication.rb', line 39

def fetch_slave_connection
  fetch_replication_connection(:slaves)
end

#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



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

def replicated(*connections)
  opts = connections.extract_options!
  opts.symbolize_keys!
  opts[:slaves] ||= []
  opts[:masters] ||= []
  opts[:type] ||= :slaves
  opts[opts[:type]] = connections unless connections.empty?
  set_replications_connections(opts)
end

#replicated?Boolean

Is this class replicated

Returns:

  • (Boolean)


13
14
15
# File 'lib/connection_manager/replication.rb', line 13

def replicated?
  defined?(@replication_connections)
end