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