Project

General

Profile

« Previous | Next » 

Revision 718238ae

Added by Marc Dequènes over 15 years ago

  • ID 718238ae84d617813d97b6b44f3a12207c4273d6

[fix] LdapObject: correct human_name() and description() to not fail when no :name_attribute and :desc_attribute is defined

View differences:

lib/ldap_shadows/object.rb
end
def human_name
[self.class.presentation[:name_attribute], 'displayName', 'cn'].each do |attr|
if attr == 'dn' or (self.has_attribute?(attr) and self.attribute_present?(attr))
val = self.send(attr)
name = val.is_a?(Array) ? val[0] : val
return name.strip
attr_list = ['displayName', 'cn']
attr_list.unshift(self.class.presentation[:name_attribute]) if self.class.presentation.has_key?(:name_attribute)
attr_list.each do |attr|
if attr == 'dn'
return self.dn
elsif self.attribute_present?(attr)
val = self.send(attr, true)
return val[0].strip
end
end
return ""
end
def description
[self.class.presentation[:desc_attribute], 'description'].each do |attr|
if self.has_attribute?(attr) and self.attribute_present?(attr)
attr_list = ['description']
attr_list.unshift(self.class.presentation[:desc_attribute]) if self.class.presentation.has_key?(:desc_attribute)
attr_list.each do |attr|
if self.attribute_present?(attr)
return self[attr].is_a?(Array) ? self[attr][0] : self[attr]
end
end

Also available in: Unified diff