### Home Classes Methods

### In Files

- lib/active_ldap/schema/syntaxes.rb
- lib/active_ldap/schema.rb

### Parent

Object

### Namespace

- MODULE ActiveLdap::Schema::Syntaxes
- CLASS ActiveLdap::Schema::Attribute
- CLASS ActiveLdap::Schema::Entry
- CLASS ActiveLdap::Schema::ObjectClass
- CLASS ActiveLdap::Schema::Syntax

### Methods

- ::new
- #[]
- #alias_map
- #attribute
- #attribute_type
- #attributes
- #cache
- #default_entries
- #determine_id_or_name
- #dit_content_rule_attribute
- #dump
- #ensure_parse
- #ensure_schema_info
- #entry
- #exist_name?
- #fetch
- #ids
- #ldap_syntax
- #ldap_syntax_attribute
- #ldap_syntaxes
- #names
- #normalize_attribute_name
- #normalize_entries
- #normalize_schema_name
- #object_class
- #object_class_attribute
- #object_classes
- #parse_attributes
- #resolve_name

### Included Modules

- ActiveLdap::GetTextSupport

### 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::Schema

### Constants

DESCRIPTION_RE
NUMERIC_OID_RE
OID_RE
RESERVED_NAMES_RE

### Public Class Methods

new(entries) click to toggle source

    # File lib/active_ldap/schema.rb, line 5
    def initialize(entries)
      @entries = normalize_entries(entries || {})
      @schema_info = {}
      @class_attributes_info = {}
      @cache = {}
    end

### Public Instance Methods

[](group, id_or_name, attribute_name) click to toggle source
Alias for: fetch
attribute(name) click to toggle source

    # File lib/active_ldap/schema.rb, line 90
    def attribute(name)
      name = name.to_s if name.is_a?(Symbol)
      cache([:attribute, name]) do
        Attribute.new(name, self)
      end
    end

attribute_type(name, attribute_name) click to toggle source

    # File lib/active_ldap/schema.rb, line 105
    def attribute_type(name, attribute_name)
      cache([:attribute_type, name, attribute_name]) do
        fetch("attributeTypes", name, attribute_name)
      end
    end

attributes() click to toggle source

    # File lib/active_ldap/schema.rb, line 97
    def attributes
      cache([:attributes]) do
        names("attributeTypes").collect do |name|
          attribute(name)
        end
      end
    end

dit_content_rule_attribute(name, attribute_name) click to toggle source

    # File lib/active_ldap/schema.rb, line 131
    def dit_content_rule_attribute(name, attribute_name)
      cache([:dit_content_rule_attribute, name, attribute_name]) do
        fetch("dITContentRules", name, attribute_name)
      end
    end

dump(output=nil) click to toggle source

    # File lib/active_ldap/schema.rb, line 157
    def dump(output=nil)
      require 'pp'
      output ||= STDOUT
      if output.respond_to?(:write)
        PP.pp(@entries, output)
      else
        open(output, "w") {|out| PP.pp(@entries, out)}
      end
      nil
    end

entry(group, id_or_name) click to toggle source

    # File lib/active_ldap/schema.rb, line 49
    def entry(group, id_or_name)
      return {} if group.empty? or id_or_name.empty?

      unless @entries.has_key?(group)
        raise ArgumentError, _("Unknown schema group: %s") % group
      end

      # Initialize anything that is required
      info, ids, aliases = ensure_schema_info(group)
      _ = info # for suppress a warning on Ruby 1.9.3
      id, name = determine_id_or_name(id_or_name, aliases)

      # Check already parsed options first
      return ids[id] if ids.has_key?(id)

      schemata = @entries[group] || []
      while schema = schemata.shift
        next unless /\A\s*\(\s*(#{OID_RE})\s*(.*)\s*\)\s*\z/ =~ schema
        schema_id = $1
        rest = $2

        if ids.has_key?(schema_id)
          attributes = ids[schema_id]
        else
          attributes = {}
          ids[schema_id] = attributes
        end

        parse_attributes(rest, attributes)
        (attributes["NAME"] || []).each do |v|
          normalized_name = normalize_schema_name(v)
          aliases[normalized_name] = schema_id
          id = schema_id if id.nil? and name == normalized_name
        end

        break if id == schema_id
      end

      ids[id || aliases[name]] || {}
    end

exist_name?(group, name) click to toggle source

    # File lib/active_ldap/schema.rb, line 23
    def exist_name?(group, name)
      alias_map(group).has_key?(normalize_schema_name(name))
    end

fetch(group, id_or_name, attribute_name) click to toggle source

fetch

This is just like LDAP::Schema#attribute except that it allows look up in any of the given keys. e.g.

    fetch('attributeTypes', 'cn', 'DESC')
    fetch('ldapSyntaxes', '1.3.6.1.4.1.1466.115.121.1.5', 'DESC')

    # File lib/active_ldap/schema.rb, line 38
    def fetch(group, id_or_name, attribute_name)
      return [] if attribute_name.empty?
      attribute_name = normalize_attribute_name(attribute_name)
      value = entry(group, id_or_name)[attribute_name]
      value ? value.dup : []
    end

Also aliased as: []
ids(group) click to toggle source

    # File lib/active_ldap/schema.rb, line 12
    def ids(group)
      ensure_parse(group)
      info, ids, aliases = ensure_schema_info(group)
      _ = info = aliases # for suppress a warning on Ruby 1.9.3
      ids.keys
    end

ldap_syntax(name) click to toggle source

    # File lib/active_ldap/schema.rb, line 137
    def ldap_syntax(name)
      cache([:ldap_syntax, name]) do
        Syntax.new(name, self)
      end
    end

ldap_syntax_attribute(name, attribute_name) click to toggle source

    # File lib/active_ldap/schema.rb, line 151
    def ldap_syntax_attribute(name, attribute_name)
      cache([:ldap_syntax_attribute, name, attribute_name]) do
        fetch("ldapSyntaxes", name, attribute_name)
      end
    end

ldap_syntaxes() click to toggle source

    # File lib/active_ldap/schema.rb, line 143
    def ldap_syntaxes
      cache([:ldap_syntaxes]) do
        ids("ldapSyntaxes").collect do |id|
          ldap_syntax(id)
        end
      end
    end

names(group) click to toggle source

    # File lib/active_ldap/schema.rb, line 19
    def names(group)
      alias_map(group).keys
    end

object_class(name) click to toggle source

    # File lib/active_ldap/schema.rb, line 111
    def object_class(name)
      cache([:object_class, name]) do
        ObjectClass.new(name, self)
      end
    end

object_class_attribute(name, attribute_name) click to toggle source

    # File lib/active_ldap/schema.rb, line 125
    def object_class_attribute(name, attribute_name)
      cache([:object_class_attribute, name, attribute_name]) do
        fetch("objectClasses", name, attribute_name)
      end
    end

object_classes() click to toggle source

    # File lib/active_ldap/schema.rb, line 117
    def object_classes
      cache([:object_classes]) do
        names("objectClasses").collect do |name|
          object_class(name)
        end
      end
    end

resolve_name(group, name) click to toggle source

    # File lib/active_ldap/schema.rb, line 27
    def resolve_name(group, name)
      alias_map(group)[normalize_schema_name(name)]
    end

### Private Instance Methods

alias_map(group) click to toggle source

    # File lib/active_ldap/schema.rb, line 241
    def alias_map(group)
      ensure_parse(group)
      return {} if @schema_info[group].nil?
      @schema_info[group][:aliases] || {}
    end

cache(key) click to toggle source

    # File lib/active_ldap/schema.rb, line 169
    def cache(key)
      (@cache[key] ||= [yield])[0]
    end

default_entries() click to toggle source

    # File lib/active_ldap/schema.rb, line 262
    def default_entries
      {
        "objectClasses" => [],
        "attributeTypes" => [],
        "ldapSyntaxes" => [],
        "dITContentRules" => [],
        "matchingRules" => [],
      }
    end

determine_id_or_name(id_or_name, aliases) click to toggle source

    # File lib/active_ldap/schema.rb, line 179
    def determine_id_or_name(id_or_name, aliases)
      if /\A[\d\.]+\z/ =~ id_or_name
        id = id_or_name
        name = nil
      else
        name = normalize_schema_name(id_or_name)
        id = aliases[name]
      end
      [id, name]
    end

ensure_parse(group) click to toggle source

    # File lib/active_ldap/schema.rb, line 247
    def ensure_parse(group)
      return if @entries[group].nil?
      unless @entries[group].empty?
        fetch(group, 'nonexistent', 'nonexistent')
      end
    end

ensure_schema_info(group) click to toggle source

    # File lib/active_ldap/schema.rb, line 173
    def ensure_schema_info(group)
      @schema_info[group] ||= {:ids => {}, :aliases => {}}
      info = @schema_info[group]
      [info, info[:ids], info[:aliases]]
    end

normalize_attribute_name(name) click to toggle source

    # File lib/active_ldap/schema.rb, line 258
    def normalize_attribute_name(name)
      name.upcase.gsub(/_/, "-")
    end

normalize_entries(entries) click to toggle source

    # File lib/active_ldap/schema.rb, line 272
    def normalize_entries(entries)
      normalized_entries = default_entries
      normalized_keys = normalized_entries.keys
      entries.each do |name, values|
        normalized_name = normalized_keys.find do |key|
          key.downcase == name
        end
        normalized_entries[normalized_name || name] = values
      end
      normalized_entries
    end

normalize_schema_name(name) click to toggle source

    # File lib/active_ldap/schema.rb, line 254
    def normalize_schema_name(name)
      name.downcase.sub(/;.*$/, '')
    end

parse_attributes(str, attributes) click to toggle source

    # File lib/active_ldap/schema.rb, line 212
    def parse_attributes(str, attributes)
      str.scan(/([A-Z\-_]+)\s+
                (?:\(\s*(\w[\w\-;]*(?:\s+\$\s+\w[\w\-;]*)*)\s*\)|
                   \(\s*([^\)]*)\s*\)|
                   '([^\']*)'|
                   ((?!#{RESERVED_NAMES_RE})[a-zA-Z][a-zA-Z\d\-;]*)|
                   (\d[\d\.\{\}]+)|
                   ()
                )/
               ) do |name, multi_amp, multi, string, literal, syntax, no_value|
        case
        when multi_amp
          values = multi_amp.rstrip.split(/\s*\$\s*/)
        when multi
          values = multi.scan(/\s*'([^\']*)'\s*/).collect {|value| value[0]}
        when string
          values = [string]
        when literal
          values = [literal]
        when syntax
          values = [syntax]
        when no_value
          values = ["TRUE"]
        end
        attributes[normalize_attribute_name(name)] ||= []
        attributes[normalize_attribute_name(name)].concat(values)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.