Class ActiveLdap::DistinguishedName
In: lib/active_ldap/distinguished_name.rb
Parent: Object
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid DistinguishedNameNotSetError EntryNotFound LdapError SaveError StrongAuthenticationRequired NotImplemented AdapterNotFound TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError ConnectionNotSetup DistinguishedNameInvalid Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] Base DistinguishedName Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Normalizable Common Find LDIF Delete Update ActiveRecord::Callbacks GetText Parser Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/jndi.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Jndi Ldap NetLdap GetTextSupport ActiveRecord::Validations Xml JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/xml.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb Compatible ClassMethods Associations LdapBenchmarking ActionController Populate lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb lib/active_ldap/association/has_many.rb HasManyUtils Association ClassMethods Tree Acts Command ClassMethods Normalizable Attributes Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Configuration ClassMethods ObjectClass ClassMethods Callbacks lib/active_ldap/get_text/parser.rb GetText lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/base.rb lib/active_ldap/adapter/jndi.rb Adapter Validations GetTextFallback Helper ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_46_0.png

Methods

+   -   <<   <=>   ==   blank?   eql?   escape_value   hash   new   normalize   normalize_for_comparing   parent   parse   to_human_readable_format   to_s   to_str   unshift  

Included Modules

GetTextSupport

Classes and Modules

Class ActiveLdap::DistinguishedName::Parser

Attributes

rdns  [R] 

Public Class methods

[Source]

     # 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

[Source]

     # 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

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 157
157:       def parse(source)
158:         Parser.new(source).parse
159:       end

Public Instance methods

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 185
185:     def +(other)
186:       self.class.new(*(@rdns + other.rdns))
187:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 189
189:     def -(other)
190:       rdns = @rdns.dup
191:       normalized_rdns = normalize(@rdns)
192:       normalize(other.rdns).reverse_each do |rdn|
193:         if rdn == normalized_rdns.pop
194:           rdns.pop
195:         else
196:           raise ArgumentError, _("%s isn't sub DN of %s") % [other, self]
197:         end
198:       end
199:       self.class.new(*rdns)
200:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 202
202:     def <<(rdn)
203:       @rdns << rdn
204:       self
205:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 216
216:     def <=>(other)
217:       other = DN.parse(other) if other.is_a?(String)
218:       return nil unless other.is_a?(self.class)
219:       normalize_for_comparing(@rdns) <=>
220:         normalize_for_comparing(other.rdns)
221:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 223
223:     def ==(other)
224:       case other
225:       when self.class
226:         normalize(@rdns) == normalize(other.rdns)
227:       when String
228:         parsed_other = nil
229:         begin
230:           parsed_other = self.class.parse(other)
231:         rescue DistinguishedNameInvalid
232:           return false
233:         end
234:         self == parsed_other
235:       else
236:         false
237:       end
238:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 181
181:     def blank?
182:       @rdns.blank?
183:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 240
240:     def eql?(other)
241:       other.is_a?(self.class) and
242:         normalize(@rdns).to_s.eql?(normalize(other.rdns).to_s)
243:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 245
245:     def hash
246:       normalize(@rdns).to_s.hash
247:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 211
211:     def parent
212:       return nil if @rdns.size <= 1
213:       self.class.new(*@rdns[1..-1])
214:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 264
264:     def to_human_readable_format
265:       to_s.inspect
266:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 249
249:     def to_s
250:       klass = self.class
251:       @rdns.collect do |rdn|
252:         rdn.sort_by do |type, value|
253:           type.upcase
254:         end.collect do |type, value|
255:           "#{type}=#{klass.escape_value(value)}"
256:         end.join("+")
257:       end.join(",")
258:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 260
260:     def to_str # for backward compatibility
261:       to_s
262:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 207
207:     def unshift(rdn)
208:       @rdns.unshift(rdn)
209:     end

Private Instance methods

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 269
269:     def normalize(rdns)
270:       rdns.collect do |rdn|
271:         normalized_rdn = {}
272:         rdn.each do |key, value|
273:           normalized_rdn[key.upcase] = value.upcase
274:         end
275:         normalized_rdn
276:       end
277:     end

[Source]

     # File lib/active_ldap/distinguished_name.rb, line 279
279:     def normalize_for_comparing(rdns)
280:       normalize(rdns).collect do |rdn|
281:         rdn.sort_by do |key, value|
282:           key
283:         end
284:       end.collect do |key, value|
285:         [key, value]
286:       end
287:     end

[Validate]