Module ActiveLdap::Operations::Find
In: lib/active_ldap/operations.rb
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid LdapError DistinguishedNameNotSetError EntryNotFound SaveError StrongAuthenticationRequired 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 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/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 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 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 236
236:       def all(*args)
237:         find(:all, *args)
238:       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 201
201:       def find(*args)
202:         options = extract_options_from_args!(args)
203:         args = [:first] if args.empty? and !options.empty?
204:         case args.first
205:         when :first
206:           options[:value] ||= args[1]
207:           find_initial(options)
208:         when :last
209:           options[:value] ||= args[1]
210:           find_last(options)
211:         when :all
212:           options[:value] ||= args[1]
213:           find_every(options)
214:         else
215:           find_from_dns(args, options)
216:         end
217:       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 222
222:       def first(*args)
223:         find(:first, *args)
224:       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 229
229:       def last(*args)
230:         find(:last, *args)
231:       end

Private Instance methods

[Source]

     # File lib/active_ldap/operations.rb, line 355
355:       def ensure_dn(target)
356:         attr, value, prefix = split_search_value(target)
357:         "#{attr || dn_attribute}=#{value},#{prefix || base}"
358:       end

[Source]

     # File lib/active_ldap/operations.rb, line 262
262:       def find_every(options)
263:         options = options.dup
264:         sort_by = options.delete(:sort_by) || self.sort_by
265:         order = options.delete(:order) || self.order
266:         limit = options.delete(:limit) if sort_by or order
267:         options[:attributes] |= ["objectClass"] if options[:attributes]
268: 
269:         results = search(options).collect do |dn, attrs|
270:           instantiate([dn, attrs, {:connection => options[:connection]}])
271:         end
272:         return results if sort_by.nil? and order.nil?
273: 
274:         sort_by ||= "dn"
275:         if sort_by.downcase == "dn"
276:           results = results.sort_by {|result| DN.parse(result.dn)}
277:         else
278:           results = results.sort_by {|result| result.send(sort_by)}
279:         end
280: 
281:         results.reverse! if normalize_sort_order(order || "ascend") == :descend
282:         results = results[0, limit] if limit
283:         results
284:       end

[Source]

     # File lib/active_ldap/operations.rb, line 286
286:       def find_from_dns(dns, options)
287:         expects_array = dns.first.is_a?(Array)
288:         return [] if expects_array and dns.first.empty?
289: 
290:         dns = dns.flatten.compact.uniq
291: 
292:         case dns.size
293:         when 0
294:           raise EntryNotFound, _("Couldn't find %s without a DN") % name
295:         when 1
296:           result = find_one(dns.first, options)
297:           expects_array ? [result] : result
298:         else
299:           find_some(dns, options)
300:         end
301:       end

[Source]

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

[Source]

     # File lib/active_ldap/operations.rb, line 245
245:       def find_last(options)
246:         order = options[:order] || self.order || 'ascend'
247:         order = normalize_sort_order(order) == :ascend ? :descend : :ascend
248:         find_initial(options.merge(:order => order))
249:       end

[Source]

     # File lib/active_ldap/operations.rb, line 303
303:       def find_one(dn, options)
304:         attr, value, prefix = split_search_value(dn)
305:         filter = [attr || ensure_search_attribute,
306:                   Escape.ldap_filter_escape(value)]
307:         filter = [:and, filter, options[:filter]] if options[:filter]
308:         options = {:prefix => prefix}.merge(options.merge(:filter => filter))
309:         result = find_initial(options)
310:         if result
311:           result
312:         else
313:           args = [self.is_a?(Class) ? name : self.class.name,
314:                   dn]
315:           if options[:filter]
316:             format = _("Couldn't find %s: DN: %s: filter: %s")
317:             args << options[:filter].inspect
318:           else
319:             format = _("Couldn't find %s: DN: %s")
320:           end
321:           raise EntryNotFound, format % args
322:         end
323:       end

[Source]

     # File lib/active_ldap/operations.rb, line 325
325:       def find_some(dns, options)
326:         dn_filters = dns.collect do |dn|
327:           attr, value, prefix = split_search_value(dn)
328:           attr ||= ensure_search_attribute
329:           filter = [attr, value]
330:           if prefix
331:             filter = [:and,
332:                       filter,
333:                       [dn, "*,#{Escape.ldap_filter_escape(prefix)},#{base}"]]
334:           end
335:           filter
336:         end
337:         filter = [:or, *dn_filters]
338:         filter = [:and, filter, options[:filter]] if options[:filter]
339:         result = find_every(options.merge(:filter => filter))
340:         if result.size == dns.size
341:           result
342:         else
343:           args = [self.is_a?(Class) ? name : self.class.name,
344:                   dns.join(", ")]
345:           if options[:filter]
346:             format = _("Couldn't find all %s: DNs (%s): filter: %s")
347:             args << options[:filter].inspect
348:           else
349:             format = _("Couldn't find all %s: DNs (%s)")
350:           end
351:           raise EntryNotFound, format % args
352:         end
353:       end

[Source]

     # File lib/active_ldap/operations.rb, line 251
251:       def normalize_sort_order(value)
252:         case value.to_s
253:         when /\Aasc(?:end)?\z/i
254:           :ascend
255:         when /\Adesc(?:end)?\z/i
256:           :descend
257:         else
258:           raise ArgumentError, _("Invalid order: %s") % value.inspect
259:         end
260:       end

[Validate]