class LDAP::Record
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.
Attributes
Public Class Methods
# File lib/ldap/ldif.rb, line 27 def initialize(dn, change_type, attrs, mods=nil, ctls=nil) @dn = dn @change_type = change_type @attrs = attrs @mods = mods @controls = ctls 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.
# File lib/ldap/ldif.rb, line 72 def clean # TODO: These operational attributes are those commonly used by # OpenLDAP 2.2. Others should probably be supported. # %w[ creatorsname createtimestamp modifiersname modifytimestamp entrycsn entryuuid structuralobjectclass ].each do |attr| @attrs.delete( attr ) end # Clean out duplicate attribute values. @attrs.each_key { |k| @attrs[k].uniq! } self end
Send the operation embodied in the Record
object to the LDAP::Conn
object specified in conn
.
# File lib/ldap/ldif.rb, line 39 def send( conn ) if @change_type == :MODRDN # TODO: How do we deal with 'newsuperior'? # The LDAP API's ldap_modrdn2_s() function doesn't seem to use it. return conn.modrdn( @dn, @attrs['newrdn'], @attrs['deleteoldrdn'] ) end # Mask out the LDAP_MOD_BVALUES bit, as it's irrelevant here. case @change_type & ~LDAP_MOD_BVALUES when LDAP_MOD_ADD @controls == [] ? conn.add( @dn, @attrs ) : conn.add_ext( @dn, @attrs, @controls, [] ) when LDAP_MOD_DELETE @controls == [] ? conn.delete( @dn ) : conn.delete_ext( @dn, @controls, [] ) when LDAP_MOD_REPLACE @controls == [] ? conn.modify( @dn, @mods ) : conn.modify_ext( @dn, @mods, @controls, [] ) end self end