lib/octoshark.rb in octoshark-0.0.9 vs lib/octoshark.rb in octoshark-0.1.0
- old
+ new
@@ -1,57 +1,25 @@
require 'octoshark/version'
require 'active_record'
require 'octoshark/active_record_extensions'
module Octoshark
- autoload :ConnectionSwitcher, 'octoshark/connection_switcher'
+ autoload :ConnectionManager, 'octoshark/connection_manager'
+ autoload :Error, 'octoshark/error'
- class NotConfiguredError < RuntimeError; end
- class NoConnectionError < StandardError; end;
- class NoCurrentConnectionError < StandardError; end;
+ # Octoshark needs to keep track of all connection managers in order to
+ # automatically reconnect on connection establish.
+ @@connection_managers = []
- OCTOSHARK = :octoshark
+ def self.connection_managers
+ @@connection_managers
+ end
- class << self
- delegate :connection_pools,
- :current_or_default_connection,
- :disconnect!,
- :find_connection_pool,
- :with_connection,
- :without_connection,
- :current_connection,
- :current_connection?,
- to: :switcher
+ def self.reset_connection_managers!
+ connection_managers.map(&:reset!)
+ end
- def configure(configs)
- @configs = configs
- @switcher = ConnectionSwitcher.new(configs)
- end
-
- def reset!
- return unless configured?
- disconnect!
- @confings = nil
- @switcher = nil
- Thread.current[OCTOSHARK] = nil
- end
-
- def reload!
- raise_not_configured_error unless @configs
- disconnect!
- @switcher = ConnectionSwitcher.new(@configs)
- end
-
- def configured?
- !@switcher.nil?
- end
-
- def switcher
- @switcher || raise_not_configured_error
- end
-
- private
- def raise_not_configured_error
- raise NotConfiguredError, "Octoshark is not configured, use Octoshark.configure"
- end
+ def self.disconnect!
+ connection_managers.map(&:disconnect!)
+ @@connection_managers = []
end
end