| Class | ActiveLdap::DistinguishedName |
| In: |
lib/active_ldap/distinguished_name.rb
|
| Parent: | Object |
| rdns | [R] |
# File lib/active_ldap/distinguished_name.rb, line 159
159: def initialize(*rdns)
160: @rdns = rdns.collect do |rdn|
161: rdn = {rdn[0] => rdn[1]} if rdn.is_a?(Array) and rdn.size == 2
162: rdn
163: end
164: end
# File lib/active_ldap/distinguished_name.rb, line 153
153: def parse(source)
154: Parser.new(source).parse
155: end
# File lib/active_ldap/distinguished_name.rb, line 166
166: def -(other)
167: rdns = @rdns.dup
168: normalized_rdns = normalize(@rdns)
169: normalize(other.rdns).reverse_each do |rdn|
170: if rdn == normalized_rdns.pop
171: rdns.pop
172: else
173: raise ArgumentError, _("%s isn't sub DN of %s") % [other, self]
174: end
175: end
176: self.class.new(*rdns)
177: end
# File lib/active_ldap/distinguished_name.rb, line 187
187: def <=>(other)
188: normalize_for_comparing(@rdns) <=>
189: normalize_for_comparing(other.rdns)
190: end
# File lib/active_ldap/distinguished_name.rb, line 192
192: def ==(other)
193: other.is_a?(self.class) and
194: normalize(@rdns) == normalize(other.rdns)
195: end
# File lib/active_ldap/distinguished_name.rb, line 197
197: def eql?(other)
198: other.is_a?(self.class) and
199: normalize(@rdns).to_s.eql?(normalize(other.rdns).to_s)
200: end
# File lib/active_ldap/distinguished_name.rb, line 202
202: def hash
203: normalize(@rdns).to_s.hash
204: end
# File lib/active_ldap/distinguished_name.rb, line 210
210: def to_s
211: @rdns.collect do |rdn|
212: rdn.sort_by do |type, value|
213: type.upcase
214: end.collect do |type, value|
215: "#{type}=#{escape(value)}"
216: end.join("+")
217: end.join(",")
218: end
# File lib/active_ldap/distinguished_name.rb, line 183
183: def unshift(rdn)
184: @rdns.unshift(rdn)
185: end
# File lib/active_ldap/distinguished_name.rb, line 241
241: def escape(value)
242: if /(\A | \z)/.match(value)
243: '"' + value.gsub(/([\\\"])/, '\\\\\1') + '"'
244: else
245: value.gsub(/([,=\+<>#;\\\"])/, '\\\\\1')
246: end
247: end
# File lib/active_ldap/distinguished_name.rb, line 221
221: def normalize(rdns)
222: rdns.collect do |rdn|
223: normalized_rdn = {}
224: rdn.each do |key, value|
225: normalized_rdn[key.upcase] = value.upcase
226: end
227: normalized_rdn
228: end
229: end