Module: ActiveLdap::Operations::Delete

Defined in:
lib/active_ldap/operations.rb

Instance Method Summary collapse

Instance Method Details

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



444
445
446
447
448
449
450
# File 'lib/active_ldap/operations.rb', line 444

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

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



457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/active_ldap/operations.rb', line 457

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

  conn.delete(targets)
end

#delete_entry(dn, options = {}) ⇒ Object



452
453
454
455
# File 'lib/active_ldap/operations.rb', line 452

def delete_entry(dn, options={})
  options[:connection] ||= connection
  options[:connection].delete(dn, options)
end

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



423
424
425
426
427
428
# File 'lib/active_ldap/operations.rb', line 423

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



430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/active_ldap/operations.rb', line 430

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