Module | ActiveLdap::Connection::ClassMethods |
In: |
lib/active_ldap/connection.rb
|
# File lib/active_ldap/connection.rb, line 37 37: def active_connection_name 38: @active_connection_name ||= determine_active_connection_name 39: end
# File lib/active_ldap/connection.rb, line 55 55: def clear_active_connection_name 56: @active_connection_name = nil 57: ObjectSpace.each_object(Class) do |klass| 58: if klass < self and !klass.name.empty? 59: klass.instance_variable_set("@active_connection_name", nil) 60: end 61: end 62: end
# File lib/active_ldap/connection.rb, line 47 47: def clear_active_connections! 48: connections = active_connections 49: connections.each do |key, connection| 50: connection.disconnect! 51: end 52: connections.clear 53: end
# File lib/active_ldap/connection.rb, line 107 107: def connected? 108: active_connections[active_connection_name] ? true : false 109: end
# File lib/active_ldap/connection.rb, line 64 64: def connection 65: conn = nil 66: @active_connection_name ||= nil 67: if @active_connection_name 68: conn = active_connections[@active_connection_name] 69: end 70: unless conn 71: conn = retrieve_connection 72: active_connections[@active_connection_name] = conn 73: end 74: conn 75: end
# File lib/active_ldap/connection.rb, line 77 77: def connection=(adapter) 78: if adapter.is_a?(Adapter::Base) 79: active_connections[active_connection_name] = adapter 80: elsif adapter.is_a?(Hash) 81: config = adapter 82: self.connection = instantiate_adapter(config) 83: elsif adapter.nil? 84: raise ConnectionNotEstablished 85: else 86: establish_connection(adapter) 87: end 88: end
# File lib/active_ldap/connection.rb, line 140 140: def establish_connection(config=nil) 141: config = ensure_configuration(config) 142: remove_connection 143: 144: clear_active_connection_name 145: key = active_connection_key 146: @active_connection_name = key 147: define_configuration(key, merge_configuration(config)) 148: end
# File lib/active_ldap/connection.rb, line 90 90: def instantiate_adapter(config) 91: adapter = (config[:adapter] || "ldap") 92: normalized_adapter = adapter.downcase.gsub(/-/, "_") 93: adapter_method = "#{normalized_adapter}_connection" 94: unless Adapter::Base.respond_to?(adapter_method) 95: raise AdapterNotFound.new(adapter) 96: end 97: if config.has_key?(:ldap_scope) 98: logger.warning do 99: _(":ldap_scope connection option is deprecated. Use :scope instead.") 100: end 101: config[:scope] ||= config.delete(:ldap_scope) 102: end 103: config = remove_connection_related_configuration(config) 104: Adapter::Base.send(adapter_method, config) 105: end
# File lib/active_ldap/connection.rb, line 41 41: def remove_active_connections! 42: active_connections.keys.each do |key| 43: remove_connection(key) 44: end 45: end
# File lib/active_ldap/connection.rb, line 126 126: def remove_connection(klass_or_key=self) 127: if klass_or_key.is_a?(Module) 128: key = active_connection_key(klass_or_key) 129: else 130: key = klass_or_key 131: end 132: config = configuration(key) 133: conn = active_connections[key] 134: remove_configuration_by_configuration(config) 135: active_connections.delete_if {|key, value| value == conn} 136: conn.disconnect! if conn 137: config 138: end
# File lib/active_ldap/connection.rb, line 111 111: def retrieve_connection 112: conn = nil 113: name = active_connection_name 114: raise ConnectionNotEstablished unless name 115: conn = active_connections[name] 116: if conn.nil? 117: config = configuration(name) 118: raise ConnectionNotEstablished unless config 119: self.connection = config 120: conn = active_connections[name] 121: end 122: raise ConnectionNotEstablished if conn.nil? 123: conn 124: end
# File lib/active_ldap/connection.rb, line 15 15: def single_threaded_active_connections 16: @@active_connections 17: end
# File lib/active_ldap/connection.rb, line 11 11: def thread_safe_active_connections 12: @@active_connections[Thread.current.object_id] ||= {} 13: end
# File lib/active_ldap/connection.rb, line 156 156: def active_connection_key(k=self) 157: k.name.empty? ? k.object_id : k.name 158: end
# File lib/active_ldap/connection.rb, line 171 171: def clear_all_cached_connections! 172: if @@allow_concurrency 173: @@active_connections.each_value do |connection_hash_for_thread| 174: connection_hash_for_thread.each_value {|conn| conn.disconnect!} 175: connection_hash_for_thread.clear 176: end 177: else 178: @@active_connections.each_value {|conn| conn.disconnect!} 179: end 180: @@active_connections.clear 181: end