Class Index [+]

Quicksearch

ActiveLdap::Operations::Find

Public Instance Methods

all(*args) click to toggle source

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

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

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')
     # 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
first(*args) click to toggle source

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

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

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

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

Private Instance Methods

ensure_dn(target) click to toggle 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
find_every(options) click to toggle 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
find_from_dns(dns, options) click to toggle 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
find_initial(options) click to toggle source
     # File lib/active_ldap/operations.rb, line 256
256:       def find_initial(options)
257:         find_every(options.merge(:limit => 1)).first
258:       end
find_last(options) click to toggle 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
find_one(dn, options) click to toggle 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
find_some(dns, options) click to toggle 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
normalize_sort_order(value) click to toggle 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/
269:           :ascend
270:         when /\Adesc(?:end)?\z/
271:           :descend
272:         else
273:           raise ArgumentError, _("Invalid order: %s") % value.inspect
274:         end
275:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.