lib/treequel/branch.rb in treequel-1.5.3 vs lib/treequel/branch.rb in treequel-1.6.0
- old
+ new
@@ -264,10 +264,37 @@
### Return the entry's DN as an RFC1781-style UFN (User-Friendly Name).
### @return [String]
def to_ufn
- return LDAP.dn2ufn( self.dn )
+ if LDAP.respond_to?( :dn2ufn )
+ return LDAP.dn2ufn( self.dn )
+
+ # An implementation for LDAP libraries with no
+ # dn2ufn
+ else
+ ufn = ''
+ tuples = self.split_dn
+
+ # Separate the trailing domainComponents
+ dcs = []
+ dcs << tuples.pop while tuples.last =~ /^dc\s*=/i
+
+ # Append the non-dc tuples with their attributes stripped first
+ ufn << tuples.collect do |rdn|
+ rdn.
+ gsub(/\b#{ATTRIBUTE_TYPE}\s*=/, '').
+ gsub(/\s*\+\s*/, ' + ')
+ end.join( ', ' )
+
+ # Now append the DCs joined with dots
+ unless dcs.empty?
+ ufn << ', '
+ ufn << dcs.reverse.map {|rdn| rdn.sub(/dc\s*=\s*/i, '') }.join( '.' )
+ end
+
+ return ufn
+ end
end
### Return the Branch as an LDAP::LDIF::Entry.
### @return [String]