Class ActiveLdap::Schema::Attribute
In: lib/active_ldap/schema.rb
Parent: Entry
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid DistinguishedNameNotSetError EntryNotFound LdapError SaveError StrongAuthenticationRequired NotImplemented AdapterNotFound TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError ConnectionNotSetup DistinguishedNameInvalid Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] Base DistinguishedName Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Normalizable Common Find LDIF Delete Update ActiveRecord::Callbacks GetText Parser 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 ActiveRecord::Validations Xml JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/xml.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb Compatible 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 ClassMethods Normalizable Attributes Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Configuration ClassMethods ObjectClass ClassMethods Callbacks lib/active_ldap/get_text/parser.rb GetText lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/base.rb lib/active_ldap/adapter/jndi.rb Adapter Validations GetTextFallback Helper ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_46_0.png

Methods

Included Modules

GetTextSupport HumanReadable

Attributes

super_attribute  [R] 

Public Class methods

[Source]

     # File lib/active_ldap/schema.rb, line 390
390:       def initialize(name, schema)
391:         super(name, schema, "attributeTypes")
392:       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 415
415:       def binary?
416:         @binary
417:       end

binary_required?

Returns true if the value MUST be transferred in binary

[Source]

     # File lib/active_ldap/schema.rb, line 422
422:       def binary_required?
423:         @binary_required
424:       end

directory_operation?

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

[Source]

     # File lib/active_ldap/schema.rb, line 430
430:       def directory_operation?
431:         @directory_operation
432:       end

[Source]

     # File lib/active_ldap/schema.rb, line 469
469:       def human_attribute_description
470:         self.class.human_attribute_description(self)
471:       end

[Source]

     # File lib/active_ldap/schema.rb, line 465
465:       def human_attribute_name
466:         self.class.human_attribute_name(self)
467:       end

[Source]

     # File lib/active_ldap/schema.rb, line 457
457:       def normalize_value(value)
458:         normalize_value_internal(value, false)
459:       end

read_only?

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

[Source]

     # File lib/active_ldap/schema.rb, line 398
398:       def read_only?
399:         @read_only
400:       end

single_value?

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

[Source]

     # File lib/active_ldap/schema.rb, line 407
407:       def single_value?
408:         @single_value
409:       end

[Source]

     # File lib/active_ldap/schema.rb, line 434
434:       def syntax
435:         @derived_syntax
436:       end

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 473
473:       def to_hash
474:         {
475:           :read_only => read_only?,
476:           :single_value => single_value?,
477:           :binary => binary?,
478:           :binary_required => binary_required?,
479:           :directory_operation => directory_operation?,
480:           :syntax => syntax,
481:           :syntax_description => syntax_description,
482:         }
483:       end

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 438
438:       def valid?(value)
439:         validate(value).nil?
440:       end

[Source]

     # File lib/active_ldap/schema.rb, line 442
442:       def validate(value)
443:         error_info = validate_each_value(value)
444:         return error_info if error_info
445:         begin
446:           normalize_value(value)
447:           nil
448:         rescue AttributeValueInvalid
449:           [$!.message]
450:         end
451:       end

Private Instance methods

[Source]

     # File lib/active_ldap/schema.rb, line 608
608:       def append_binary_key(hash)
609:         key, value = hash.to_a[0]
610:         if value.is_a?(Hash)
611:           append_binary_key(value)
612:         else
613:           hash.merge(key => {"binary" => value})
614:         end
615:       end

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 490
490:       def collect_info
491:         @description = attribute("DESC")[0]
492:         @super_attribute = attribute("SUP")[0]
493:         if @super_attribute
494:           @super_attribute = @schema.attribute(@super_attribute)
495:           @super_attribute = nil if @super_attribute.id.nil?
496:         end
497:         @read_only = attribute('NO-USER-MODIFICATION')[0] == 'TRUE'
498:         @single_value = attribute('SINGLE-VALUE')[0] == 'TRUE'
499:         @syntax = attribute("SYNTAX")[0]
500:         @syntax = @schema.ldap_syntax(@syntax) if @syntax
501:         if @syntax
502:           @binary_required = @syntax.binary_transfer_required?
503:           @binary = (@binary_required or !@syntax.human_readable?)
504:           @derived_syntax = @syntax
505:         else
506:           @binary_required = false
507:           @binary = false
508:           @derived_syntax = nil
509:           @derived_syntax = @super_attribute.syntax if @super_attribute
510:         end
511:         @directory_operation = attribute("USAGE").include?("directoryOperation")
512:       end

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 566
566:       def normalize_array_value(value, have_binary_mark)
567:         if single_value? and value.reject {|v| v.is_a?(Hash)}.size > 1
568:           format = _("Attribute %s can only have a single value: %s")
569:           message = format % [human_attribute_name, value.inspect]
570:           raise AttributeValueInvalid.new(self, value, message)
571:         end
572:         if value.empty?
573:           if !have_binary_mark and binary_required?
574:             [{'binary' => value}]
575:           else
576:             value
577:           end
578:         else
579:           value.collect do |entry|
580:             normalize_value_internal(entry, have_binary_mark)[0]
581:           end
582:         end
583:       end

[Source]

     # File lib/active_ldap/schema.rb, line 585
585:       def normalize_hash_value(value, have_binary_mark)
586:         if value.size > 1
587:           format = _("Attribute %s: Hash must have one key-value pair only: %s")
588:           message = format % [human_attribute_name, value.inspect]
589:           raise AttributeValueInvalid.new(self, value, message)
590:         end
591: 
592:         if !have_binary_mark and binary_required? and !have_binary_key?(value)
593:           [append_binary_key(value)]
594:         else
595:           key = value.keys[0]
596:           have_binary_mark ||= key == "binary"
597:           [{key => normalize_value_internal(value.values[0], have_binary_mark)}]
598:         end
599:       end

[Source]

     # File lib/active_ldap/schema.rb, line 546
546:       def normalize_value_internal(value, have_binary_mark)
547:         case value
548:         when Array
549:           normalize_array_value(value, have_binary_mark)
550:         when Hash
551:           normalize_hash_value(value, have_binary_mark)
552:         else
553:           if value.blank?
554:             value = []
555:           else
556:             value = send_to_syntax(value, :normalize_value, value)
557:           end
558:           if !have_binary_mark and binary_required?
559:             [{'binary' => value}]
560:           else
561:             value.is_a?(Array) ? value : [value]
562:           end
563:         end
564:       end

[Source]

     # File lib/active_ldap/schema.rb, line 514
514:       def send_to_syntax(default_value, method_name, *args)
515:         _syntax = syntax
516:         if _syntax
517:           _syntax.send(method_name, *args)
518:         else
519:           default_value
520:         end
521:       end

[Source]

     # File lib/active_ldap/schema.rb, line 523
523:       def validate_each_value(value, option=nil)
524:         failed_reason = nil
525:         case value
526:         when Hash
527:           original_option = option
528:           value.each do |sub_option, val|
529:             opt = [original_option, sub_option].compact.join(";")
530:             failed_reason, option = validate_each_value(val, opt)
531:             break if failed_reason
532:           end
533:         when Array
534:           original_option = option
535:           value.each do |val|
536:             failed_reason, option = validate_each_value(val, original_option)
537:             break if failed_reason
538:           end
539:         else
540:           failed_reason = send_to_syntax(nil, :validate, value)
541:         end
542:         return nil if failed_reason.nil?
543:         [failed_reason, option]
544:       end

[Validate]