Module: ActiveLdap::Connection::ClassMethods
- Defined in:
- lib/active_ldap/connection.rb
Constant Summary collapse
- @@active_connections =
{}
Instance Method Summary collapse
- #active_connection_name ⇒ Object
- #active_connections ⇒ Object
- #clear_active_connection_name ⇒ Object
- #clear_active_connections! ⇒ Object
- #connected? ⇒ Boolean
- #connection ⇒ Object
- #connection=(adaptor) ⇒ Object
- #establish_connection(config = nil) ⇒ Object
- #remove_connection(klass = self) ⇒ Object
- #retrieve_connection ⇒ Object
-
#schema ⇒ Object
Return the schema object.
Instance Method Details
#active_connection_name ⇒ Object
14 15 16 |
# File 'lib/active_ldap/connection.rb', line 14 def active_connection_name @active_connection_name ||= determine_active_connection_name end |
#active_connections ⇒ Object
10 11 12 |
# File 'lib/active_ldap/connection.rb', line 10 def active_connections @@active_connections[Thread.current.object_id] ||= {} end |
#clear_active_connection_name ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/active_ldap/connection.rb', line 26 def clear_active_connection_name @active_connection_name = nil ObjectSpace.each_object(Class) do |klass| if klass < self and !klass.name.empty? klass.instance_variable_set("@active_connection_name", nil) end end end |
#clear_active_connections! ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/active_ldap/connection.rb', line 18 def clear_active_connections! connections = active_connections connections.each do |key, connection| connection.disconnect! end connections.clear end |
#connected? ⇒ Boolean
63 64 65 |
# File 'lib/active_ldap/connection.rb', line 63 def connected? active_connections[active_connection_name] ? true : false end |
#connection ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_ldap/connection.rb', line 35 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 |
#connection=(adaptor) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_ldap/connection.rb', line 48 def connection=(adaptor) if adaptor.is_a?(Adaptor::Base) @schema = nil active_connections[active_connection_name] = adaptor elsif adaptor.is_a?(Hash) config = adaptor adaptor = Inflector.camelize(config[:adaptor] || "ldap") self.connection = Adaptor.const_get(adaptor).new(config) elsif adaptor.nil? raise ConnectionNotEstablished else establish_connection(adaptor) end end |
#establish_connection(config = nil) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/active_ldap/connection.rb', line 92 def establish_connection(config=nil) config = ensure_configuration(config) remove_connection clear_active_connection_name key = active_connection_key @active_connection_name = key define_configuration(key, merge_configuration(config)) end |
#remove_connection(klass = self) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/active_ldap/connection.rb', line 82 def remove_connection(klass=self) key = active_connection_key(klass) config = configuration(key) conn = active_connections[key] remove_configuration_by_configuration(config) active_connections.delete_if {|key, value| value == conn} conn.disconnect! if conn config end |
#retrieve_connection ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/active_ldap/connection.rb', line 67 def retrieve_connection conn = nil name = active_connection_name raise ConnectionNotEstablished unless name conn = active_connections[name] if conn.nil? config = configuration(name) raise ConnectionNotEstablished unless config self.connection = config conn = active_connections[name] end raise ConnectionNotEstablished if conn.nil? conn end |
#schema ⇒ Object
Return the schema object
103 104 105 |
# File 'lib/active_ldap/connection.rb', line 103 def schema @schema ||= connection.schema end |