Skip to content

Commit d4c19ee

Browse files
author
blackhedd
committed
Reinterpreted search result sets as Arrays rather than Hashes.
WARNING WARNING WARNING: This change breaks existing code.
1 parent 6e5aba6 commit d4c19ee

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lib/net/ldap.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,22 @@ def searchx args
492492
# be called 1000 times. If the search returns no entries, the block will
493493
# not be called.
494494
#
495+
#--
496+
# ORIGINAL TEXT, replaced 04May06.
495497
# #search returns either a result-set or a boolean, depending on the
496498
# value of the <tt>:return_result</tt> argument. The default behavior is to return
497499
# a result set, which is a hash. Each key in the hash is a string specifying
498500
# the DN of an entry. The corresponding value for each key is a Net::LDAP::Entry object.
499501
# If you request a result set and #search fails with an error, it will return nil.
500502
# Call #get_operation_result to get the error information returned by
501503
# the LDAP server.
504+
#++
505+
# #search returns either a result-set or a boolean, depending on the
506+
# value of the <tt>:return_result</tt> argument. The default behavior is to return
507+
# a result set, which is an Array of objects of class Net::LDAP::Entry.
508+
# If you request a result set and #search fails with an error, it will return nil.
509+
# Call #get_operation_result to get the error information returned by
510+
# the LDAP server.
502511
#
503512
# When <tt>:return_result => false,</tt> #search will
504513
# return only a Boolean, to indicate whether the operation succeeded. This can improve performance
@@ -539,21 +548,29 @@ def searchx args
539548
# that the caller can set to suppress the return of a result set,
540549
# if he's planning to process every entry as it comes from the server.
541550
#
551+
# REINTERPRETED the result set, 04May06. Originally this was a hash
552+
# of entries keyed by DNs. But let's get away from making users
553+
# handle DNs. Change it to a plain array. Eventually we may
554+
# want to return a Dataset object that delegates to an internal
555+
# array, so we can provide sort methods and what-not.
556+
#
542557
def search args = {}
543558
args[:base] ||= @base
544-
result_set = (args and args[:return_result] == false) ? nil : {}
559+
result_set = (args and args[:return_result] == false) ? nil : []
545560

546561
if @open_connection
547562
@result = @open_connection.search( args ) {|entry|
548-
result_set[entry.dn] = entry if result_set
563+
#result_set[entry.dn] = entry if result_set
564+
result_set << entry if result_set
549565
yield( entry ) if block_given?
550566
}
551567
else
552568
@result = 0
553569
conn = Connection.new( :host => @host, :port => @port )
554570
if (@result = conn.bind( args[:auth] || @auth )) == 0
555571
@result = conn.search( args ) {|entry|
556-
(result_set[entry.dn] = entry) if result_set
572+
#(result_set[entry.dn] = entry) if result_set
573+
result_set << entry if result_set
557574
yield( entry ) if block_given?
558575
}
559576
end

0 commit comments

Comments
 (0)