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 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] 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 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 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_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

[Source]

     # File lib/active_ldap/schema.rb, line 461
461:       def human_attribute_description
462:         self.class.human_attribute_description(self)
463:       end

[Source]

     # File lib/active_ldap/schema.rb, line 457
457:       def human_attribute_name
458:         self.class.human_attribute_name(self)
459:       end

[Source]

     # File lib/active_ldap/schema.rb, line 449
449:       def normalize_value(value)
450:         normalize_value_internal(value, false)
451:       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 426
426:       def syntax
427:         @derived_syntax
428:       end

[Source]

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

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 430
430:       def valid?(value)
431:         validate(value).nil?
432:       end

[Source]

     # File lib/active_ldap/schema.rb, line 434
434:       def validate(value)
435:         error_info = validate_each_value(value)
436:         return error_info if error_info
437:         begin
438:           normalize_value(value)
439:           nil
440:         rescue AttributeValueInvalid
441:           [$!.message]
442:         end
443:       end

Private Instance methods

[Source]

     # File lib/active_ldap/schema.rb, line 587
587:       def append_binary_key(hash)
588:         key, value = hash.to_a[0]
589:         if value.is_a?(Hash)
590:           append_binary_key(value)
591:         else
592:           hash.merge(key => {"binary" => value})
593:         end
594:       end

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 470
470:       def collect_info
471:         @description = attribute("DESC")[0]
472:         @super_attribute = attribute("SUP")[0]
473:         if @super_attribute
474:           @super_attribute = @schema.attribute(@super_attribute)
475:           @super_attribute = nil if @super_attribute.id.nil?
476:         end
477:         @read_only = attribute('NO-USER-MODIFICATION')[0] == 'TRUE'
478:         @single_value = attribute('SINGLE-VALUE')[0] == 'TRUE'
479:         @syntax = attribute("SYNTAX")[0]
480:         @syntax = @schema.ldap_syntax(@syntax) if @syntax
481:         if @syntax
482:           @binary_required = @syntax.binary_transfer_required?
483:           @binary = (@binary_required or !@syntax.human_readable?)
484:           @derived_syntax = @syntax
485:         else
486:           @binary_required = false
487:           @binary = false
488:           @derived_syntax = nil
489:           @derived_syntax = @super_attribute.syntax if @super_attribute
490:         end
491:       end

[Source]

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

[Source]

     # File lib/active_ldap/schema.rb, line 545
545:       def normalize_array_value(value, have_binary_mark)
546:         if single_value? and value.reject {|v| v.is_a?(Hash)}.size > 1
547:           format = _("Attribute %s can only have a single value: %s")
548:           message = format % [human_attribute_name, value.inspect]
549:           raise AttributeValueInvalid.new(self, value, message)
550:         end
551:         if value.empty?
552:           if !have_binary_mark and binary_required?
553:             [{'binary' => value}]
554:           else
555:             value
556:           end
557:         else
558:           value.collect do |entry|
559:             normalize_value_internal(entry, have_binary_mark)[0]
560:           end
561:         end
562:       end

[Source]

     # File lib/active_ldap/schema.rb, line 564
564:       def normalize_hash_value(value, have_binary_mark)
565:         if value.size > 1
566:           format = _("Attribute %s: Hash must have one key-value pair only: %s")
567:           message = format % [human_attribute_name, value.inspect]
568:           raise AttributeValueInvalid.new(self, value, message)
569:         end
570: 
571:         if !have_binary_mark and binary_required? and !have_binary_key?(value)
572:           [append_binary_key(value)]
573:         else
574:           key = value.keys[0]
575:           have_binary_mark ||= key == "binary"
576:           [{key => normalize_value_internal(value.values[0], have_binary_mark)}]
577:         end
578:       end

[Source]

     # File lib/active_ldap/schema.rb, line 525
525:       def normalize_value_internal(value, have_binary_mark)
526:         case value
527:         when Array
528:           normalize_array_value(value, have_binary_mark)
529:         when Hash
530:           normalize_hash_value(value, have_binary_mark)
531:         else
532:           if value.blank?
533:             value = []
534:           else
535:             value = send_to_syntax(value, :normalize_value, value)
536:           end
537:           if !have_binary_mark and binary_required?
538:             [{'binary' => value}]
539:           else
540:             value.is_a?(Array) ? value : [value]
541:           end
542:         end
543:       end

[Source]

     # File lib/active_ldap/schema.rb, line 493
493:       def send_to_syntax(default_value, method_name, *args)
494:         _syntax = syntax
495:         if _syntax
496:           _syntax.send(method_name, *args)
497:         else
498:           default_value
499:         end
500:       end

[Source]

     # File lib/active_ldap/schema.rb, line 502
502:       def validate_each_value(value, option=nil)
503:         failed_reason = nil
504:         case value
505:         when Hash
506:           original_option = option
507:           value.each do |sub_option, val|
508:             opt = [original_option, sub_option].compact.join(";")
509:             failed_reason, option = validate_each_value(val, opt)
510:             break if failed_reason
511:           end
512:         when Array
513:           original_option = option
514:           value.each do |val|
515:             failed_reason, option = validate_each_value(val, original_option)
516:             break if failed_reason
517:           end
518:         else
519:           failed_reason = send_to_syntax(nil, :validate, value)
520:         end
521:         return nil if failed_reason.nil?
522:         [failed_reason, option]
523:       end

[Validate]