Class: LDAP::Schema

Inherits:
Hash
  • Object
show all
Defined in:
lib/ldap/schema.rb

Overview

Retrieve and process information pertaining to LDAP schemas.

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ Schema

Returns a new instance of Schema.



16
17
18
19
20
21
22
# File 'lib/ldap/schema.rb', line 16

def initialize(entry)
  if( entry )
	entry.each{|key,vals|
	  self[key] = vals
	}
  end
end

Instance Method Details

#attr(oc, at) ⇒ Object

Return the list of attributes in object class oc that are of category at. at may be the string MUST, MAY or SUP.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ldap/schema.rb', line 34

def attr(oc,at)
  self['objectClasses'].each{|s|
	if( s =~ /NAME\s+'#{oc}'/ )
	  case s
	  when /#{at}\s+\(([\w\d_-\s\$]+)\)/i
 return $1.split("$").collect{|attr| attr.strip}
	  when /#{at}\s+([\w\d_-]+)/i
 return $1.split("$").collect{|attr| attr.strip}
	  end
	end
  }
  return nil
end

#may(oc) ⇒ Object

Return the list of attributes that an entry with object class oc may possess.



58
59
60
# File 'lib/ldap/schema.rb', line 58

def may(oc)
  attr(oc, "MAY")
end

#must(oc) ⇒ Object

Return the list of attributes that an entry with object class oc must possess.



51
52
53
# File 'lib/ldap/schema.rb', line 51

def must(oc)
  attr(oc, "MUST")
end

#names(key) ⇒ Object

Return the list of values related to the schema component given in key. See LDAP::Conn#schema for common values of key.



27
28
29
# File 'lib/ldap/schema.rb', line 27

def names(key)
  self[key].collect{|val| val =~ /NAME\s+'([\w\d_-]+)'/; $1}
end

#sup(oc) ⇒ Object

Return the superior object class of object class oc.



64
65
66
# File 'lib/ldap/schema.rb', line 64

def sup(oc)
  attr(oc, "SUP")
end