Module: ActiveLdap::Operations::Update

Defined in:
lib/active_ldap/operations.rb

Instance Method Summary collapse

Instance Method Details

#add_entry(dn, attributes, options = {}) ⇒ Object



558
559
560
561
562
563
564
# File 'lib/active_ldap/operations.rb', line 558

def add_entry(dn, attributes, options={})
  unnormalized_attributes = attributes.collect do |key, value|
    [:add, key, unnormalize_attribute(key, value)]
  end
  options[:connection] ||= connection
  options[:connection].add(dn, unnormalized_attributes, options)
end

#modify_entry(dn, attributes, options = {}) ⇒ Object



566
567
568
569
570
571
572
573
# File 'lib/active_ldap/operations.rb', line 566

def modify_entry(dn, attributes, options={})
  return if attributes.empty?
  unnormalized_attributes = attributes.collect do |type, key, value|
    [type, key, unnormalize_attribute(key, value)]
  end
  options[:connection] ||= connection
  options[:connection].modify(dn, unnormalized_attributes, options)
end

#modify_rdn_entry(dn, new_rdn, delete_old_rdn, new_superior, options = {}) ⇒ Object



575
576
577
578
579
# File 'lib/active_ldap/operations.rb', line 575

def modify_rdn_entry(dn, new_rdn, delete_old_rdn, new_superior, options={})
  options[:connection] ||= connection
  options[:connection].modify_rdn(dn, new_rdn, delete_old_rdn,
                                  new_superior, options)
end

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



581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/active_ldap/operations.rb', line 581

def update_all(attributes, filter=nil, options={})
  search_options = options.dup
  if filter
    if filter.is_a?(String) and /[=\(\)&\|]/ !~ filter
      search_options = search_options.merge(:value => filter)
    else
      search_options = search_options.merge(:filter => filter)
    end
  end
  targets = search(search_options).collect do |dn, attrs|
    dn
  end

  unnormalized_attributes = attributes.collect do |name, value|
    normalized_name, normalized_value = normalize_attribute(name, value)
    [:replace, normalized_name,
     unnormalize_attribute(normalized_name, normalized_value)]
  end
  options[:connection] ||= connection
  conn = options[:connection]
  targets.each do |dn|
    conn.modify(dn, unnormalized_attributes, options)
  end
end