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)


203
204
205
# File 'lib/active_ldap/connection.rb', line 203

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

#connectionObject



197
198
199
200
201
# File 'lib/active_ldap/connection.rb', line 197

def connection
  conn = @connection
  conn ||= self.class.active_connections[dn] || retrieve_connection if id
  conn || self.class.connection
end

#connection=(adapter) ⇒ Object



207
208
209
210
211
212
213
214
215
216
# File 'lib/active_ldap/connection.rb', line 207

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



184
185
186
187
188
189
190
191
# File 'lib/active_ldap/connection.rb', line 184

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



193
194
195
# File 'lib/active_ldap/connection.rb', line 193

def remove_connection
  self.class.remove_connection(dn)
end

#retrieve_connectionObject



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/active_ldap/connection.rb', line 218

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



230
231
232
# File 'lib/active_ldap/connection.rb', line 230

def schema
  connection.schema
end