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)


268
269
270
# File 'lib/active_ldap/connection.rb', line 268

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

#connectionObject



253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/active_ldap/connection.rb', line 253

def connection
  conn = @connection
  return conn if conn

  have_dn = !@dn.nil?
  if !have_dn and attribute_name_resolvable_without_connection?
    begin
      have_dn = !get_attribute_before_type_cast(dn_attribute)[1].nil?
    rescue DistinguishedNameInvalid
    end
  end
  conn = self.class.active_connections[dn] || retrieve_connection if have_dn
  conn || self.class.connection
end

#connection=(adapter) ⇒ Object



272
273
274
275
276
277
278
279
280
281
# File 'lib/active_ldap/connection.rb', line 272

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
    setup_connection(adapter)
  end
end

#establish_connection(config = nil) ⇒ Object



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

def establish_connection(config=nil)
  message =
    _("ActiveLdap::Connection#establish_connection has been deprecated " \
      "since 1.1.0. " \
      "Please use ActiveLdap::Connection#setup_connection instead.")
  ActiveSupport::Deprecation.warn(message)
  setup_connection(config)
end

#remove_connectionObject



248
249
250
251
# File 'lib/active_ldap/connection.rb', line 248

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

#retrieve_connectionObject



283
284
285
286
287
288
289
290
291
292
293
# File 'lib/active_ldap/connection.rb', line 283

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



295
296
297
# File 'lib/active_ldap/connection.rb', line 295

def schema
  connection.schema
end

#setup_connection(config = nil) ⇒ Object



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

def setup_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