Class: ESearchy::OtherEngines::Ldap

Inherits:
Object
  • Object
show all
Defined in:
lib/esearchy/OtherEngines/ldap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, port = nil, base = nil, scope = nil, filter = nil, attr = nil) ⇒ Ldap

Returns a new instance of Ldap.



5
6
7
8
9
10
11
12
13
# File 'lib/esearchy/OtherEngines/ldap.rb', line 5

def initialize(host = nil, port = nil, base = nil, 
               scope = nil, filter = nil, attr = nil)
  @HOST    = host
  @PORT    = port || LDAP::LDAP_PORT
  @base    = base || "dc=localhost,dc=#{host}"
  @scope   = scope || 2
  @filter  = filter || '(objectclass=person)'
  @attrs   = attr || ['sn', 'cn'] 
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



14
15
16
# File 'lib/esearchy/OtherEngines/ldap.rb', line 14

def attrs
  @attrs
end

#baseObject

Returns the value of attribute base.



14
15
16
# File 'lib/esearchy/OtherEngines/ldap.rb', line 14

def base
  @base
end

#filterObject

Returns the value of attribute filter.



14
15
16
# File 'lib/esearchy/OtherEngines/ldap.rb', line 14

def filter
  @filter
end

#HOSTObject

Returns the value of attribute HOST.



14
15
16
# File 'lib/esearchy/OtherEngines/ldap.rb', line 14

def HOST
  @HOST
end

#PORTObject

Returns the value of attribute PORT.



14
15
16
# File 'lib/esearchy/OtherEngines/ldap.rb', line 14

def PORT
  @PORT
end

#scopeObject

Returns the value of attribute scope.



14
15
16
# File 'lib/esearchy/OtherEngines/ldap.rb', line 14

def scope
  @scope
end

#SSLPORTObject

Returns the value of attribute SSLPORT.



14
15
16
# File 'lib/esearchy/OtherEngines/ldap.rb', line 14

def SSLPORT
  @SSLPORT
end

Instance Method Details

#search(bind, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/esearchy/OtherEngines/ldap.rb', line 16

def search(bind, &block)
  connect(bind)
  begin
    block.call(self) if block_given?
    @conn.search(base, scope, filter, attrs, block)
  rescue LDAP::ResultError
    @conn.perror("search")        
  end
  @conn.perror("search")
  close
end