Module: ActiveLdap::Connection

Defined in:
lib/active_ldap/connection.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/active_ldap/connection.rb', line 3

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


224
225
226
# File 'lib/active_ldap/connection.rb', line 224

def connected?
  connection != self.class.connection
end

#connectionObject



212
213
214
215
216
217
218
219
220
221
222
# File 'lib/active_ldap/connection.rb', line 212

def connection
  conn = @connection
  return conn if conn

  if @dn or
      (attribute_name_resolvable_without_connection? and
       get_attribute_before_type_cast(dn_attribute)[1])
    conn = self.class.active_connections[dn] || retrieve_connection
  end
  conn || self.class.connection
end

#connection=(adapter) ⇒ Object



228
229
230
231
232
233
234
235
236
237
# File 'lib/active_ldap/connection.rb', line 228

def connection=(adapter)
  if adapter.nil? or adapter.is_a?(Adapter::Base)
    @connection = adapter
  elsif adapter.is_a?(Hash)
    config = adapter
    @connection = self.class.instantiate_adapter(config)
  else
    establish_connection(adapter)
  end
end

#establish_connection(config = nil) ⇒ Object



198
199
200
201
202
203
204
205
# File 'lib/active_ldap/connection.rb', line 198

def establish_connection(config=nil)
  config = self.class.ensure_configuration(config)
  config = self.class.configuration.merge(config)
  config = self.class.merge_configuration(config, self)

  remove_connection
  self.class.define_configuration(dn, config)
end

#remove_connectionObject



207
208
209
210
# File 'lib/active_ldap/connection.rb', line 207

def remove_connection
  self.class.remove_connection(dn)
  @connection = nil
end

#retrieve_connectionObject



239
240
241
242
243
244
245
246
247
248
249
# File 'lib/active_ldap/connection.rb', line 239

def retrieve_connection
  conn = self.class.active_connections[dn]
  return conn if conn

  config = self.class.configuration(dn)
  return nil unless config

  conn = self.class.instantiate_adapter(config)
  @connection = self.class.active_connections[dn] = conn
  conn
end

#schemaObject



251
252
253
# File 'lib/active_ldap/connection.rb', line 251

def schema
  connection.schema
end