| 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.
| attrs | [R] | |
| change_type | [R] | |
| controls | [R] | |
| dn | [R] | |
| mods | [R] |
# File lib/ldap/ldif.rb, line 24
24: def initialize(dn, change_type, attrs, mods=nil, ctls=nil)
25: @dn = dn
26: @change_type = change_type
27: @attrs = attrs
28: @mods = mods
29: @controls = ctls
30: end
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.
# File lib/ldap/ldif.rb, line 69
69: def clean
70:
71: # TODO: These operational attributes are those commonly used by
72: # OpenLDAP 2.2. Others should probably be supported.
73: #
74: %w[ creatorsname createtimestamp modifiersname modifytimestamp
75: entrycsn entryuuid structuralobjectclass ].each do |attr|
76: @attrs.delete( attr )
77: end
78:
79: # Clean out duplicate attribute values.
80: @attrs.each_key { |k| @attrs[k].uniq! }
81:
82: self
83: end
Send the operation embodied in the Record object to the LDAP::Conn object specified in conn.
# File lib/ldap/ldif.rb, line 36
36: def send( conn )
37: if @change_type == :MODRDN
38: # TODO: How do we deal with 'newsuperior'?
39: # The LDAP API's ldap_modrdn2_s() function doesn't seem to use it.
40: return conn.modrdn( @dn, @attrs['newrdn'], @attrs['deleteoldrdn'] )
41: end
42:
43: # Mask out the LDAP_MOD_BVALUES bit, as it's irrelevant here.
44: case @change_type & ~LDAP_MOD_BVALUES
45: when LDAP_MOD_ADD
46: @controls == [] ? conn.add( @dn, @attrs ) :
47: conn.add_ext( @dn, @attrs, @controls, [] )
48: when LDAP_MOD_DELETE
49: @controls == [] ? conn.delete( @dn ) :
50: conn.delete_ext( @dn, @controls, [] )
51: when LDAP_MOD_REPLACE
52: @controls == [] ? conn.modify( @dn, @mods ) :
53: conn.modify_ext( @dn, @mods, @controls, [] )
54: end
55:
56: self
57: end