class ActiveLdap::Schema::Attribute

def append_binary_key(hash)

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

def apply_encoding(value)

Returns:
  • (void) -
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

def attribute(attribute_name, name=@name)

def attribute(attribute_name, name=@name)
  @schema.attribute_type(name, attribute_name)
end

def binary?

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

binary?
def binary?
  @binary
end

def binary_required?

Returns true if the value MUST be transferred in binary

binary_required?
def binary_required?
  @binary_required
end

def collect_info

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

def directory_operation?

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

directory_operation?
def directory_operation?
  @directory_operation
end

def have_binary_key?(hash)

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

def human_attribute_description

def human_attribute_description
  self.class.human_attribute_description(self)
end

def human_attribute_name

def human_attribute_name
  self.class.human_attribute_name(self)
end

def initialize(name, schema)

def initialize(name, schema)
  super(name, schema, "attributeTypes")
end

def normalize_array_value(value, have_binary_mark)

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

def normalize_hash_value(value, have_binary_mark)

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

def normalize_value(value)

def normalize_value(value)
  normalize_value_internal(value, false)
end

def normalize_value_internal(value, have_binary_mark)

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

def read_only?

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

read_only?
def read_only?
  @read_only
end

def send_to_syntax(default_value, method_name, *args)

def send_to_syntax(default_value, method_name, *args)
  _syntax = syntax
  if _syntax
    _syntax.send(method_name, *args)
  else
    default_value
  end
end

def single_value?

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

single_value?
def single_value?
  @single_value
end

def syntax

def syntax
  @derived_syntax
end

def syntax_description

def syntax_description
  send_to_syntax(nil, :description)
end

def to_hash

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

def type_cast(value)

def type_cast(value)
  send_to_syntax(value, :type_cast, value)
end

def valid?(value)

def valid?(value)
  validate(value).nil?
end

def validate(value)

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

def validate_each_value(value, option=nil)

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