Module: SeamlessDatabasePool::ControllerFilter::ClassMethods
- Defined in:
- lib/seamless_database_pool/controller_filter.rb
Instance Method Summary collapse
- #seamless_database_pool_options ⇒ Object
-
#use_database_pool(options) ⇒ Object
Call this method to set up the connection types that will be used for your actions.
Instance Method Details
#seamless_database_pool_options ⇒ Object
25 26 27 28 29 |
# File 'lib/seamless_database_pool/controller_filter.rb', line 25 def return @seamless_database_pool_options if @seamless_database_pool_options @seamless_database_pool_options = superclass..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.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/seamless_database_pool/controller_filter.rb', line 40 def use_database_pool() = .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| [action.to_sym] = connection_method end end @seamless_database_pool_options = end |