Created
June 10, 2009 22:20
-
-
Save irjudson/127544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @return [Integer] | |
# The number of records that were actually saved into the | |
# data-store | |
# | |
# @api semipublic | |
def create(resources) | |
created = 0 | |
resources.each do |resource| | |
if resource.cn.nil? || resource.cn.empty? | |
resource.cn = "test_#{rand(9999)}" | |
end | |
id = "cn=#{resource.cn},#{@options[:base]}" | |
# Convert resources into a Hash for the ldap calls | |
ldap_obj = convert_resource_to_hash(resource) | |
# Call LDAP create | |
begin | |
@ldap.add(:dn => id, :attributes => ldap_obj) | |
rescue Net::LDAP::LdapError => e | |
return false | |
end | |
ldap_result = @ldap.get_operation_result | |
# Accumulate successful create calls to return | |
if ldap_result.code == 0 | |
initialize_identity_field(resource, id) | |
created = created + 1 | |
else | |
return false | |
end | |
end | |
# Return number created | |
return created | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment