Method: ConnectionManager::Replication#replicated

Defined in:
lib/connection_manager/replication.rb

#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