# Extensions to Rubu/LDAP to make ActiveLDAP behave better # module LDAP # Creates useful exceptions from err2string output # Returns [exception, message] based on err2string def LDAP.err2exception(errno=0) err = LDAP::err2string(errno) err = err.split(' ').collect {|w| w.capitalize }.join('') err.gsub!(/[^A-Za-z]/, '') # If the exception exists - raise it! begin exc = LDAP.const_get(err) rescue NameError # Doesn't exist :-) LDAP.module_eval(<<-end_module_eval) class #{err} < LDAP::ResultError end end_module_eval exc = LDAP.const_get(err) end return [exc, err2string(errno)] end end