Class LDAP::Record
In: lib/ldap/ldif.rb
Parent: Object

Record objects are embodiments of LDAP operations. They possess a DN, a change type (LDAP_MOD_ADD, LDAP_MOD_DELETE or LDAP_MOD_REPLACE [any of which can be logically AND‘ed with LDAP_MOD_BVALUES]), a hash of attributes and value arrays, a hash of modification operations (useful only when the change type is LDAP_MOD_REPLACE) and an array of LDAP controls.

The Record class‘s primary use is as a transitional medium for LDIF operations parsed by the LDAP::LDIF module. You are unlikely to want to use it in application code.

Methods

clean   new   send  

Attributes

attrs  [R] 
change_type  [R] 
controls  [R] 
dn  [R] 
mods  [R] 

Public Class methods

[Source]

    # File lib/ldap/ldif.rb, line 26
26:     def initialize(dn, change_type, attrs, mods=nil, ctls=nil)
27:       @dn = dn
28:       @change_type = change_type
29:       @attrs = attrs
30:       @mods = mods
31:       @controls = ctls
32:     end

Public Instance methods

Remove common operational attributes from a Record object. This is useful if you have Record objects formed from LDIF data that contained operational attributes. Using LDAP::Record#send to send such an object to an LDAP server is likely to meet with an exception unless the data is first cleaned.

In addition, attributes with duplicate values are pruned, as this can also result in an exception.

[Source]

    # File lib/ldap/ldif.rb, line 71
71:     def clean
72: 
73:       # TODO: These operational attributes are those commonly used by
74:       # OpenLDAP 2.2. Others should probably be supported.
75:       #
76:       %w[ creatorsname createtimestamp modifiersname modifytimestamp
77:           entrycsn entryuuid structuralobjectclass ].each do |attr|
78:         @attrs.delete( attr )
79:       end
80: 
81:       # Clean out duplicate attribute values.
82:       @attrs.each_key { |k| @attrs[k].uniq! }
83: 
84:       self
85:     end

Send the operation embodied in the Record object to the LDAP::Conn object specified in conn.

[Source]

    # File lib/ldap/ldif.rb, line 38
38:     def send( conn )
39:       if @change_type == :MODRDN
40:         # TODO: How do we deal with 'newsuperior'?
41:         # The LDAP API's ldap_modrdn2_s() function doesn't seem to use it.
42:         return conn.modrdn( @dn, @attrs['newrdn'], @attrs['deleteoldrdn'] )
43:       end
44: 
45:       # Mask out the LDAP_MOD_BVALUES bit, as it's irrelevant here.
46:       case @change_type & ~LDAP_MOD_BVALUES
47:       when LDAP_MOD_ADD
48:         @controls == [] ? conn.add( @dn, @attrs ) :
49:                           conn.add_ext( @dn, @attrs, @controls, [] )
50:       when LDAP_MOD_DELETE
51:         @controls == [] ? conn.delete( @dn ) :
52:                           conn.delete_ext( @dn, @controls, [] )
53:       when LDAP_MOD_REPLACE
54:         @controls == [] ? conn.modify( @dn, @mods ) :
55:                           conn.modify_ext( @dn, @mods, @controls, [] )
56:       end
57: 
58:       self
59:     end

[Validate]