Module: ConnectionManager::Replication
- Defined in:
- lib/connection_manager/replication.rb
Instance Attribute Summary collapse
-
#replication_connections ⇒ Object
Replication methods (replication_method_name, which is the option for the #replication method) and all their associated connections.
Instance Method Summary collapse
-
#replicated(*connections) ⇒ Object
Builds a class method that returns an ActiveRecord::Relation for use with in ActiveRecord method chaining.
-
#replicated? ⇒ Boolean
Is this class replicated.
Instance Attribute Details
#replication_connections ⇒ Object
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) = {:slaves => [], :masters => [], :type => :slaves}.merge(connections..symbolize_keys) [[:type]] = connections unless connections.empty? set_replications_connections() end |
#replicated? ⇒ Boolean
Is this class replicated
16 17 18 |
# File 'lib/connection_manager/replication.rb', line 16 def replicated? (@replication_connections && (!replication_connections[:slaves].empty? || !replication_connections[:masters].empty?)) end |