Module ActiveLdap::Operations::Find
In: lib/active_ldap/operations.rb
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

Public Instance methods

This is an alias for find(:all). You can pass in all the same arguments to this method as you can to find(:all)

[Source]

     # File lib/active_ldap/operations.rb, line 251
251:       def all(*args)
252:         find(:all, *args)
253:       end

find

Finds the first match for value where |value| is the value of some |field|, or the wildcard match. This is only useful for derived classes. usage: Subclass.find(:all, :attribute => "cn", :value => "some*val")

       Subclass.find(:all, 'some*val')

[Source]

     # File lib/active_ldap/operations.rb, line 216
216:       def find(*args)
217:         options = extract_options_from_args!(args)
218:         args = [:first] if args.empty? and !options.empty?
219:         case args.first
220:         when :first
221:           options[:value] ||= args[1]
222:           find_initial(options)
223:         when :last
224:           options[:value] ||= args[1]
225:           find_last(options)
226:         when :all
227:           options[:value] ||= args[1]
228:           find_every(options)
229:         else
230:           find_from_dns(args, options)
231:         end
232:       end

A convenience wrapper for find(:first, *args). You can pass in all the same arguments to this method as you can to find(:first).

[Source]

     # File lib/active_ldap/operations.rb, line 237
237:       def first(*args)
238:         find(:first, *args)
239:       end

A convenience wrapper for find(:last, *args). You can pass in all the same arguments to this method as you can to find(:last).

[Source]

     # File lib/active_ldap/operations.rb, line 244
244:       def last(*args)
245:         find(:last, *args)
246:       end

Private Instance methods

[Source]

     # File lib/active_ldap/operations.rb, line 370
370:       def ensure_dn(target)
371:         attr, value, prefix = split_search_value(target)
372:         "#{attr || dn_attribute}=#{value},#{prefix || base}"
373:       end

[Source]

     # File lib/active_ldap/operations.rb, line 277
277:       def find_every(options)
278:         options = options.dup
279:         sort_by = options.delete(:sort_by) || self.sort_by
280:         order = options.delete(:order) || self.order
281:         limit = options.delete(:limit) if sort_by or order
282:         options[:attributes] |= ["objectClass"] if options[:attributes]
283: 
284:         results = search(options).collect do |dn, attrs|
285:           instantiate([dn, attrs, {:connection => options[:connection]}])
286:         end
287:         return results if sort_by.nil? and order.nil?
288: 
289:         sort_by ||= "dn"
290:         if sort_by.downcase == "dn"
291:           results = results.sort_by {|result| DN.parse(result.dn)}
292:         else
293:           results = results.sort_by {|result| result.send(sort_by)}
294:         end
295: 
296:         results.reverse! if normalize_sort_order(order || "ascend") == :descend
297:         results = results[0, limit] if limit
298:         results
299:       end

[Source]

     # File lib/active_ldap/operations.rb, line 301
301:       def find_from_dns(dns, options)
302:         expects_array = dns.first.is_a?(Array)
303:         return [] if expects_array and dns.first.empty?
304: 
305:         dns = dns.flatten.compact.uniq
306: 
307:         case dns.size
308:         when 0
309:           raise EntryNotFound, _("Couldn't find %s without a DN") % name
310:         when 1
311:           result = find_one(dns.first, options)
312:           expects_array ? [result] : result
313:         else
314:           find_some(dns, options)
315:         end
316:       end

[Source]

     # File lib/active_ldap/operations.rb, line 256
256:       def find_initial(options)
257:         find_every(options.merge(:limit => 1)).first
258:       end

[Source]

     # File lib/active_ldap/operations.rb, line 260
260:       def find_last(options)
261:         order = options[:order] || self.order || 'ascend'
262:         order = normalize_sort_order(order) == :ascend ? :descend : :ascend
263:         find_initial(options.merge(:order => order))
264:       end

[Source]

     # File lib/active_ldap/operations.rb, line 318
318:       def find_one(dn, options)
319:         attr, value, prefix = split_search_value(dn)
320:         filter = [attr || ensure_search_attribute,
321:                   Escape.ldap_filter_escape(value)]
322:         filter = [:and, filter, options[:filter]] if options[:filter]
323:         options = {:prefix => prefix}.merge(options.merge(:filter => filter))
324:         result = find_initial(options)
325:         if result
326:           result
327:         else
328:           args = [self.is_a?(Class) ? name : self.class.name,
329:                   dn]
330:           if options[:filter]
331:             format = _("Couldn't find %s: DN: %s: filter: %s")
332:             args << options[:filter].inspect
333:           else
334:             format = _("Couldn't find %s: DN: %s")
335:           end
336:           raise EntryNotFound, format % args
337:         end
338:       end

[Source]

     # File lib/active_ldap/operations.rb, line 340
340:       def find_some(dns, options)
341:         dn_filters = dns.collect do |dn|
342:           attr, value, prefix = split_search_value(dn)
343:           attr ||= ensure_search_attribute
344:           filter = [attr, value]
345:           if prefix
346:             filter = [:and,
347:                       filter,
348:                       [dn, "*,#{Escape.ldap_filter_escape(prefix)},#{base}"]]
349:           end
350:           filter
351:         end
352:         filter = [:or, *dn_filters]
353:         filter = [:and, filter, options[:filter]] if options[:filter]
354:         result = find_every(options.merge(:filter => filter))
355:         if result.size == dns.size
356:           result
357:         else
358:           args = [self.is_a?(Class) ? name : self.class.name,
359:                   dns.join(", ")]
360:           if options[:filter]
361:             format = _("Couldn't find all %s: DNs (%s): filter: %s")
362:             args << options[:filter].inspect
363:           else
364:             format = _("Couldn't find all %s: DNs (%s)")
365:           end
366:           raise EntryNotFound, format % args
367:         end
368:       end

[Source]

     # File lib/active_ldap/operations.rb, line 266
266:       def normalize_sort_order(value)
267:         case value.to_s
268:         when /\Aasc(?:end)?\z/i
269:           :ascend
270:         when /\Adesc(?:end)?\z/i
271:           :descend
272:         else
273:           raise ArgumentError, _("Invalid order: %s") % value.inspect
274:         end
275:       end

[Validate]