class AdvancedConnection::Config
Constants
- CALLBACK_TYPES
- DEFAULT_CONFIG
- VALID_QUEUE_TYPES
Attributes
loaded[R]
loaded?[R]
Public Class Methods
add_callback(*names)
click to toggle source
# File lib/advanced_connection/config.rb, line 69 def add_callback(*names) Array(names).flatten.each { |name| class_eval(<<-EOS, __FILE__, __LINE__ + 1) def #{name}_callbacks @config.callbacks.#{name} ||= CALLBACK_TYPES.dup end def #{name}_callbacks=(value) if not value.is_a? Hash fail Error::ConfigError, "#{name} callbacks must be a hash" elsif (bad_options = (value.keys.collect(&:to_sym) - CALLBACK_TYPES.keys)).size > 0 plural = bad_options .size > 1 ? 's' : '' fail Error::ConfigError, "Unexpected callback option\#{plural}: " \ " `\#{bad_options.join('`, `')}`" elsif (uncallable = value.select { |k,v| !v.respond_to? :call }).present? plural = uncallable.size > 1 ? 's' : '' fail Error::ConfigError, "Expected #{name} callback\#{plural}" \ " `\#{uncallable.keys.join('`, `')}` to be callable" end @config.callbacks.#{name} = CALLBACK_TYPES.merge(value) end EOS DEFAULT_CONFIG.callbacks[name.to_sym] = CALLBACK_TYPES.dup } end
Also aliased as: add_callbacks
include?(key)
click to toggle source
Calls superclass method
# File lib/advanced_connection/config.rb, line 65 def include?(key) instance.include?(key) || super end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/advanced_connection/config.rb, line 56 def method_missing(method, *args, &block) return super unless instance.include?(method) || instance.respond_to?(method) instance.public_send(method, *args, &block) end
new()
click to toggle source
# File lib/advanced_connection/config.rb, line 103 def initialize @loaded = false @config = DEFAULT_CONFIG.deep_dup @mutex = Monitor.new end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/advanced_connection/config.rb, line 61 def respond_to_missing?(method, include_private = false) instance.respond_to?(method, include_private) || super end
Public Instance Methods
[](key)
click to toggle source
# File lib/advanced_connection/config.rb, line 126 def [](key) @config[key.to_sym] end
[]=(key, value)
click to toggle source
# File lib/advanced_connection/config.rb, line 130 def []=(key, value) public_send("#{key}=".to_sym, value) end
callbacks()
click to toggle source
# File lib/advanced_connection/config.rb, line 142 def callbacks @config.callbacks end
can_enable?()
click to toggle source
# File lib/advanced_connection/config.rb, line 114 def can_enable? # don't enable if we're running rake tasks generally, # and specifically, if it's db: or assets: tasks return false if $0.include? 'rake' return false if ARGV.grep(/^(assets|db):/).any? true end
connection_pool_queue_type()
click to toggle source
# File lib/advanced_connection/config.rb, line 252 def connection_pool_queue_type @config[:connection_pool_queue_type] end
connection_pool_queue_type=(value)
click to toggle source
# File lib/advanced_connection/config.rb, line 256 def connection_pool_queue_type=(value) unless value.is_a?(String) || value.is_a?(Symbol) fail Error::ConfigError, 'Expected String or Symbol for connection_pool_queue_type ' \ "but found `#{value.class.name}`" end unless VALID_QUEUE_TYPES.include? value.to_sym fail Error::ConfigError, 'Expected connection_pool_queue_type to be one of ' \ ':fifo, :lifo, :stack, :prefer_younger, or :prefer_older ' \ "but found `#{value.inspect}`" end synchronize { @config[:connection_pool_queue_type] = value } end
enable_idle_connection_manager()
click to toggle source
# File lib/advanced_connection/config.rb, line 183 def enable_idle_connection_manager @config[:enable_idle_connection_manager] end
enable_idle_connection_manager=(value)
click to toggle source
# File lib/advanced_connection/config.rb, line 187 def enable_idle_connection_manager=(value) synchronize { @config[:enable_idle_connection_manager] = !!value } end
enable_statement_pooling()
click to toggle source
# File lib/advanced_connection/config.rb, line 172 def enable_statement_pooling @config[:enable_statement_pooling] end
enable_statement_pooling=(value)
click to toggle source
# File lib/advanced_connection/config.rb, line 176 def enable_statement_pooling=(value) if enable_without_connection && !!value raise Error::ConfigError, "Statement Pooling conflicts with WithoutConnection feature" end synchronize { @config[:enable_statement_pooling] = !!value } end
enable_without_connection()
click to toggle source
# File lib/advanced_connection/config.rb, line 161 def enable_without_connection @config[:enable_without_connection] end
enable_without_connection=(value)
click to toggle source
# File lib/advanced_connection/config.rb, line 165 def enable_without_connection=(value) if enable_statement_pooling && !!value raise Error::ConfigError, "WithoutConnection blocks conflict with Statement Pooling feature" end synchronize { @config[:enable_without_connection] = !!value } end
idle_check_interval()
click to toggle source
# File lib/advanced_connection/config.rb, line 240 def idle_check_interval @config[:idle_check_interval] end
idle_check_interval=(value)
click to toggle source
# File lib/advanced_connection/config.rb, line 244 def idle_check_interval=(value) unless value.is_a?(Numeric) || value =~ /^\d+$/ fail Error::ConfigError, 'Expected idle_check_interval to be ' \ "a valid integer value, but found `#{value.inspect}`" end synchronize { @config[:idle_check_interval] = value.to_i } end
idle_manager_log_level()
click to toggle source
# File lib/advanced_connection/config.rb, line 146 def idle_manager_log_level @config[:log_level] end
idle_manager_log_level=(level)
click to toggle source
# File lib/advanced_connection/config.rb, line 150 def idle_manager_log_level=(level) @config[:log_level] = case level when :debug, /debug/i, ::Logger::DEBUG then ::Logger::DEBUG when :info, /info/i, ::Logger::INFO then ::Logger::INFO when :warn, /warn/i, ::Logger::WARN then ::Logger::WARN when :error, /error/i, ::Logger::ERROR then ::Logger::ERROR when :fatal, /fatal/i, ::Logger::FATAL then ::Logger::FATAL else ::Logger::INFO end end
include?(key)
click to toggle source
# File lib/advanced_connection/config.rb, line 134 def include?(key) @config.include? key.to_s.tr('=', '').to_sym end
loaded!()
click to toggle source
# File lib/advanced_connection/config.rb, line 122 def loaded! synchronize { @loaded = true } end
max_idle_connections()
click to toggle source
# File lib/advanced_connection/config.rb, line 209 def max_idle_connections @config[:max_idle_connections] end
max_idle_connections=(value)
click to toggle source
# File lib/advanced_connection/config.rb, line 213 def max_idle_connections=(value) unless value.is_a?(Numeric) || value =~ /^\d+$/ fail Error::ConfigError, 'Expected max_idle_connections to be ' \ "a valid integer value, but found `#{value.inspect}`" end synchronize { @config[:max_idle_connections] = begin value.to_i rescue FloatDomainError raise unless $!.message =~ /infinity/i ::Float::INFINITY end } end
max_idle_time()
click to toggle source
# File lib/advanced_connection/config.rb, line 228 def max_idle_time @config[:max_idle_time] end
max_idle_time=(value)
click to toggle source
# File lib/advanced_connection/config.rb, line 232 def max_idle_time=(value) unless value.is_a?(Numeric) || value =~ /^\d+$/ fail Error::ConfigError, 'Expected max_idle_time to be ' \ "a valid integer value, but found `#{value.inspect}`" end synchronize { @config[:max_idle_time] = value.to_i } end
min_idle_connections()
click to toggle source
# File lib/advanced_connection/config.rb, line 200 def min_idle_connections # deprecated and not used 0 end
min_idle_connections=(value)
click to toggle source
# File lib/advanced_connection/config.rb, line 205 def min_idle_connections=(value) # deprecated and not used end
to_h()
click to toggle source
# File lib/advanced_connection/config.rb, line 138 def to_h @config.dup end
warmup_connections()
click to toggle source
# File lib/advanced_connection/config.rb, line 191 def warmup_connections # deprecated and not used 0 end
warmup_connections=(value)
click to toggle source
# File lib/advanced_connection/config.rb, line 196 def warmup_connections=(value) # deprecated and not used end
Private Instance Methods
synchronize() { || ... }
click to toggle source
# File lib/advanced_connection/config.rb, line 109 def synchronize @mutex.synchronize { yield } end