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 do |key, vals|
      self[key] = vals
    end
  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
# File 'lib/ldap/schema.rb', line 34

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

  return nil
end

#may(oc) ⇒ Object

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



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

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

#must(oc) ⇒ Object

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



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

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.



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

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