Object
Objects of this class represent individual entries in an LDAP directory. User code generally does not instantiate this class. Net::LDAP#search provides objects of this class to user code, either as block parameters or as return values.
In LDAP-land, an “entry” is a collection of attributes that are uniquely and globally identified by a DN (“Distinguished Name”). Attributes are identified by short, descriptive words or phrases. Although a directory is free to implement any attribute name, most of them follow rigorous standards so that the range of commonly-encountered attribute names is not large.
An attribute name is case-insensitive. Most directories also restrict the range of characters allowed in attribute names. To simplify handling attribute names, Net::LDAP::Entry internally converts them to a standard format. Therefore, the methods which take attribute names can take Strings or Symbols, and work correctly regardless of case or capitalization.
An attribute consists of zero or more data items called values. An entry is the combination of a unique DN, a set of attribute names, and a (possibly-empty) array of values for each attribute.
Class Net::LDAP::Entry provides convenience methods for dealing with LDAP entries. In addition to the methods documented below, you may access individual attributes of an entry simply by giving the attribute name as the name of a method call. For example:
ldap.search( ... ) do |entry| puts "Common name: #{entry.cn}" puts "Email addresses:" entry.mail.each {|ma| puts ma} end
If you use this technique to access an attribute that is not present in a particular Entry object, a NoMethodError exception will be raised.
# File lib/net/ldap/entry.rb, line 85 85: def _load entry 86: from_single_ldif_string entry 87: end
# File lib/net/ldap/entry.rb, line 171 171: def from_single_ldif_string ldif 172: entry = Entry.new 173: entry[:dn] = [] 174: ldif.split(/\r?\n/).each {|line| 175: break if line.length == 0 176: if line =~ /\A([\w]+):(:?)[\s]*/ 177: entry[$1] <<= if $2 == ':' 178: Base64.decode64($') 179: else 180: $' 181: end 182: end 183: } 184: entry.dn ? entry : nil 185: end
# File lib/net/ldap/entry.rb, line 80 80: def _dump depth 81: to_ldif 82: end
Returns an array of the attribute names present in the Entry.
# File lib/net/ldap/entry.rb, line 114 114: def attribute_names 115: @myhash.keys 116: end
Accesses each of the attributes present in the Entry. Calls a user-supplied block with each attribute in turn, passing two arguments to the block: a Symbol giving the name of the attribute, and a (possibly empty) Array of data values.
# File lib/net/ldap/entry.rb, line 124 124: def each 125: if block_given? 126: attribute_names.each {|a| 127: attr_name,values = a,self[a] 128: yield attr_name, values 129: } 130: end 131: end
# File lib/net/ldap/entry.rb, line 191 191: def respond_to?(sym) 192: name = attribute_name(sym) 193: return true if valid_attribute?(name) 194: return super 195: end
Converts the Entry to a String, representing the Entry’s attributes in LDIF format.
# File lib/net/ldap/entry.rb, line 138 138: def to_ldif 139: ary = [] 140: ary << "dn: #{dn}\n" 141: v2 = "" # temp value, save on GC 142: each_attribute do |k,v| 143: unless k == :dn 144: v.each {|v1| 145: v2 = if (k == :userpassword) || is_attribute_value_binary?(v1) 146: ": #{Base64.encode64(v1).chomp.gsub(/\n/m,"\n ")}" 147: else 148: " #{v1}" 149: end 150: ary << "#{k}:#{v2}\n" 151: } 152: end 153: end 154: ary << "\n" 155: ary.join 156: end
Returns the symbol that can be used to access the attribute that sym_or_str designates.
# File lib/net/ldap/entry.rb, line 245 245: def attribute_name(sym_or_str) 246: str = sym_or_str.to_s.downcase 247: 248: # Does str match 'something='? Still only returns :something 249: return str[0...1].to_sym if str.size>1 && str[1] == == 250: return str.to_sym 251: end
# File lib/net/ldap/entry.rb, line 231 231: def is_attribute_value_binary? value 232: v = value.to_s 233: v.each_byte {|byt| 234: return true if (byt < 32) || (byt > 126) 235: } 236: if v[0..0] == ':' or v[0..0] == '<' 237: return true 238: end 239: false 240: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.