Module: ActiveLdap::Operations::Delete

Defined in:
lib/active_ldap/operations.rb

Instance Method Summary collapse

Instance Method Details

#delete(targets, options = {}) ⇒ Object



339
340
341
342
343
344
345
346
# File 'lib/active_ldap/operations.rb', line 339

def delete(targets, options={})
  targets = [targets] unless targets.is_a?(Array)
  targets = targets.collect do |target|
    ensure_dn_attribute(ensure_base(target))
  end
  conn = options[:connection] || connection
  conn.delete(targets, options)
end

#delete_all(filter = nil, options = {}) ⇒ Object



348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/active_ldap/operations.rb', line 348

def delete_all(filter=nil, options={})
  options = {:base => base, :scope => scope}.merge(options)
  options = options.merge(:filter => filter) if filter
  conn = options[:connection] || connection
  targets = conn.search(options).collect do |dn, attributes|
    dn
  end.sort_by do |dn|
    dn.upcase.reverse
  end.reverse

  conn.delete(targets)
end

#destroy(targets, options = {}) ⇒ Object



318
319
320
321
322
323
# File 'lib/active_ldap/operations.rb', line 318

def destroy(targets, options={})
  targets = [targets] unless targets.is_a?(Array)
  targets.each do |target|
    find(target, options).destroy
  end
end

#destroy_all(filter = nil, options = {}) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/active_ldap/operations.rb', line 325

def destroy_all(filter=nil, options={})
  targets = []
  if filter.is_a?(Hash)
    options = options.merge(filter)
    filter = nil
  end
  options = options.merge(:filter => filter) if filter
  find(:all, options).sort_by do |target|
    target.dn.reverse
  end.reverse.each do |target|
    target.destroy
  end
end