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
- #update(dn, attributes, options = {}) ⇒ Object
- #update_all(attributes, filter = nil, options = {}) ⇒ Object
Instance Method Details
#add_entry(dn, attributes, options = {}) ⇒ Object
363 364 365 366 367 368 369 |
# File 'lib/active_ldap/operations.rb', line 363 def add_entry(dn, attributes, ={}) unnormalized_attributes = attributes.collect do |type, key, value| [type, key, unnormalize_attribute(key, value)] end conn = [:connection] || connection conn.add(dn, unnormalized_attributes, ) end |
#modify_entry(dn, attributes, options = {}) ⇒ Object
371 372 373 374 375 376 377 |
# File 'lib/active_ldap/operations.rb', line 371 def modify_entry(dn, attributes, ={}) unnormalized_attributes = attributes.collect do |type, key, value| [type, key, unnormalize_attribute(key, value)] end conn = [:connection] || connection conn.modify(dn, unnormalized_attributes, ) end |
#update(dn, attributes, options = {}) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/active_ldap/operations.rb', line 379 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
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/active_ldap/operations.rb', line 394 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 conn = [:connection] || connection targets.each do |dn| conn.modify(dn, unnormalized_attributes, ) end end |