Skip to content

Commit 28185fd

Browse files
author
blackhedd
committed
Improved the search-result handling
1 parent 7be5474 commit 28185fd

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

lib/net/ldap.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,15 @@ module Net
5353
# :password => "opensesame"
5454
# }
5555
#
56-
# filter = Net::LDAP::Filter.eq?( "cn", "George*" )
56+
# filter = Net::LDAP::Filter.eq( "cn", "George*" )
5757
# treebase = "dc=example,dc=com"
5858
#
59-
# ldap.search( :base => treebase, :filter => filter ) do |result|
60-
# result.each do |dn, attrs|
61-
# puts "DN: #{dn}"
62-
# attrs.each do |attr, values|
63-
# puts "***Attr: #{attr}"
64-
# values.each do |value|
65-
# puts " #{value}"
66-
# end
59+
# ldap.search( :base => treebase, :filter => filter ) do |entry|
60+
# puts "DN: #{entry.dn}"
61+
# entry.each do |attribute, values|
62+
# puts " #{attribute}:"
63+
# values.each do |value|
64+
# puts " --->#{value}"
6765
# end
6866
# end
6967
# end
@@ -425,7 +423,7 @@ def search args
425423
conn = Connection.new( :host => @host, :port => @port )
426424
if (@result = conn.bind( args[:auth] || @auth )) == 0
427425
@result = conn.search( args ) {|entry|
428-
result_set[entry.dn] = entry if result_set
426+
(result_set[entry.dn] = entry) if result_set
429427
yield( entry ) if block_given?
430428
}
431429
end

lib/net/ldap/entry.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Entry
3737

3838
def initialize dn = nil
3939
@myhash = Hash.new {|k,v| k[v] = [] }
40-
self[:dn] = [dn]
40+
@myhash[:dn] = [dn]
4141
end
4242

4343

@@ -47,20 +47,27 @@ def []= name, value
4747
end
4848

4949
def [] name
50-
unless name.is_a?(Symbol)
51-
name = name.to_s.downcase.intern
52-
end
50+
#unless name.is_a?(Symbol)
51+
# name = name.to_s.downcase.intern
52+
#end
5353
@myhash[name]
5454
end
5555

5656
def dn
57-
self[:dn].shift
57+
self[:dn][0]
5858
end
5959

6060
def attribute_names
6161
@myhash.keys
6262
end
6363

64+
def each
65+
if block_given?
66+
attribute_names.each {|a| yield a, self[a] }
67+
end
68+
end
69+
70+
alias_method :each_attribute, :each
6471

6572
end # class Entry
6673

0 commit comments

Comments
 (0)