Module: LDAP

Defined in:
lib/activeldap/ldap.rb,
lib/activeldap/schema2.rb

Defined Under Namespace

Classes: Conn, Schema2

Class Method Summary collapse

Class Method Details

.err2exception(errno = 0) ⇒ Object

Creates useful exceptions from err2string output Returns [exception, message] based on err2string



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/activeldap/ldap.rb', line 9

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