| Module | ActiveLdap::Connection::ClassMethods |
| In: |
lib/active_ldap/connection.rb
|
# File lib/active_ldap/connection.rb, line 14
14: def active_connection_name
15: @active_connection_name ||= determine_active_connection_name
16: end
# File lib/active_ldap/connection.rb, line 10
10: def active_connections
11: @@active_connections[Thread.current.object_id] ||= {}
12: end
# File lib/active_ldap/connection.rb, line 26
26: def clear_active_connection_name
27: @active_connection_name = nil
28: ObjectSpace.each_object(Class) do |klass|
29: if klass < self and !klass.name.empty?
30: klass.instance_variable_set("@active_connection_name", nil)
31: end
32: end
33: end
# File lib/active_ldap/connection.rb, line 18
18: def clear_active_connections!
19: connections = active_connections
20: connections.each do |key, connection|
21: connection.disconnect!
22: end
23: connections.clear
24: end
# File lib/active_ldap/connection.rb, line 69
69: def connected?
70: active_connections[active_connection_name] ? true : false
71: end
# File lib/active_ldap/connection.rb, line 35
35: def connection
36: conn = nil
37: @active_connection_name ||= nil
38: if @active_connection_name
39: conn = active_connections[@active_connection_name]
40: end
41: unless conn
42: conn = retrieve_connection
43: active_connections[@active_connection_name] = conn
44: end
45: conn
46: end
# File lib/active_ldap/connection.rb, line 48
48: def connection=(adapter)
49: if adapter.is_a?(Adapter::Base)
50: @schema = nil
51: active_connections[active_connection_name] = adapter
52: elsif adapter.is_a?(Hash)
53: config = adapter
54: adapter = (config[:adapter] || "ldap")
55: normalized_adapter = adapter.downcase.gsub(/-/, "_")
56: adapter_method = "#{normalized_adapter}_connection"
57: unless Adapter::Base.respond_to?(adapter_method)
58: raise AdapterNotFound.new(adapter)
59: end
60: config = remove_connection_related_configuration(config)
61: self.connection = Adapter::Base.send(adapter_method, config)
62: elsif adapter.nil?
63: raise ConnectionNotEstablished
64: else
65: establish_connection(adapter)
66: end
67: end
# File lib/active_ldap/connection.rb, line 98
98: def establish_connection(config=nil)
99: config = ensure_configuration(config)
100: remove_connection
101:
102: clear_active_connection_name
103: key = active_connection_key
104: @active_connection_name = key
105: define_configuration(key, merge_configuration(config))
106: end
# File lib/active_ldap/connection.rb, line 88
88: def remove_connection(klass=self)
89: key = active_connection_key(klass)
90: config = configuration(key)
91: conn = active_connections[key]
92: remove_configuration_by_configuration(config)
93: active_connections.delete_if {|key, value| value == conn}
94: conn.disconnect! if conn
95: config
96: end
# File lib/active_ldap/connection.rb, line 73
73: def retrieve_connection
74: conn = nil
75: name = active_connection_name
76: raise ConnectionNotEstablished unless name
77: conn = active_connections[name]
78: if conn.nil?
79: config = configuration(name)
80: raise ConnectionNotEstablished unless config
81: self.connection = config
82: conn = active_connections[name]
83: end
84: raise ConnectionNotEstablished if conn.nil?
85: conn
86: end
# File lib/active_ldap/connection.rb, line 114
114: def active_connection_key(k=self)
115: k.name.empty? ? k.object_id : k.name
116: end