### Home Classes Methods

### In Files

- lib/active_ldap/operations.rb

### Methods

- #all
- #ensure_dn
- #find
- #find_every
- #find_from_dns
- #find_initial
- #find_last
- #find_one
- #find_some
- #first
- #last
- #normalize_sort_order

### Files

- USAGE

### Class/Module Index

Quicksearch

- ActiveLdap
- ActiveLdap::ActionController
- ActiveLdap::ActionController::LdapBenchmarking
- ActiveLdap::Acts
- ActiveLdap::Acts::Tree
- ActiveLdap::Acts::Tree::ClassMethods
- ActiveLdap::Adapter
- ActiveLdap::Adapter::Base
- ActiveLdap::Adapter::Jndi
- ActiveLdap::Adapter::JndiConnection
- ActiveLdap::Adapter::JndiConnection::ModifyRecord
- ActiveLdap::Adapter::JndiConnection::Scope
- ActiveLdap::Adapter::Ldap
- ActiveLdap::Adapter::Ldap::Method
- ActiveLdap::Adapter::Ldap::Method::Base
- ActiveLdap::Adapter::Ldap::Method::Plain
- ActiveLdap::Adapter::Ldap::Method::SSL
- ActiveLdap::Adapter::Ldap::Method::TLS
- ActiveLdap::Adapter::NetLdap
- ActiveLdap::Association
- ActiveLdap::Association::BelongsTo
- ActiveLdap::Association::BelongsToMany
- ActiveLdap::Association::Children
- ActiveLdap::Association::Collection
- ActiveLdap::Association::HasMany
- ActiveLdap::Association::HasManyUtils
- ActiveLdap::Association::HasManyWrap
- ActiveLdap::Association::Proxy
- ActiveLdap::Associations
- ActiveLdap::Associations::ClassMethods
- ActiveLdap::AttributeMethods
- ActiveLdap::AttributeMethods::BeforeTypeCast
- ActiveLdap::AttributeMethods::Dirty
- ActiveLdap::AttributeMethods::Query
- ActiveLdap::AttributeMethods::Read
- ActiveLdap::AttributeMethods::Write
- ActiveLdap::Attributes
- ActiveLdap::Attributes::ClassMethods
- ActiveLdap::Attributes::Normalizable
- ActiveLdap::Callbacks
- ActiveLdap::Callbacks::ClassMethods
- ActiveLdap::Command
- ActiveLdap::Compatible
- ActiveLdap::Configuration
- ActiveLdap::Configuration::ClassMethods
- ActiveLdap::Connection
- ActiveLdap::Connection::ClassMethods
- ActiveLdap::DN
- ActiveLdap::DistinguishedName
- ActiveLdap::DistinguishedName::Parser
- ActiveLdap::Entry
- ActiveLdap::EntryAttribute
- ActiveLdap::Escape
- ActiveLdap::Generators
- ActiveLdap::Generators::ModelGenerator
- ActiveLdap::Generators::ScaffoldGenerator
- ActiveLdap::GetText
- ActiveLdap::GetText::Parser
- ActiveLdap::GetTextSupport
- ActiveLdap::Helper
- ActiveLdap::HumanReadable
- ActiveLdap::HumanReadable::ClassMethods
- ActiveLdap::LDIF
- ActiveLdap::LdapError
- ActiveLdap::Ldif
- ActiveLdap::Ldif::AddRecord
- ActiveLdap::Ldif::Attribute
- ActiveLdap::Ldif::Attributes
- ActiveLdap::Ldif::ChangeRecord
- ActiveLdap::Ldif::ChangeRecord::Control
- ActiveLdap::Ldif::ContentRecord
- ActiveLdap::Ldif::DeleteRecord
- ActiveLdap::Ldif::ModifyDNRecord
- ActiveLdap::Ldif::ModifyNameRecord
- ActiveLdap::Ldif::ModifyRDNRecord
- ActiveLdap::Ldif::ModifyRecord
- ActiveLdap::Ldif::ModifyRecord::AddOperation
- ActiveLdap::Ldif::ModifyRecord::DeleteOperation
- ActiveLdap::Ldif::ModifyRecord::Operation
- ActiveLdap::Ldif::ModifyRecord::ReplaceOperation
- ActiveLdap::Ldif::Parser
- ActiveLdap::Ldif::Record
- ActiveLdap::Ldif::Scanner
- ActiveLdap::LogSubscriber
- ActiveLdap::ObjectClass
- ActiveLdap::ObjectClass::ClassMethods
- ActiveLdap::Operations
- ActiveLdap::Operations::ClassOnlyDelete
- ActiveLdap::Operations::ClassOnlyUpdate
- ActiveLdap::Operations::Common
- ActiveLdap::Operations::Delete
- ActiveLdap::Operations::Find
- ActiveLdap::Operations::LDIF
- ActiveLdap::Operations::LDIF::AddRecordLoadable
- ActiveLdap::Operations::LDIF::ContentRecordLoadable
- ActiveLdap::Operations::LDIF::DeleteRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyNameRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::AddOperationModifiable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::DeleteOperationModifiable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::ReplaceOperationModifiable
- ActiveLdap::Operations::Update
- ActiveLdap::Persistence
- ActiveLdap::Populate
- ActiveLdap::Railtie
- ActiveLdap::Railties
- ActiveLdap::Railties::ControllerRuntime
- ActiveLdap::Railties::ControllerRuntime::ClassMethods
- ActiveLdap::Schema
- ActiveLdap::Schema::Attribute
- ActiveLdap::Schema::Entry
- ActiveLdap::Schema::ObjectClass
- ActiveLdap::Schema::Syntax
- ActiveLdap::Schema::Syntaxes
- ActiveLdap::Schema::Syntaxes::Base
- ActiveLdap::Schema::Syntaxes::BitString
- ActiveLdap::Schema::Syntaxes::Boolean
- ActiveLdap::Schema::Syntaxes::CountryString
- ActiveLdap::Schema::Syntaxes::DirectoryString
- ActiveLdap::Schema::Syntaxes::DistinguishedName
- ActiveLdap::Schema::Syntaxes::GeneralizedTime
- ActiveLdap::Schema::Syntaxes::Integer
- ActiveLdap::Schema::Syntaxes::JPEG
- ActiveLdap::Schema::Syntaxes::NameAndOptionalUID
- ActiveLdap::Schema::Syntaxes::NumericString
- ActiveLdap::Schema::Syntaxes::OID
- ActiveLdap::Schema::Syntaxes::ObjectSecurityDescriptor
- ActiveLdap::Schema::Syntaxes::OctetString
- ActiveLdap::Schema::Syntaxes::OtherMailbox
- ActiveLdap::Schema::Syntaxes::PostalAddress
- ActiveLdap::Schema::Syntaxes::PrintableString
- ActiveLdap::Schema::Syntaxes::TelephoneNumber
- ActiveLdap::UserPassword
- ActiveLdap::UserPassword::Salt
- ActiveLdap::Validations
- ActiveLdap::XML
- ActiveLdap::Xml
- ActiveLdap::Xml::Serializer
- LDAP
- LDAP::Conn
- LDAP::Mod
- Net
- Net::LDAP
- Net::LDAP::Entry
- ActionView
- ActionView::Base
- URI
- URI::LDAPS
- Object
- Timeout

No matching classes.

# 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 260
    def all(*args)
      find(:all, *args)
    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 225
    def find(*args)
      options = extract_options_from_args!(args)
      args = [:first] if args.empty? and !options.empty?
      case args.first
      when :first
        options[:value] ||= args[1]
        find_initial(options)
      when :last
        options[:value] ||= args[1]
        find_last(options)
      when :all
        options[:value] ||= args[1]
        find_every(options)
      else
        find_from_dns(args, options)
      end
    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 246
    def first(*args)
      find(:first, *args)
    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 253
    def last(*args)
      find(:last, *args)
    end

### Private Instance Methods

ensure_dn(target) click to toggle source

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

find_every(options) click to toggle source

    # File lib/active_ldap/operations.rb, line 286
    def find_every(options)
      options = options.dup
      sort_by = options.delete(:sort_by) || self.sort_by
      order = options.delete(:order) || self.order
      limit = options.delete(:limit) if sort_by or order
      offset = options.delete(:offset) || offset
      options[:attributes] = options.delete(:attributes) || ['*']
      options[:attributes] |= ['objectClass']
      results = search(options).collect do |dn, attrs|
        instantiate([dn, attrs, {:connection => options[:connection]}])
      end
      return results if sort_by.nil? and order.nil?

      sort_by ||= "dn"
      if sort_by.downcase == "dn"
        results = results.sort_by {|result| DN.parse(result.dn)}
      else
        results = results.sort_by {|result| result.send(sort_by)}
      end

      results.reverse! if normalize_sort_order(order || "ascend") == :descend
      results = results[offset, results.size] if offset
      results = results[0, limit] if limit
      results
    end

find_from_dns(dns, options) click to toggle source

    # File lib/active_ldap/operations.rb, line 312
    def find_from_dns(dns, options)
      expects_array = dns.first.is_a?(Array)
      return [] if expects_array and dns.first.empty?

      dns = dns.flatten.compact.uniq

      case dns.size
      when 0
        raise EntryNotFound, _("Couldn't find %s without a DN") % name
      when 1
        result = find_one(dns.first, options)
        expects_array ? [result] : result
      else
        find_some(dns, options)
      end
    end

find_initial(options) click to toggle source

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

find_last(options) click to toggle source

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

find_one(dn, options) click to toggle source

    # File lib/active_ldap/operations.rb, line 329
    def find_one(dn, options)
      attr, value, prefix = split_search_value(dn)
      filter = [attr || ensure_search_attribute,
                Escape.ldap_filter_escape(value)]
      filter = [:and, filter, options[:filter]] if options[:filter]
      options = {:prefix => prefix}.merge(options.merge(:filter => filter))
      result = find_initial(options)
      if result
        result
      else
        args = [self.is_a?(Class) ? name : self.class.name,
                dn]
        if options[:filter]
          format = _("Couldn't find %s: DN: %s: filter: %s")
          args << options[:filter].inspect
        else
          format = _("Couldn't find %s: DN: %s")
        end
        raise EntryNotFound, format % args
      end
    end

find_some(dns, options) click to toggle source

    # File lib/active_ldap/operations.rb, line 351
    def find_some(dns, options)
      dn_filters = dns.collect do |dn|
        attr, value, prefix = split_search_value(dn)
        attr ||= ensure_search_attribute
        filter = [attr, value]
        if prefix
          filter = [:and,
                    filter,
                    [dn, "*,#{Escape.ldap_filter_escape(prefix)},#{base}"]]
        end
        filter
      end
      filter = [:or, *dn_filters]
      filter = [:and, filter, options[:filter]] if options[:filter]
      result = find_every(options.merge(:filter => filter))
      if result.size == dns.size
        result
      else
        args = [self.is_a?(Class) ? name : self.class.name,
                dns.join(", ")]
        if options[:filter]
          format = _("Couldn't find all %s: DNs (%s): filter: %s")
          args << options[:filter].inspect
        else
          format = _("Couldn't find all %s: DNs (%s)")
        end
        raise EntryNotFound, format % args
      end
    end

normalize_sort_order(value) click to toggle source

    # File lib/active_ldap/operations.rb, line 275
    def normalize_sort_order(value)
      case value.to_s
      when /\Aasc(?:end)?\z/
        :ascend
      when /\Adesc(?:end)?\z/
        :descend
      else
        raise ArgumentError, _("Invalid order: %s") % value.inspect
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.