module ActiveLdap::Connection::ClassMethods
Public Instance Methods
Source
# File lib/active_ldap/connection.rb, line 170 def active_connection_key(k=self) k.name.blank? ? k.object_id : k.name end
Source
# File lib/active_ldap/connection.rb, line 37 def active_connection_name @active_connection_name ||= determine_active_connection_name end
Source
# File lib/active_ldap/connection.rb, line 55 def clear_active_connection_name @active_connection_name = nil ObjectSpace.each_object(Class) do |klass| if klass < self and !klass.name.blank? and !klass.frozen? klass.instance_variable_set("@active_connection_name", nil) end end end
Source
# File lib/active_ldap/connection.rb, line 47 def clear_active_connections! connections = active_connections connections.each do |key, connection| connection.disconnect! end connections.clear end
Source
# File lib/active_ldap/connection.rb, line 105 def connected? active_connections[active_connection_name] ? true : false end
Source
# File lib/active_ldap/connection.rb, line 64 def connection conn = nil @active_connection_name ||= nil if @active_connection_name conn = active_connections[@active_connection_name] end unless conn conn = retrieve_connection active_connections[@active_connection_name] = conn end conn end
Source
# File lib/active_ldap/connection.rb, line 77 def connection=(adapter) if adapter.is_a?(Adapter::Base) active_connections[active_connection_name] = adapter elsif adapter.is_a?(Hash) config = adapter self.connection = instantiate_adapter(config) elsif adapter.nil? raise ConnectionNotSetup else setup_connection(adapter) end end
Source
# File lib/active_ldap/connection.rb, line 101 def default_adapter @@default_adapter ||= guess_available_adapter end
Source
# File lib/active_ldap/connection.rb, line 90 def instantiate_adapter(config) adapter = (config[:adapter] || default_adapter) normalized_adapter = adapter.downcase.gsub(/-/, "_") adapter_method = "#{normalized_adapter}_connection" unless Adapter::Base.respond_to?(adapter_method) raise AdapterNotFound.new(adapter) end config = remove_connection_related_configuration(config) Adapter::Base.send(adapter_method, config) end
Source
# File lib/active_ldap/connection.rb, line 41 def remove_active_connections! active_connections.keys.each do |key| remove_connection(key) end end
Source
# File lib/active_ldap/connection.rb, line 124 def remove_connection(klass_or_key=self) if klass_or_key.is_a?(Module) key = active_connection_key(klass_or_key) else key = klass_or_key end config = configuration(key) conn = active_connections[key] remove_configuration_by_key(key) active_connections.delete_if {|_key, value| value == conn} conn.disconnect! if conn config end
Source
# File lib/active_ldap/connection.rb, line 109 def retrieve_connection conn = nil name = active_connection_name raise ConnectionNotSetup unless name conn = active_connections[name] if conn.nil? config = configuration(name) raise ConnectionNotSetup unless config self.connection = config conn = active_connections[name] end raise ConnectionNotSetup if conn.nil? conn end
Source
# File lib/active_ldap/connection.rb, line 166 def schema connection.schema end
Return the schema object
Source
# File lib/active_ldap/connection.rb, line 138 def setup_connection(config=nil) if config.is_a?(Hash) and config.size == 1 and config.key? :name name = config[:name] config = nil else name = nil end config = ensure_configuration(config) if name config = config[name.to_s] elsif config.is_a?(Hash) and config.values.all?(Hash) config = config["primary"] || config.values.first end unless config raise ConnectionError, _("%s connection is not configured") % (name || "primary") end remove_connection clear_active_connection_name key = active_connection_key @active_connection_name = key define_configuration(key, merge_configuration(config)) end
Source
# File lib/active_ldap/connection.rb, line 15 def single_threaded_active_connections @@active_connections end
Source
# File lib/active_ldap/connection.rb, line 11 def thread_safe_active_connections @@active_connections[Thread.current.object_id] ||= {} end
Private Instance Methods
Source
# File lib/active_ldap/connection.rb, line 186 def clear_all_cached_connections! if @@allow_concurrency @@active_connections.each_value do |connection_hash_for_thread| connection_hash_for_thread.each_value {|conn| conn.disconnect!} connection_hash_for_thread.clear end else @@active_connections.each_value {|conn| conn.disconnect!} end @@active_connections.clear end
Source
# File lib/active_ldap/connection.rb, line 175 def determine_active_connection_name key = active_connection_key if active_connections[key] or configuration(key) key elsif self == ActiveLdap::Base nil else superclass.active_connection_name end end
Source
# File lib/active_ldap/connection.rb, line 198 def guess_available_adapter if Object.respond_to?(:java) "jndi" else "net-ldap" end end