@@ -181,6 +181,8 @@ module Net
181181 # the attribute values stored in the directory for a particular entity.
182182 # #modify may add or delete attributes (which are lists of values) or it change attributes by
183183 # adding to or deleting from their values.
184+ # There are three easier methods to modify an entry's attribute values:
185+ # #add_attribute, #replace_attribute, and #delete_attribute.
184186 #
185187 # ==== Delete
186188 # #delete operation specifies an entity DN. If it succeeds, the entity and all its attributes
@@ -600,7 +602,9 @@ def add args
600602 end
601603
602604
603- # Modify the attribute values of a particular entry on the LDAP directory.
605+ # _DEPRECATED_ - Please use #add_attribute, #replace_attribute, or #delete_attribute.
606+ #
607+ # Modifies the attribute values of a particular entry on the LDAP directory.
604608 # Takes a hash with arguments. Supported arguments are:
605609 # :dn :: (the full DN of the entry whose attributes are to be modified)
606610 # :operations :: (the modifications to be performed, detailed next)
@@ -681,6 +685,61 @@ def modify args
681685 @result == 0
682686 end
683687
688+
689+ # Add a value to an attribute.
690+ # Takes the full DN of the entry to modify,
691+ # the name (Symbol or String) of the attribute, and the value (String or
692+ # Array). If the attribute does not exist (and there are no schema violations),
693+ # #add_attribute will create it with the caller-specified values.
694+ # If the attribute already exists (and there are no schema violations), the
695+ # caller-specified values will be _added_ to the values already present.
696+ #
697+ # Returns True or False to indicate whether the operation
698+ # succeeded or failed, with extended information available by calling
699+ # #get_operation_result. See also #replace_attribute and #delete_attribute.
700+ #
701+ # dn = "cn=modifyme,dc=example,dc=com"
702+ # ldap.add_attribute dn, :mail, "newmailaddress@example.com"
703+ #
704+ def add_attribute dn , attribute , value
705+ modify :dn => dn , :operations => [ [ :add , attribute , value ] ]
706+ end
707+
708+ # Replace the value of an attribute.
709+ # #replace_attribute can be thought of as equivalent to calling #delete_attribute
710+ # followed by #add_attribute. It takes the full DN of the entry to modify,
711+ # the name (Symbol or String) of the attribute, and the value (String or
712+ # Array). If the attribute does not exist, it will be created with the
713+ # caller-specified value(s). If the attribute does exist, its values will be
714+ # _discarded_ and replaced with the caller-specified values.
715+ #
716+ # Returns True or False to indicate whether the operation
717+ # succeeded or failed, with extended information available by calling
718+ # #get_operation_result. See also #add_attribute and #delete_attribute.
719+ #
720+ # dn = "cn=modifyme,dc=example,dc=com"
721+ # ldap.replace_attribute dn, :mail, "newmailaddress@example.com"
722+ #
723+ def replace_attribute dn , attribute , value
724+ modify :dn => dn , :operations => [ [ :replace , attribute , value ] ]
725+ end
726+
727+ # Delete an attribute and all its values.
728+ # Takes the full DN of the entry to modify, and the
729+ # name (Symbol or String) of the attribute to delete.
730+ #
731+ # Returns True or False to indicate whether the operation
732+ # succeeded or failed, with extended information available by calling
733+ # #get_operation_result. See also #add_attribute and #replace_attribute.
734+ #
735+ # dn = "cn=modifyme,dc=example,dc=com"
736+ # ldap.delete_attribute dn, :mail
737+ #
738+ def delete_attribute dn , attribute
739+ modify :dn => dn , :operations => [ [ :delete , attribute , nil ] ]
740+ end
741+
742+
684743 # Rename an entry on the remote DIS by changing the last RDN of its DN.
685744 # _Documentation_ _stub_
686745 #
0 commit comments