Improved the search-result handling
This commit is contained in:
parent
7be5474f06
commit
28185fdf0f
|
@ -53,17 +53,15 @@ module Net
|
|||
# :password => "opensesame"
|
||||
# }
|
||||
#
|
||||
# filter = Net::LDAP::Filter.eq?( "cn", "George*" )
|
||||
# filter = Net::LDAP::Filter.eq( "cn", "George*" )
|
||||
# treebase = "dc=example,dc=com"
|
||||
#
|
||||
# ldap.search( :base => treebase, :filter => filter ) do |result|
|
||||
# result.each do |dn, attrs|
|
||||
# puts "DN: #{dn}"
|
||||
# attrs.each do |attr, values|
|
||||
# puts "***Attr: #{attr}"
|
||||
# values.each do |value|
|
||||
# puts " #{value}"
|
||||
# end
|
||||
# ldap.search( :base => treebase, :filter => filter ) do |entry|
|
||||
# puts "DN: #{entry.dn}"
|
||||
# entry.each do |attribute, values|
|
||||
# puts " #{attribute}:"
|
||||
# values.each do |value|
|
||||
# puts " --->#{value}"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
@ -425,7 +423,7 @@ module Net
|
|||
conn = Connection.new( :host => @host, :port => @port )
|
||||
if (@result = conn.bind( args[:auth] || @auth )) == 0
|
||||
@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?
|
||||
}
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ class LDAP
|
|||
|
||||
def initialize dn = nil
|
||||
@myhash = Hash.new {|k,v| k[v] = [] }
|
||||
self[:dn] = [dn]
|
||||
@myhash[:dn] = [dn]
|
||||
end
|
||||
|
||||
|
||||
|
@ -47,20 +47,27 @@ class LDAP
|
|||
end
|
||||
|
||||
def [] name
|
||||
unless name.is_a?(Symbol)
|
||||
name = name.to_s.downcase.intern
|
||||
end
|
||||
#unless name.is_a?(Symbol)
|
||||
# name = name.to_s.downcase.intern
|
||||
#end
|
||||
@myhash[name]
|
||||
end
|
||||
|
||||
def dn
|
||||
self[:dn].shift
|
||||
self[:dn][0]
|
||||
end
|
||||
|
||||
def attribute_names
|
||||
@myhash.keys
|
||||
end
|
||||
|
||||
def each
|
||||
if block_given?
|
||||
attribute_names.each {|a| yield a, self[a] }
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :each_attribute, :each
|
||||
|
||||
end # class Entry
|
||||
|
||||
|
|
Loading…
Reference in a new issue