lib/activeldap/base.rb in ruby-activeldap-debug-0.5.6 vs lib/activeldap/base.rb in ruby-activeldap-debug-0.5.7
- old
+ new
@@ -495,13 +495,11 @@
if val.class != String
raise TypeError, "Object key must be a String"
end
@data = {} # where the r/w entry data is stored
- @data.default = []
@ldap_data = {} # original ldap entry data
- @ldap_data.default = []
@attr_methods = {} # list of valid method calls for attributes used for dereferencing
# Break val apart if it is a dn
if val.match(/^#{dnattr()}=([^,=]+),#{base()}$/i)
val = $1
@@ -622,11 +620,14 @@
# Make sure all MUST attributes have a value
@data['objectClass'].each do |objc|
@must.each do |req_attr|
deref = @attr_methods[req_attr]
- if @data[deref] == []
+ # Set default if it wasn't yet set.
+ @data[deref] = [] if @data[deref].nil?
+ # Check for missing requirements.
+ if @data[deref].empty?
raise AttributeEmpty,
"objectClass '#{objc}' requires attribute '#{Base.schema.attribute_aliases(req_attr).join(', ')}'"
end
end
end
@@ -865,13 +866,11 @@
if entry.class != LDAP::Entry
raise TypeError, "argument must be a LDAP::Entry"
end
@data = {} # where the r/w entry data is stored
- @data.default = []
@ldap_data = {} # original ldap entry data
- @ldap_data.default = []
@attr_methods = {} # list of valid method calls for attributes used for dereferencing
# Get some attributes
@dn = entry.dn
entry.attrs.each do |attr|
@@ -1162,9 +1161,12 @@
#
# Return the value of the attribute called by method_missing?
def attribute_method(method, not_array = false)
@@logger.debug("stub: called attribute_method(#{method.inspect}, #{not_array.inspect}")
attr = @attr_methods[method]
+
+ # Set the default value to empty if attr is not set.
+ @data[attr] = [] if @data[attr].nil?
# Return a copy of the stored data
return array_of(@data[attr].dup, false) if not_array
return @data[attr]
end