Class: LDAP::Record
- Inherits:
-
Object
- Object
- LDAP::Record
- Defined in:
- lib/ldap/ldif.rb
Overview
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.
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#change_type ⇒ Object
readonly
Returns the value of attribute change_type.
-
#controls ⇒ Object
readonly
Returns the value of attribute controls.
-
#dn ⇒ Object
readonly
Returns the value of attribute dn.
-
#mods ⇒ Object
readonly
Returns the value of attribute mods.
Instance Method Summary collapse
-
#clean ⇒ Object
Remove common operational attributes from a Record object.
-
#initialize(dn, change_type, attrs, mods = nil, ctls = nil) ⇒ Record
constructor
A new instance of Record.
-
#send(conn) ⇒ Object
Send the operation embodied in the Record object to the LDAP::Conn object specified in
conn
.
Constructor Details
#initialize(dn, change_type, attrs, mods = nil, ctls = nil) ⇒ Record
Returns a new instance of Record.
27 28 29 30 31 32 33 |
# 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 |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
25 26 27 |
# File 'lib/ldap/ldif.rb', line 25 def attrs @attrs end |
#change_type ⇒ Object (readonly)
Returns the value of attribute change_type.
25 26 27 |
# File 'lib/ldap/ldif.rb', line 25 def change_type @change_type end |
#controls ⇒ Object (readonly)
Returns the value of attribute controls.
25 26 27 |
# File 'lib/ldap/ldif.rb', line 25 def controls @controls end |
#dn ⇒ Object (readonly)
Returns the value of attribute dn.
25 26 27 |
# File 'lib/ldap/ldif.rb', line 25 def dn @dn end |
#mods ⇒ Object (readonly)
Returns the value of attribute mods.
25 26 27 |
# File 'lib/ldap/ldif.rb', line 25 def mods @mods end |
Instance Method Details
#clean ⇒ Object
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.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# 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(conn) ⇒ Object
Send the operation embodied in the Record object to the LDAP::Conn object specified in conn
.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 |