Module: SeamlessDatabasePool::ControllerFilter::ClassMethods

Defined in:
lib/seamless_database_pool/controller_filter.rb

Instance Method Summary collapse

Instance Method Details

#seamless_database_pool_optionsObject


32
33
34
35
36
# File 'lib/seamless_database_pool/controller_filter.rb', line 32

def seamless_database_pool_options
  return @seamless_database_pool_options if @seamless_database_pool_options
  @seamless_database_pool_options = superclass.seamless_database_pool_options.dup if superclass.respond_to?(:seamless_database_pool_options)
  @seamless_database_pool_options ||= {}
end

#use_database_pool(options) ⇒ Object

Call this method to set up the connection types that will be used for your actions. The configuration is given as a hash where the key is the action name and the value is the connection type (:master, :persistent, or :random). You can specify :all as the action to define a default connection type. You can also specify the action names in an array to easily map multiple actions to one connection type.

The configuration is inherited from parent controller classes, so if you have default behavior, you should simply specify it in ApplicationController to have it available globally.


47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/seamless_database_pool/controller_filter.rb', line 47

def use_database_pool(options)
  remapped_options = seamless_database_pool_options
  options.each_pair do |actions, connection_method|
    unless SeamlessDatabasePool::READ_CONNECTION_METHODS.include?(connection_method)
      raise "Invalid read pool method: #{connection_method}; should be one of #{SeamlessDatabasePool::READ_CONNECTION_METHODS.inspect}"
    end
    actions = [actions] unless actions.kind_of?(Array)
    actions.each do |action|
      remapped_options[action.to_sym] = connection_method
    end
  end
  @seamless_database_pool_options = remapped_options
end