Module: ActiveLdap::Operations::Update
- Defined in:
- lib/active_ldap/operations.rb
Instance Method Summary collapse
- #add_entry(dn, attributes, options = {}) ⇒ Object
- #modify_entry(dn, attributes, options = {}) ⇒ Object
- #modify_rdn_entry(dn, new_rdn, delete_old_rdn, new_superior, options = {}) ⇒ Object
- #update(dn, attributes, options = {}) ⇒ Object
- #update_all(attributes, filter = nil, options = {}) ⇒ Object
Instance Method Details
#add_entry(dn, attributes, options = {}) ⇒ Object
546 547 548 549 550 551 552 |
# File 'lib/active_ldap/operations.rb', line 546 def add_entry(dn, attributes, ={}) unnormalized_attributes = attributes.collect do |key, value| [:add, key, unnormalize_attribute(key, value)] end [:connection] ||= connection [:connection].add(dn, unnormalized_attributes, ) end |
#modify_entry(dn, attributes, options = {}) ⇒ Object
554 555 556 557 558 559 560 561 |
# File 'lib/active_ldap/operations.rb', line 554 def modify_entry(dn, attributes, ={}) return if attributes.empty? unnormalized_attributes = attributes.collect do |type, key, value| [type, key, unnormalize_attribute(key, value)] end [:connection] ||= connection [:connection].modify(dn, unnormalized_attributes, ) end |
#modify_rdn_entry(dn, new_rdn, delete_old_rdn, new_superior, options = {}) ⇒ Object
563 564 565 566 567 |
# File 'lib/active_ldap/operations.rb', line 563 def modify_rdn_entry(dn, new_rdn, delete_old_rdn, new_superior, ={}) [:connection] ||= connection [:connection].modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, ) end |
#update(dn, attributes, options = {}) ⇒ Object
569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/active_ldap/operations.rb', line 569 def update(dn, attributes, ={}) if dn.is_a?(Array) i = -1 dns = dn dns.collect do |_dn| i += 1 update(_dn, attributes[i], ) end else object = find(dn, ) object.update_attributes(attributes) object end end |
#update_all(attributes, filter = nil, options = {}) ⇒ Object
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/active_ldap/operations.rb', line 584 def update_all(attributes, filter=nil, ={}) = .dup if filter if filter.is_a?(String) and /[=\(\)&\|]/ !~ filter = .merge(:value => filter) else = .merge(:filter => filter) end end targets = search().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 [:connection] ||= connection conn = [:connection] targets.each do |dn| conn.modify(dn, unnormalized_attributes, ) end end |