| Class | ActiveLdap::DistinguishedName |
| In: |
lib/active_ldap/distinguished_name.rb
|
| Parent: | Object |
| rdns | [R] |
# File lib/active_ldap/distinguished_name.rb, line 154
154: def initialize(*rdns)
155: @rdns = rdns.collect do |rdn|
156: rdn = {rdn[0] => rdn[1]} if rdn.is_a?(Array) and rdn.size == 2
157: rdn
158: end
159: end
# File lib/active_ldap/distinguished_name.rb, line 148
148: def parse(source)
149: Parser.new(source).parse
150: end
# File lib/active_ldap/distinguished_name.rb, line 161
161: def -(other)
162: rdns = @rdns.dup
163: normalized_rdns = normalize(@rdns)
164: normalize(other.rdns).reverse_each do |rdn|
165: if rdn == normalized_rdns.pop
166: rdns.pop
167: else
168: raise ArgumentError, "#{other} isn't sub DN of #{self}"
169: end
170: end
171: self.class.new(*rdns)
172: end
# File lib/active_ldap/distinguished_name.rb, line 182
182: def <=>(other)
183: normalize_for_comparing(@rdns) <=>
184: normalize_for_comparing(other.rdns)
185: end
# File lib/active_ldap/distinguished_name.rb, line 187
187: def ==(other)
188: other.is_a?(self.class) and
189: normalize(@rdns) == normalize(other.rdns)
190: end
# File lib/active_ldap/distinguished_name.rb, line 192
192: def eql?(other)
193: other.is_a?(self.class) and
194: normalize(@rdns).to_s.eql?(normalize(other.rdns).to_s)
195: end
# File lib/active_ldap/distinguished_name.rb, line 197
197: def hash
198: normalize(@rdns).to_s.hash
199: end
# File lib/active_ldap/distinguished_name.rb, line 205
205: def to_s
206: @rdns.collect do |rdn|
207: rdn.sort_by do |type, value|
208: type.upcase
209: end.collect do |type, value|
210: "#{type}=#{escape(value)}"
211: end.join("+")
212: end.join(",")
213: end
# File lib/active_ldap/distinguished_name.rb, line 178
178: def unshift(rdn)
179: @rdns.unshift(rdn)
180: end
# File lib/active_ldap/distinguished_name.rb, line 236
236: def escape(value)
237: if /(\A | \z)/.match(value)
238: '"' + value.gsub(/([\\\"])/, '\\\\\1') + '"'
239: else
240: value.gsub(/([,=\+<>#;\\\"])/, '\\\\\1')
241: end
242: end
# File lib/active_ldap/distinguished_name.rb, line 216
216: def normalize(rdns)
217: rdns.collect do |rdn|
218: normalized_rdn = {}
219: rdn.each do |key, value|
220: normalized_rdn[key.upcase] = value.upcase
221: end
222: normalized_rdn
223: end
224: end