Module ActiveLdap::Operations::Find
In: lib/active_ldap/operations.rb
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid LdapError DistinguishedNameNotSetError EntryNotFound 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] DistinguishedName Base Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Common Find LDIF Delete Update GetText::Translation Normalizable GetText Parser ActiveRecord::Callbacks ActiveRecord::Validations 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 Xml JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/schema/syntaxes.rb lib/active_ldap/xml.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 Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Normalizable Attributes ClassMethods Configuration ClassMethods ObjectClass lib/active_ldap/get_text/parser.rb GetText ClassMethods Callbacks Validations lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/jndi.rb Adapter Helper Translation GetTextFallback 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 252
252:       def all(*args)
253:         find(:all, *args)
254:       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 217
217:       def find(*args)
218:         options = extract_options_from_args!(args)
219:         args = [:first] if args.empty? and !options.empty?
220:         case args.first
221:         when :first
222:           options[:value] ||= args[1]
223:           find_initial(options)
224:         when :last
225:           options[:value] ||= args[1]
226:           find_last(options)
227:         when :all
228:           options[:value] ||= args[1]
229:           find_every(options)
230:         else
231:           find_from_dns(args, options)
232:         end
233:       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 238
238:       def first(*args)
239:         find(:first, *args)
240:       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 245
245:       def last(*args)
246:         find(:last, *args)
247:       end

Private Instance methods

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Validate]