### Home Classes Methods

### In Files

- lib/active_ldap/associations.rb

### Methods

- #associated_class
- #association_accessor
- #association_reader
- #association_writer
- #belongs_to
- #has_many
- #set_associated_class
- #validate_belongs_to_options
- #validate_has_many_options

### 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::Associations::ClassMethods

### Constants

VALID_BELONGS_TO_OPTIONS
VALID_HAS_MANY_OPTIONS

### Public Instance Methods

associated_class(name) click to toggle source

    # File lib/active_ldap/associations.rb, line 26
    def associated_class(name)
      @associated_classes[name.to_s]
    end

belongs_to(association_id, options={}) click to toggle source

belongs_to

This defines a method for an extension class map its DN key attribute value on to multiple items which reference it by |:foreign_key| in the other LDAP entry covered by class |:class_name|.

Example:

    belongs_to :groups, :class_name => "Group",
               :many => "memberUid" # Group#memberUid
               # :primary_key => "uid" # User#uid
               ## deprecated since 1.1.0. Use :primary_key instead.
               ## :foreign_key => "uid" # User#uid
               # dn attribute value is used by default
    belongs_to :primary_group, :class_name => "Group",
               :foreign_key => "gidNumber", # User#gidNumber
               :primary_key => "gidNumber"  # Group#gidNumber

    # File lib/active_ldap/associations.rb, line 48
    def belongs_to(association_id, options={})
      validate_belongs_to_options(options)
      klass = options[:class]
      klass ||= (options[:class_name] || association_id.to_s).classify
      foreign_key = options[:foreign_key]
      primary_key = options[:primary_key]
      many = options[:many]
      set_associated_class(association_id, klass)

      opts = {
        :association_id => association_id,
        :foreign_key_name => foreign_key,
        :primary_key_name => primary_key,
        :many => many,
        :extend => options[:extend],
      }
      if opts[:many]
        association_class = Association::BelongsToMany
        foreign_key_name = opts[:foreign_key_name]
        if foreign_key_name
          message = _(":foreign_key belongs_to(:many) option is "                          "deprecated since 1.1.0. Use :primary_key instead.")
          ActiveSupport::Deprecation.warn(message)
          opts[:primary_key_name] ||= foreign_key_name
        end
        opts[:primary_key_name] ||= dn_attribute
      else
        association_class = Association::BelongsTo
        opts[:foreign_key_name] ||= "#{association_id}_id"

        before_save(            if defined?(@#{association_id})              association = @#{association_id}              if association and association.updated?                self[association.__send__(:primary_key)] =                  association[#{opts[:foreign_key_name].dump}]              end            end)
      end

      association_accessor(association_id) do |target|
        association_class.new(target, opts)
      end
    end

has_many(association_id, options = {}) click to toggle source

has_many

This defines a method for an extension class expand an existing multi-element attribute into ActiveLdap objects. This discards any calls which result in entries that don't exist in LDAP!

Example:

    has_many :primary_members, :class_name => "User",
             :primary_key => "gidNumber", # Group#gidNumber
             :foreign_key => "gidNumber"  # User#gidNumber
             ## deprecated since 1.1.0. Those options
             ## are inverted.
             # :primary_key => "gidNumber", # User#gidNumber
             # :foreign_key => "gidNumber"  # Group#gidNumber
    has_many :members, :class_name => "User",
             :wrap => "memberUid" # Group#memberUid

    # File lib/active_ldap/associations.rb, line 112
    def has_many(association_id, options = {})
      validate_has_many_options(options)
      klass = options[:class]
      klass ||= (options[:class_name] || association_id.to_s).classify
      foreign_key = options[:foreign_key]
      primary_key = options[:primary_key]
      set_associated_class(association_id, klass)

      opts = {
        :association_id => association_id,
        :foreign_key_name => foreign_key,
        :primary_key_name => primary_key,
        :wrap => options[:wrap],
        :extend => options[:extend],
      }
      if opts[:wrap]
        association_class = Association::HasManyWrap
      else
        association_class = Association::HasMany
        primary_key_name = opts[:primary_key_name]
        foreign_key_name = opts[:foreign_key_name]
        if primary_key_name != foreign_key_name and
            primary_key_name != "dn" and
            !new.have_attribute?(primary_key_name)
          message = _(":primary_key and :foreign_key has_many options are "                          "inverted their mean since 1.1.0. Please invert them.")
          ActiveSupport::Deprecation.warn(message)
          opts[:foreign_key_name] = primary_key_name
          opts[:primary_key_name] = foreign_key_name
        end
      end

      association_accessor(association_id) do |target|
        association_class.new(target, opts)
      end
    end

set_associated_class(name, klass) click to toggle source

    # File lib/active_ldap/associations.rb, line 21
    def set_associated_class(name, klass)
      @associated_classes ||= {}
      @associated_classes[name.to_s] = klass
    end

### Private Instance Methods

association_accessor(name, &make_association) click to toggle source

    # File lib/active_ldap/associations.rb, line 150
    def association_accessor(name, &make_association)
      define_method("__make_#{name}") do
        make_association.call(self)
      end
      associations << name
      association_reader(name, &make_association)
      association_writer(name, &make_association)
    end

association_reader(name, &make_association) click to toggle source

    # File lib/active_ldap/associations.rb, line 159
    def association_reader(name, &make_association)
      class_eval(          def #{name}            @#{name} ||= __make_#{name}          end, __FILE__, __LINE__ + 1)
    end

association_writer(name, &make_association) click to toggle source

    # File lib/active_ldap/associations.rb, line 167
    def association_writer(name, &make_association)
      class_eval(          def #{name}=(new_value)            association = defined?(@#{name}) ? @#{name} : nil            association ||= __make_#{name}            association.replace(new_value)            @#{name} = new_value.nil? ? nil : association            @#{name}          end, __FILE__, __LINE__ + 1)
    end

validate_belongs_to_options(options) click to toggle source

    # File lib/active_ldap/associations.rb, line 182
    def validate_belongs_to_options(options)
      options.assert_valid_keys(VALID_BELONGS_TO_OPTIONS)
    end

validate_has_many_options(options) click to toggle source

    # File lib/active_ldap/associations.rb, line 189
    def validate_has_many_options(options)
      options.assert_valid_keys(VALID_HAS_MANY_OPTIONS)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.