ruby-ldap / ruby-net-ldap

Pure Ruby LDAP library
https://rubygems.org/gems/net-ldap
Other
399 stars 253 forks source link

Add explicit close method #374

Closed HynekPetrak closed 4 years ago

HynekPetrak commented 4 years ago

Hi,

I assume in the below example (taken from the documentation) the TCP connection is not closed at the end and there is no method for that. Can you please add explicit close method to the LDAP class? It's seems it's only assumed to go via #open method, which closes the connection in the ensure block.

require 'rubygems'
require 'net/ldap'

ldap = Net::LDAP.new :host => server_ip_address,
     :port => 389,
     :auth => {
           :method => :simple,
           :username => "cn=manager, dc=example, dc=com",
           :password => "opensesame"
     }

filter = Net::LDAP::Filter.eq("cn", "George*")
treebase = "dc=example, dc=com"

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

p ldap.get_operation_result