Module: ActiveLdap::Operations::Update

Defined in:
lib/active_ldap/operations.rb

Instance Method Summary collapse

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, options={})
  unnormalized_attributes = attributes.collect do |type, key, value|
    [type, key, unnormalize_attribute(key, value)]
  end
  conn = options[:connection] || connection
  conn.add(dn, unnormalized_attributes, options)
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, options={})
  unnormalized_attributes = attributes.collect do |type, key, value|
    [type, key, unnormalize_attribute(key, value)]
  end
  conn = options[:connection] || connection
  conn.modify(dn, unnormalized_attributes, options)
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, options={})
  if dn.is_a?(Array)
    i = -1
    dns = dn
    dns.collect do |dn|
      i += 1
      update(dn, attributes[i], options)
    end
  else
    object = find(dn, options)
    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, 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
  conn = options[:connection] || connection
  targets.each do |dn|
    conn.modify(dn, unnormalized_attributes, options)
  end
end