Reinterpreted search result sets as Arrays rather than Hashes.

WARNING WARNING WARNING: This change breaks existing code.
This commit is contained in:
blackhedd 2006-05-04 13:08:36 +00:00
parent 6e5aba6530
commit d4c19eea44

View file

@ -492,6 +492,8 @@ module Net
# be called 1000 times. If the search returns no entries, the block will # be called 1000 times. If the search returns no entries, the block will
# not be called. # not be called.
# #
#--
# ORIGINAL TEXT, replaced 04May06.
# #search returns either a result-set or a boolean, depending on the # #search returns either a result-set or a boolean, depending on the
# value of the <tt>:return_result</tt> argument. The default behavior is to return # value of the <tt>:return_result</tt> argument. The default behavior is to return
# a result set, which is a hash. Each key in the hash is a string specifying # a result set, which is a hash. Each key in the hash is a string specifying
@ -499,6 +501,13 @@ module Net
# If you request a result set and #search fails with an error, it will return nil. # If you request a result set and #search fails with an error, it will return nil.
# Call #get_operation_result to get the error information returned by # Call #get_operation_result to get the error information returned by
# the LDAP server. # the LDAP server.
#++
# #search returns either a result-set or a boolean, depending on the
# value of the <tt>:return_result</tt> argument. The default behavior is to return
# a result set, which is an Array of objects of class Net::LDAP::Entry.
# If you request a result set and #search fails with an error, it will return nil.
# Call #get_operation_result to get the error information returned by
# the LDAP server.
# #
# When <tt>:return_result => false,</tt> #search will # When <tt>:return_result => false,</tt> #search will
# return only a Boolean, to indicate whether the operation succeeded. This can improve performance # return only a Boolean, to indicate whether the operation succeeded. This can improve performance
@ -539,13 +548,20 @@ module Net
# that the caller can set to suppress the return of a result set, # that the caller can set to suppress the return of a result set,
# if he's planning to process every entry as it comes from the server. # if he's planning to process every entry as it comes from the server.
# #
# REINTERPRETED the result set, 04May06. Originally this was a hash
# of entries keyed by DNs. But let's get away from making users
# handle DNs. Change it to a plain array. Eventually we may
# want to return a Dataset object that delegates to an internal
# array, so we can provide sort methods and what-not.
#
def search args = {} def search args = {}
args[:base] ||= @base args[:base] ||= @base
result_set = (args and args[:return_result] == false) ? nil : {} result_set = (args and args[:return_result] == false) ? nil : []
if @open_connection if @open_connection
@result = @open_connection.search( args ) {|entry| @result = @open_connection.search( args ) {|entry|
result_set[entry.dn] = entry if result_set #result_set[entry.dn] = entry if result_set
result_set << entry if result_set
yield( entry ) if block_given? yield( entry ) if block_given?
} }
else else
@ -553,7 +569,8 @@ module Net
conn = Connection.new( :host => @host, :port => @port ) conn = Connection.new( :host => @host, :port => @port )
if (@result = conn.bind( args[:auth] || @auth )) == 0 if (@result = conn.bind( args[:auth] || @auth )) == 0
@result = conn.search( args ) {|entry| @result = conn.search( args ) {|entry|
(result_set[entry.dn] = entry) if result_set #(result_set[entry.dn] = entry) if result_set
result_set << entry if result_set
yield( entry ) if block_given? yield( entry ) if block_given?
} }
end end