Module ActiveLdap::Operations::Find
In: lib/active_ldap/operations.rb
Error DeleteError LdapError AdapterNotSpecified OperationNotPermitted RequiredAttributeMissed LdifInvalid AttributeAssignmentError RequiredObjectClassMissed DistinguishedNameNotSetError StrongAuthenticationRequired ConnectionError SaveError EntryNotFound AuthenticationError EntryNotSaved UnknownAttribute ConnectionNotEstablished TimeoutError ConfigurationError AdapterNotFound DistinguishedNameInvalid ObjectClassError EntryInvalid EntryAlreadyExist Base DistinguishedName Ldif Reloadable::Deprecated Reloadable::Subclasses Enumerable Collection StandardError Children HasMany HasManyWrap BelongsToMany Proxy BelongsTo Common Find LDIF Delete Update GetText Parser GetTextSupport Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Ldap NetLdap Normalize ActiveRecord::Callbacks ActiveRecord::Validations Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] lib/active_ldap/base.rb lib/active_ldap/schema.rb lib/active_ldap/ldif.rb lib/active_ldap/distinguished_name.rb lib/active_ldap/ldap_error.rb ClassMethods Associations ClassMethods HumanReadable lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/has_many.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb HasManyUtils Association ClassMethods Tree Acts Common LDIF Delete Find Update Operations lib/active_ldap/get_text/parser.rb GetText ClassMethods Configuration Command lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb Adapter GetTextSupport Normalize ClassMethods Attributes Escape Callbacks ClassMethods ObjectClass Helper Validations ClassMethods Connection GetTextFallback Populate Salt UserPassword ActiveLdap dot/m_40_0.png

Methods

Public Instance methods

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(:attribute => "cn", :value => "some*val")

       Subclass.find('some*val')

[Source]

     # File lib/active_ldap/operations.rb, line 175
175:       def find(*args)
176:         options = extract_options_from_args!(args)
177:         args = [:first] if args.empty? and !options.empty?
178:         case args.first
179:         when :first
180:           find_initial(options)
181:         when :all
182:           options[:value] ||= args[1]
183:           find_every(options)
184:         else
185:           find_from_dns(args, options)
186:         end
187:       end

Private Instance methods

[Source]

     # File lib/active_ldap/operations.rb, line 297
297:       def ensure_dn(target)
298:         attr, value, prefix = split_search_value(target)
299:         "#{attr || dn_attribute}=#{value},#{prefix || base}"
300:       end

[Source]

     # File lib/active_ldap/operations.rb, line 205
205:       def find_every(options)
206:         options = options.dup
207:         sort_by = options.delete(:sort_by) || sort_by
208:         order = options.delete(:order) || order
209:         limit = options.delete(:limit) if sort_by or order
210: 
211:         results = search(options).collect do |dn, attrs|
212:           instantiate([dn, attrs, {:connection => options[:connection]}])
213:         end
214:         return results if sort_by.nil? and order.nil?
215: 
216:         sort_by ||= "dn"
217:         if sort_by.downcase == "dn"
218:           results = results.sort_by {|result| DN.parse(result.dn)}
219:         else
220:           results = results.sort_by {|result| result.send(sort_by)}
221:         end
222: 
223:         results.reverse! if normalize_sort_order(order || "ascend") == :descend
224:         results = results[0, limit] if limit
225:         results
226:       end

[Source]

     # File lib/active_ldap/operations.rb, line 228
228:       def find_from_dns(dns, options)
229:         expects_array = dns.first.is_a?(Array)
230:         return [] if expects_array and dns.first.empty?
231: 
232:         dns = dns.flatten.compact.uniq
233: 
234:         case dns.size
235:         when 0
236:           raise EntryNotFound, _("Couldn't find %s without a DN") % name
237:         when 1
238:           result = find_one(dns.first, options)
239:           expects_array ? [result] : result
240:         else
241:           find_some(dns, options)
242:         end
243:       end

[Source]

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

[Source]

     # File lib/active_ldap/operations.rb, line 245
245:       def find_one(dn, options)
246:         attr, value, prefix = split_search_value(dn)
247:         filter = [attr || ensure_search_attribute,
248:                   Escape.ldap_filter_escape(value)]
249:         filter = [:and, filter, options[:filter]] if options[:filter]
250:         options = {:prefix => prefix}.merge(options.merge(:filter => filter))
251:         result = find_initial(options)
252:         if result
253:           result
254:         else
255:           args = [self.is_a?(Class) ? name : self.class.name,
256:                   dn]
257:           if options[:filter]
258:             format = _("Couldn't find %s: DN: %s: filter: %s")
259:             args << options[:filter].inspect
260:           else
261:             format = _("Couldn't find %s: DN: %s")
262:           end
263:           raise EntryNotFound, format % args
264:         end
265:       end

[Source]

     # File lib/active_ldap/operations.rb, line 267
267:       def find_some(dns, options)
268:         dn_filters = dns.collect do |dn|
269:           attr, value, prefix = split_search_value(dn)
270:           attr ||= ensure_search_attribute
271:           filter = [attr, value]
272:           if prefix
273:             filter = [:and,
274:                       filter,
275:                       [dn, "*,#{Escape.ldap_filter_escape(prefix)},#{base}"]]
276:           end
277:           filter
278:         end
279:         filter = [:or, *dn_filters]
280:         filter = [:and, filter, options[:filter]] if options[:filter]
281:         result = find_every(options.merge(:filter => filter))
282:         if result.size == dns.size
283:           result
284:         else
285:           args = [self.is_a?(Class) ? name : self.class.name,
286:                   dns.join(", ")]
287:           if options[:filter]
288:             format = _("Couldn't find all %s: DNs (%s): filter: %s")
289:             args << options[:filter].inspect
290:           else
291:             format = _("Couldn't find all %s: DNs (%s)")
292:           end
293:           raise EntryNotFound, format % args
294:         end
295:       end

[Source]

     # File lib/active_ldap/operations.rb, line 194
194:       def normalize_sort_order(value)
195:         case value.to_s
196:         when /\Aasc(?:end)?\z/i
197:           :ascend
198:         when /\Adesc(?:end)?\z/i
199:           :descend
200:         else
201:           raise ArgumentError, _("Invalid order: %s") % value.inspect
202:         end
203:       end

[Validate]