Method: LDAP::LDIF.mods_to_ldif

Defined in:
lib/ldap/ldif.rb

.mods_to_ldif(dn, *mods) ⇒ Object

Given the DN, dn, convert a single LDAP::Mod or an array of LDAP::Mod objects, given in mods, to LDIF.



493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/ldap/ldif.rb', line 493

def LDIF.mods_to_ldif( dn, *mods )
  ldif = "dn: %s\nchangetype: modify\n" % dn
  plural = false

  mods.flatten.each do |mod|
    # TODO: Need to dynamically assemble this case statement to add
    # OpenLDAP's increment change type, etc.
    change_type = case mod.mod_op & ~LDAP_MOD_BVALUES
      when LDAP_MOD_ADD     then 'add'
      when LDAP_MOD_DELETE  then 'delete'
      when LDAP_MOD_REPLACE then 'replace'
    end

    ldif << "-\n" if plural
    ldif << LDIF.to_ldif( change_type, [mod.mod_type] )
    ldif << LDIF.to_ldif( mod.mod_type, mod.mod_vals )

    plural = true
  end

  LDIF::Mod.new( ldif )
end