Class: ActiveLdap::Schema
- Inherits:
-
Object
- Object
- ActiveLdap::Schema
show all
- Includes:
- GetTextSupport
- Defined in:
- lib/active_ldap/schema.rb,
lib/active_ldap/schema/syntaxes.rb
Defined Under Namespace
Modules: Syntaxes
Classes: Attribute, Entry, ObjectClass, Syntax
Constant Summary
collapse
- NUMERIC_OID_RE =
"\\d[\\d\\.]+"
- DESCRIPTION_RE =
"[a-zA-Z][a-zA-Z\\d\\-]*"
- OID_RE =
"(?:#{NUMERIC_OID_RE}|#{DESCRIPTION_RE}-oid)"
Instance Method Summary
collapse
included
Constructor Details
#initialize(entries) ⇒ Schema
Returns a new instance of Schema.
5
6
7
8
9
10
|
# File 'lib/active_ldap/schema.rb', line 5
def initialize(entries)
@entries = normalize_entries(entries || {})
@schema_info = {}
@class_attributes_info = {}
@cache = {}
end
|
Instance Method Details
#attribute(name) ⇒ Object
88
89
90
91
92
|
# File 'lib/active_ldap/schema.rb', line 88
def attribute(name)
cache([:attribute, name]) do
Attribute.new(name, self)
end
end
|
#attribute_type(name, attribute_name) ⇒ Object
102
103
104
105
106
|
# File 'lib/active_ldap/schema.rb', line 102
def attribute_type(name, attribute_name)
cache([:attribute_type, name, attribute_name]) do
fetch("attributeTypes", name, attribute_name)
end
end
|
#attributes ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/active_ldap/schema.rb', line 94
def attributes
cache([:attributes]) do
names("attributeTypes").collect do |name|
attribute(name)
end
end
end
|
#dit_content_rule_attribute(name, attribute_name) ⇒ Object
128
129
130
131
132
|
# File 'lib/active_ldap/schema.rb', line 128
def dit_content_rule_attribute(name, attribute_name)
cache([:dit_content_rule_attribute, name, attribute_name]) do
fetch("dITContentRules", name, attribute_name)
end
end
|
#dump(output = nil) ⇒ Object
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/active_ldap/schema.rb', line 154
def dump(output=nil)
require 'pp'
output ||= STDOUT
if output.respond_to?(:write)
PP.pp(@entries, output)
else
open(output, "w") {|out| PP.pp(@entries, out)}
end
nil
end
|
#entry(group, id_or_name) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/active_ldap/schema.rb', line 48
def entry(group, id_or_name)
return {} if group.empty? or id_or_name.empty?
unless @entries.has_key?(group)
raise ArgumentError, _("Unknown schema group: %s") % group
end
info, ids, aliases = ensure_schema_info(group)
id, name = determine_id_or_name(id_or_name, aliases)
return ids[id] if ids.has_key?(id)
schemata = @entries[group] || []
while schema = schemata.shift
next unless /\A\s*\(\s*(#{OID_RE})\s*(.*)\s*\)\s*\z/ =~ schema
schema_id = $1
rest = $2
if ids.has_key?(schema_id)
attributes = ids[schema_id]
else
attributes = {}
ids[schema_id] = attributes
end
parse_attributes(rest, attributes)
(attributes["NAME"] || []).each do |v|
normalized_name = normalize_schema_name(v)
aliases[normalized_name] = schema_id
id = schema_id if id.nil? and name == normalized_name
end
break if id == schema_id
end
ids[id || aliases[name]] || {}
end
|
#exist_name?(group, name) ⇒ Boolean
22
23
24
|
# File 'lib/active_ldap/schema.rb', line 22
def exist_name?(group, name)
alias_map(group).has_key?(normalize_schema_name(name))
end
|
#fetch(group, id_or_name, attribute_name) ⇒ Object
Also known as:
[]
fetch
This is just like LDAP::Schema#attribute except that it allows look up in any of the given keys. e.g.
fetch('attributeTypes', 'cn', 'DESC')
fetch('ldapSyntaxes', '1.3.6.1.4.1.1466.115.121.1.5', 'DESC')
37
38
39
40
41
42
|
# File 'lib/active_ldap/schema.rb', line 37
def fetch(group, id_or_name, attribute_name)
return [] if attribute_name.empty?
attribute_name = normalize_attribute_name(attribute_name)
value = entry(group, id_or_name)[attribute_name]
value ? value.dup : []
end
|
#ids(group) ⇒ Object
12
13
14
15
16
|
# File 'lib/active_ldap/schema.rb', line 12
def ids(group)
ensure_parse(group)
info, ids, aliases = ensure_schema_info(group)
ids.keys
end
|
#ldap_syntax(name) ⇒ Object
134
135
136
137
138
|
# File 'lib/active_ldap/schema.rb', line 134
def ldap_syntax(name)
cache([:ldap_syntax, name]) do
Syntax.new(name, self)
end
end
|
#ldap_syntax_attribute(name, attribute_name) ⇒ Object
148
149
150
151
152
|
# File 'lib/active_ldap/schema.rb', line 148
def ldap_syntax_attribute(name, attribute_name)
cache([:ldap_syntax_attribute, name, attribute_name]) do
fetch("ldapSyntaxes", name, attribute_name)
end
end
|
#ldap_syntaxes ⇒ Object
140
141
142
143
144
145
146
|
# File 'lib/active_ldap/schema.rb', line 140
def ldap_syntaxes
cache([:ldap_syntaxes]) do
ids("ldapSyntaxes").collect do |id|
ldap_syntax(id)
end
end
end
|
#names(group) ⇒ Object
18
19
20
|
# File 'lib/active_ldap/schema.rb', line 18
def names(group)
alias_map(group).keys
end
|
#object_class(name) ⇒ Object
108
109
110
111
112
|
# File 'lib/active_ldap/schema.rb', line 108
def object_class(name)
cache([:object_class, name]) do
ObjectClass.new(name, self)
end
end
|
#object_class_attribute(name, attribute_name) ⇒ Object
122
123
124
125
126
|
# File 'lib/active_ldap/schema.rb', line 122
def object_class_attribute(name, attribute_name)
cache([:object_class_attribute, name, attribute_name]) do
fetch("objectClasses", name, attribute_name)
end
end
|
#object_classes ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/active_ldap/schema.rb', line 114
def object_classes
cache([:object_classes]) do
names("objectClasses").collect do |name|
object_class(name)
end
end
end
|
#resolve_name(group, name) ⇒ Object
26
27
28
|
# File 'lib/active_ldap/schema.rb', line 26
def resolve_name(group, name)
alias_map(group)[normalize_schema_name(name)]
end
|