Improved the search-result handling

This commit is contained in:
blackhedd 2006-04-25 20:15:46 +00:00
parent 7be5474f06
commit 28185fdf0f
2 changed files with 20 additions and 15 deletions

View file

@ -53,17 +53,15 @@ module Net
# :password => "opensesame" # :password => "opensesame"
# } # }
# #
# filter = Net::LDAP::Filter.eq?( "cn", "George*" ) # filter = Net::LDAP::Filter.eq( "cn", "George*" )
# treebase = "dc=example,dc=com" # treebase = "dc=example,dc=com"
# #
# ldap.search( :base => treebase, :filter => filter ) do |result| # ldap.search( :base => treebase, :filter => filter ) do |entry|
# result.each do |dn, attrs| # puts "DN: #{entry.dn}"
# puts "DN: #{dn}" # entry.each do |attribute, values|
# attrs.each do |attr, values| # puts " #{attribute}:"
# puts "***Attr: #{attr}" # values.each do |value|
# values.each do |value| # puts " --->#{value}"
# puts " #{value}"
# end
# end # end
# end # end
# end # end
@ -425,7 +423,7 @@ 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
yield( entry ) if block_given? yield( entry ) if block_given?
} }
end end

View file

@ -37,7 +37,7 @@ class LDAP
def initialize dn = nil def initialize dn = nil
@myhash = Hash.new {|k,v| k[v] = [] } @myhash = Hash.new {|k,v| k[v] = [] }
self[:dn] = [dn] @myhash[:dn] = [dn]
end end
@ -47,20 +47,27 @@ class LDAP
end end
def [] name def [] name
unless name.is_a?(Symbol) #unless name.is_a?(Symbol)
name = name.to_s.downcase.intern # name = name.to_s.downcase.intern
end #end
@myhash[name] @myhash[name]
end end
def dn def dn
self[:dn].shift self[:dn][0]
end end
def attribute_names def attribute_names
@myhash.keys @myhash.keys
end end
def each
if block_given?
attribute_names.each {|a| yield a, self[a] }
end
end
alias_method :each_attribute, :each
end # class Entry end # class Entry