Class: ActiveLdap::EntryAttribute

Inherits:
Object
  • Object
show all
Includes:
Attributes::Normalizable
Defined in:
lib/active_ldap/entry_attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attributes::Normalizable

#normalize_attribute, #normalize_attribute_name, #normalize_attribute_options, #unnormalize_attribute, #unnormalize_attribute_options, #unnormalize_attributes

Constructor Details

#initialize(schema, object_classes) ⇒ EntryAttribute

Returns a new instance of EntryAttribute.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_ldap/entry_attribute.rb', line 8

def initialize(schema, object_classes)
  @schemata = {}
  @names = {}
  @normalized_names = {}
  @aliases = {}
  @must = []
  @may = []
  @object_classes = []
  register(schema.attribute('objectClass')) if schema
  object_classes.each do |objc|
    # get all attributes for the class
    object_class = schema.object_class(objc)
    @object_classes << object_class
    @must.concat(object_class.must)
    @may.concat(object_class.may)
  end
  @must.uniq!
  @may.uniq!
  (@must + @may).each do |attr|
    # Update attr_method with appropriate
    register(attr)
  end
end

Instance Attribute Details

#mayObject (readonly)

Returns the value of attribute may.



7
8
9
# File 'lib/active_ldap/entry_attribute.rb', line 7

def may
  @may
end

#mustObject (readonly)

Returns the value of attribute must.



7
8
9
# File 'lib/active_ldap/entry_attribute.rb', line 7

def must
  @must
end

#object_classesObject (readonly)

Returns the value of attribute object_classes.



7
8
9
# File 'lib/active_ldap/entry_attribute.rb', line 7

def object_classes
  @object_classes
end

#schemataObject (readonly)

Returns the value of attribute schemata.



7
8
9
# File 'lib/active_ldap/entry_attribute.rb', line 7

def schemata
  @schemata
end

Instance Method Details

#all_namesObject



63
64
65
# File 'lib/active_ldap/entry_attribute.rb', line 63

def all_names
  @names.keys + @aliases.keys
end

#exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/active_ldap/entry_attribute.rb', line 59

def exist?(name)
  not normalize(name).nil?
end

#names(normalize = false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/active_ldap/entry_attribute.rb', line 32

def names(normalize=false)
  names = @names.keys
  if normalize
    names.collect do |name|
      normalize(name)
    end.uniq
  else
    names
  end
end

#normalize(name, allow_normalized_name = false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_ldap/entry_attribute.rb', line 43

def normalize(name, allow_normalized_name=false)
  return name if name.nil?
  return nil if @names.empty? and @aliases.empty?
  name = name.to_s
  real_name = @names[name]
  real_name ||= @aliases[name.underscore]
  if real_name
    real_name
  elsif allow_normalized_name
    return nil if @normalized_names.empty?
    @normalized_names[normalize_attribute_name(name)]
  else
    nil
  end
end

#register(attribute) ⇒ Object

register

Make a method entry for every alias of a valid attribute and map it onto the first attribute passed in.



71
72
73
74
75
76
77
78
79
80
# File 'lib/active_ldap/entry_attribute.rb', line 71

def register(attribute)
  real_name = attribute.name
  return if @schemata.has_key?(real_name)
  @schemata[real_name] = attribute
  ([real_name] + attribute.aliases).each do |name|
    @names[name] = real_name
    @aliases[name.underscore] = real_name
    @normalized_names[normalize_attribute_name(name)] = real_name
  end
end