Class ActiveLdap::Schema::Attribute
In: lib/active_ldap/schema.rb
Parent: Entry
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid LdapError DistinguishedNameNotSetError EntryNotFound SaveError StrongAuthenticationRequired AdapterNotFound ConnectionNotEstablished TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError DistinguishedNameInvalid DistinguishedName Base Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Common Find LDIF Delete Update Normalizable GetText Parser ActiveRecord::Callbacks ActiveRecord::Validations Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/jndi.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Jndi Ldap NetLdap GetTextSupport Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb ClassMethods Associations LdapBenchmarking ActionController Populate lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb lib/active_ldap/association/has_many.rb HasManyUtils Association ClassMethods Tree Acts Command Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Normalizable Attributes ClassMethods Configuration ClassMethods ObjectClass lib/active_ldap/get_text/parser.rb GetText ClassMethods Callbacks Validations lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/jndi.rb Adapter Helper GetTextFallback ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_44_0.png

Methods

Included Modules

GetTextSupport HumanReadable

Attributes

super_attribute  [R] 

Public Class methods

[Source]

     # File lib/active_ldap/schema.rb, line 356
356:       def initialize(name, schema)
357:         super(name, schema, "attributeTypes")
358:       end

Public Instance methods

binary?

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

[Source]

     # File lib/active_ldap/schema.rb, line 381
381:       def binary?
382:         @binary
383:       end

binary_required?

Returns true if the value MUST be transferred in binary

[Source]

     # File lib/active_ldap/schema.rb, line 388
388:       def binary_required?
389:         @binary_required
390:       end

[Source]

     # File lib/active_ldap/schema.rb, line 427
427:       def human_attribute_description
428:         self.class.human_attribute_description(self)
429:       end

[Source]

     # File lib/active_ldap/schema.rb, line 423
423:       def human_attribute_name
424:         self.class.human_attribute_name(self)
425:       end

[Source]

     # File lib/active_ldap/schema.rb, line 415
415:       def normalize_value(value)
416:         normalize_value_internal(value, false)
417:       end

read_only?

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

[Source]

     # File lib/active_ldap/schema.rb, line 364
364:       def read_only?
365:         @read_only
366:       end

single_value?

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

[Source]

     # File lib/active_ldap/schema.rb, line 373
373:       def single_value?
374:         @single_value
375:       end

[Source]

     # File lib/active_ldap/schema.rb, line 392
392:       def syntax
393:         @derived_syntax
394:       end

[Source]

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

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 396
396:       def valid?(value)
397:         validate(value).nil?
398:       end

[Source]

     # File lib/active_ldap/schema.rb, line 400
400:       def validate(value)
401:         error_info = validate_each_value(value)
402:         return error_info if error_info
403:         begin
404:           normalize_value(value)
405:           nil
406:         rescue AttributeValueInvalid
407:           [$!.message]
408:         end
409:       end

Private Instance methods

[Source]

     # File lib/active_ldap/schema.rb, line 553
553:       def append_binary_key(hash)
554:         key, value = hash.to_a[0]
555:         if value.is_a?(Hash)
556:           append_binary_key(value)
557:         else
558:           hash.merge(key => {"binary" => value})
559:         end
560:       end

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 436
436:       def collect_info
437:         @description = attribute("DESC")[0]
438:         @super_attribute = attribute("SUP")[0]
439:         if @super_attribute
440:           @super_attribute = @schema.attribute(@super_attribute)
441:           @super_attribute = nil if @super_attribute.id.nil?
442:         end
443:         @read_only = attribute('NO-USER-MODIFICATION')[0] == 'TRUE'
444:         @single_value = attribute('SINGLE-VALUE')[0] == 'TRUE'
445:         @syntax = attribute("SYNTAX")[0]
446:         @syntax = @schema.ldap_syntax(@syntax) if @syntax
447:         if @syntax
448:           @binary_required = @syntax.binary_transfer_required?
449:           @binary = (@binary_required or !@syntax.human_readable?)
450:           @derived_syntax = @syntax
451:         else
452:           @binary_required = false
453:           @binary = false
454:           @derived_syntax = nil
455:           @derived_syntax = @super_attribute.syntax if @super_attribute
456:         end
457:       end

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 511
511:       def normalize_array_value(value, have_binary_mark)
512:         if single_value? and value.reject {|v| v.is_a?(Hash)}.size > 1
513:           format = _("Attribute %s can only have a single value: %s")
514:           message = format % [human_attribute_name, value.inspect]
515:           raise AttributeValueInvalid.new(self, value, message)
516:         end
517:         if value.empty?
518:           if !have_binary_mark and binary_required?
519:             [{'binary' => value}]
520:           else
521:             value
522:           end
523:         else
524:           value.collect do |entry|
525:             normalize_value_internal(entry, have_binary_mark)[0]
526:           end
527:         end
528:       end

[Source]

     # File lib/active_ldap/schema.rb, line 530
530:       def normalize_hash_value(value, have_binary_mark)
531:         if value.size > 1
532:           format = _("Attribute %s: Hash must have one key-value pair only: %s")
533:           message = format % [human_attribute_name, value.inspect]
534:           raise AttributeValueInvalid.new(self, value, message)
535:         end
536: 
537:         if !have_binary_mark and binary_required? and !have_binary_key?(value)
538:           [append_binary_key(value)]
539:         else
540:           key = value.keys[0]
541:           have_binary_mark ||= key == "binary"
542:           [{key => normalize_value_internal(value.values[0], have_binary_mark)}]
543:         end
544:       end

[Source]

     # File lib/active_ldap/schema.rb, line 491
491:       def normalize_value_internal(value, have_binary_mark)
492:         case value
493:         when Array
494:           normalize_array_value(value, have_binary_mark)
495:         when Hash
496:           normalize_hash_value(value, have_binary_mark)
497:         else
498:           if value.blank?
499:             value = []
500:           else
501:             value = send_to_syntax(value, :normalize_value, value)
502:           end
503:           if !have_binary_mark and binary_required?
504:             [{'binary' => value}]
505:           else
506:             value.is_a?(Array) ? value : [value]
507:           end
508:         end
509:       end

[Source]

     # File lib/active_ldap/schema.rb, line 459
459:       def send_to_syntax(default_value, method_name, *args)
460:         _syntax = syntax
461:         if _syntax
462:           _syntax.send(method_name, *args)
463:         else
464:           default_value
465:         end
466:       end

[Source]

     # File lib/active_ldap/schema.rb, line 468
468:       def validate_each_value(value, option=nil)
469:         failed_reason = nil
470:         case value
471:         when Hash
472:           original_option = option
473:           value.each do |sub_option, val|
474:             opt = [original_option, sub_option].compact.join(";")
475:             failed_reason, option = validate_each_value(val, opt)
476:             break if failed_reason
477:           end
478:         when Array
479:           original_option = option
480:           value.each do |val|
481:             failed_reason, option = validate_each_value(val, original_option)
482:             break if failed_reason
483:           end
484:         else
485:           failed_reason = send_to_syntax(nil, :validate, value)
486:         end
487:         return nil if failed_reason.nil?
488:         [failed_reason, option]
489:       end

[Validate]