Class | ActiveLdap::DistinguishedName |
In: |
lib/active_ldap/distinguished_name.rb
|
Parent: | Object |
rdns | [R] |
# File lib/active_ldap/distinguished_name.rb, line 161 161: def escape_value(value) 162: if /(\A | \z)/.match(value) 163: '"' + value.gsub(/([\\\"])/, '\\\\\1') + '"' 164: else 165: value.gsub(/([,=\+<>#;\\\"])/, '\\\\\1') 166: end 167: end
# File lib/active_ldap/distinguished_name.rb, line 171 171: def initialize(*rdns) 172: @rdns = rdns.collect do |rdn| 173: if rdn.is_a?(Array) and rdn.size == 2 174: {rdn[0] => rdn[1]} 175: else 176: rdn 177: end 178: end 179: end
# File lib/active_ldap/distinguished_name.rb, line 157 157: def parse(source) 158: Parser.new(source).parse 159: end
# File lib/active_ldap/distinguished_name.rb, line 181 181: def -(other) 182: rdns = @rdns.dup 183: normalized_rdns = normalize(@rdns) 184: normalize(other.rdns).reverse_each do |rdn| 185: if rdn == normalized_rdns.pop 186: rdns.pop 187: else 188: raise ArgumentError, _("%s isn't sub DN of %s") % [other, self] 189: end 190: end 191: self.class.new(*rdns) 192: end
# File lib/active_ldap/distinguished_name.rb, line 202 202: def <=>(other) 203: normalize_for_comparing(@rdns) <=> 204: normalize_for_comparing(other.rdns) 205: end
# File lib/active_ldap/distinguished_name.rb, line 207 207: def ==(other) 208: other.is_a?(self.class) and 209: normalize(@rdns) == normalize(other.rdns) 210: end
# File lib/active_ldap/distinguished_name.rb, line 212 212: def eql?(other) 213: other.is_a?(self.class) and 214: normalize(@rdns).to_s.eql?(normalize(other.rdns).to_s) 215: end
# File lib/active_ldap/distinguished_name.rb, line 217 217: def hash 218: normalize(@rdns).to_s.hash 219: end
# File lib/active_ldap/distinguished_name.rb, line 235 235: def to_human_readable_format 236: to_s.inspect 237: end
# File lib/active_ldap/distinguished_name.rb, line 225 225: def to_s 226: @rdns.collect do |rdn| 227: rdn.sort_by do |type, value| 228: type.upcase 229: end.collect do |type, value| 230: "#{type}=#{self.class.escape_value(value)}" 231: end.join("+") 232: end.join(",") 233: end
# File lib/active_ldap/distinguished_name.rb, line 198 198: def unshift(rdn) 199: @rdns.unshift(rdn) 200: end
# File lib/active_ldap/distinguished_name.rb, line 240 240: def normalize(rdns) 241: rdns.collect do |rdn| 242: normalized_rdn = {} 243: rdn.each do |key, value| 244: normalized_rdn[key.upcase] = value.upcase 245: end 246: normalized_rdn 247: end 248: end