### Home Classes Methods

### In Files

- lib/active_ldap/schema.rb

### Parent

ActiveLdap::Schema::Entry

### Methods

- ::new
- #append_binary_key
- #apply_encoding
- #attribute
- #binary?
- #binary_required?
- #collect_info
- #directory_operation?
- #have_binary_key?
- #human_attribute_description
- #human_attribute_name
- #normalize_array_value
- #normalize_hash_value
- #normalize_value
- #normalize_value_internal
- #read_only?
- #send_to_syntax
- #single_value?
- #syntax
- #syntax_description
- #to_hash
- #type_cast
- #valid?
- #validate
- #validate_each_value

### Included Modules

- ActiveLdap::GetTextSupport
- ActiveLdap::HumanReadable

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

### Attributes

super_attribute[R]

### Public Class Methods

new(name, schema) click to toggle source

    # File lib/active_ldap/schema.rb, line 398
    def initialize(name, schema)
      super(name, schema, "attributeTypes")
    end

### Public Instance Methods

apply_encoding(value) click to toggle source

Sets binary encoding to value if the given attribute's syntax is binary syntax. Does nothing otherwise. @return [void]

    # File lib/active_ldap/schema.rb, line 430
    def apply_encoding(value)
      return unless binary?
      case value
      when Hash
        value.each_value do |sub_value|
          apply_encoding(sub_value)
        end
      when Array
        value.each do |sub_value|
          apply_encoding(sub_value)
        end
      else
        return unless value.respond_to?(:force_encoding)
        value.force_encoding("ASCII-8BIT")
      end
    end

binary?() click to toggle source

binary?

Returns true if the given attribute's syntax is binary syntax, X-NOT-HUMAN-READABLE or X-BINARY-TRANSFER-REQUIRED

    # File lib/active_ldap/schema.rb, line 423
    def binary?
      @binary
    end

binary_required?() click to toggle source

binary_required?

Returns true if the value MUST be transferred in binary

    # File lib/active_ldap/schema.rb, line 450
    def binary_required?
      @binary_required
    end

directory_operation?() click to toggle source

directory_operation?

Returns true if an attribute is directory operation. It means that USAGE contains directoryOperation.

    # File lib/active_ldap/schema.rb, line 458
    def directory_operation?
      @directory_operation
    end

human_attribute_description() click to toggle source

    # File lib/active_ldap/schema.rb, line 497
    def human_attribute_description
      self.class.human_attribute_description(self)
    end

human_attribute_name() click to toggle source

    # File lib/active_ldap/schema.rb, line 493
    def human_attribute_name
      self.class.human_attribute_name(self)
    end

normalize_value(value) click to toggle source

    # File lib/active_ldap/schema.rb, line 485
    def normalize_value(value)
      normalize_value_internal(value, false)
    end

read_only?() click to toggle source

read_only?

Returns true if an attribute is read-only NO-USER-MODIFICATION

    # File lib/active_ldap/schema.rb, line 406
    def read_only?
      @read_only
    end

single_value?() click to toggle source

single_value?

Returns true if an attribute can only have one value defined SINGLE-VALUE

    # File lib/active_ldap/schema.rb, line 415
    def single_value?
      @single_value
    end

syntax() click to toggle source

    # File lib/active_ldap/schema.rb, line 462
    def syntax
      @derived_syntax
    end

syntax_description() click to toggle source

    # File lib/active_ldap/schema.rb, line 489
    def syntax_description
      send_to_syntax(nil, :description)
    end

to_hash() click to toggle source

    # File lib/active_ldap/schema.rb, line 501
    def to_hash
      {
        :read_only => read_only?,
        :single_value => single_value?,
        :binary => binary?,
        :binary_required => binary_required?,
        :directory_operation => directory_operation?,
        :syntax => syntax,
        :syntax_description => syntax_description,
      }
    end

type_cast(value) click to toggle source

    # File lib/active_ldap/schema.rb, line 481
    def type_cast(value)
      send_to_syntax(value, :type_cast, value)
    end

valid?(value) click to toggle source

    # File lib/active_ldap/schema.rb, line 466
    def valid?(value)
      validate(value).nil?
    end

validate(value) click to toggle source

    # File lib/active_ldap/schema.rb, line 470
    def validate(value)
      error_info = validate_each_value(value)
      return error_info if error_info
      begin
        normalize_value(value)
        nil
      rescue AttributeValueInvalid
        [$!.message]
      end
    end

### Private Instance Methods

append_binary_key(hash) click to toggle source

    # File lib/active_ldap/schema.rb, line 636
    def append_binary_key(hash)
      key, value = hash.to_a[0]
      if value.is_a?(Hash)
        append_binary_key(value)
      else
        hash.merge(key => {"binary" => value})
      end
    end

attribute(attribute_name, name=@name) click to toggle source

    # File lib/active_ldap/schema.rb, line 514
    def attribute(attribute_name, name=@name)
      @schema.attribute_type(name, attribute_name)
    end

collect_info() click to toggle source

    # File lib/active_ldap/schema.rb, line 518
    def collect_info
      @description = attribute("DESC")[0]
      @super_attribute = attribute("SUP")[0]
      if @super_attribute
        @super_attribute = @schema.attribute(@super_attribute)
        @super_attribute = nil if @super_attribute.id.nil?
      end
      @read_only = attribute('NO-USER-MODIFICATION')[0] == 'TRUE'
      @single_value = attribute('SINGLE-VALUE')[0] == 'TRUE'
      @syntax = attribute("SYNTAX")[0]
      @syntax = @schema.ldap_syntax(@syntax) if @syntax
      if @syntax
        @binary_required = @syntax.binary_transfer_required?
        @binary = @syntax.binary?
        @derived_syntax = @syntax
      else
        @binary_required = false
        @binary = false
        @derived_syntax = nil
        @derived_syntax = @super_attribute.syntax if @super_attribute
      end
      @directory_operation = attribute("USAGE").include?("directoryOperation")
    end

have_binary_key?(hash) click to toggle source

    # File lib/active_ldap/schema.rb, line 629
    def have_binary_key?(hash)
      key, value = hash.to_a[0]
      return true if key == "binary"
      return have_binary_key?(value) if value.is_a?(Hash)
      false
    end

normalize_array_value(value, have_binary_mark) click to toggle source

    # File lib/active_ldap/schema.rb, line 594
    def normalize_array_value(value, have_binary_mark)
      if single_value? and value.reject {|v| v.is_a?(Hash)}.size > 1
        format = _("Attribute %s can only have a single value: %s")
        message = format % [human_attribute_name, value.inspect]
        raise AttributeValueInvalid.new(self, value, message)
      end
      if value.empty?
        if !have_binary_mark and binary_required?
          [{'binary' => value}]
        else
          value
        end
      else
        value.collect do |entry|
          normalize_value_internal(entry, have_binary_mark)[0]
        end
      end
    end

normalize_hash_value(value, have_binary_mark) click to toggle source

    # File lib/active_ldap/schema.rb, line 613
    def normalize_hash_value(value, have_binary_mark)
      if value.size > 1
        format = _("Attribute %s: Hash must have one key-value pair only: %s")
        message = format % [human_attribute_name, value.inspect]
        raise AttributeValueInvalid.new(self, value, message)
      end

      if !have_binary_mark and binary_required? and !have_binary_key?(value)
        [append_binary_key(value)]
      else
        key = value.keys[0]
        have_binary_mark ||= key == "binary"
        [{key => normalize_value_internal(value.values[0], have_binary_mark)}]
      end
    end

normalize_value_internal(value, have_binary_mark) click to toggle source

    # File lib/active_ldap/schema.rb, line 574
    def normalize_value_internal(value, have_binary_mark)
      case value
      when Array
        normalize_array_value(value, have_binary_mark)
      when Hash
        normalize_hash_value(value, have_binary_mark)
      else
        if value.nil?
          value = []
        else
          value = send_to_syntax(value, :normalize_value, value)
        end
        if !have_binary_mark and binary_required?
          [{'binary' => value}]
        else
          value.is_a?(Array) ? value : [value]
        end
      end
    end

send_to_syntax(default_value, method_name, *args) click to toggle source

    # File lib/active_ldap/schema.rb, line 542
    def send_to_syntax(default_value, method_name, *args)
      _syntax = syntax
      if _syntax
        _syntax.send(method_name, *args)
      else
        default_value
      end
    end

validate_each_value(value, option=nil) click to toggle source

    # File lib/active_ldap/schema.rb, line 551
    def validate_each_value(value, option=nil)
      failed_reason = nil
      case value
      when Hash
        original_option = option
        value.each do |sub_option, val|
          opt = [original_option, sub_option].compact.join(";")
          failed_reason, option = validate_each_value(val, opt)
          break if failed_reason
        end
      when Array
        original_option = option
        value.each do |val|
          failed_reason, option = validate_each_value(val, original_option)
          break if failed_reason
        end
      else
        failed_reason = send_to_syntax(nil, :validate, value)
      end
      return nil if failed_reason.nil?
      [failed_reason, option]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.