Class | ActiveLdap::Schema::Attribute |
In: |
lib/active_ldap/schema.rb
|
Parent: | Entry |
super_attribute | [R] |
# File lib/active_ldap/schema.rb, line 390 390: def initialize(name, schema) 391: super(name, schema, "attributeTypes") 392: end
Returns true if the value MUST be transferred in binary
# File lib/active_ldap/schema.rb, line 422 422: def binary_required? 423: @binary_required 424: end
Returns true if an attribute is directory operation. It means that USAGE contains directoryOperation.
# File lib/active_ldap/schema.rb, line 430 430: def directory_operation? 431: @directory_operation 432: end
# File lib/active_ldap/schema.rb, line 469 469: def human_attribute_description 470: self.class.human_attribute_description(self) 471: end
# File lib/active_ldap/schema.rb, line 465 465: def human_attribute_name 466: self.class.human_attribute_name(self) 467: end
# File lib/active_ldap/schema.rb, line 457 457: def normalize_value(value) 458: normalize_value_internal(value, false) 459: end
Returns true if an attribute is read-only NO-USER-MODIFICATION
# File lib/active_ldap/schema.rb, line 398 398: def read_only? 399: @read_only 400: end
Returns true if an attribute can only have one value defined SINGLE-VALUE
# File lib/active_ldap/schema.rb, line 407 407: def single_value? 408: @single_value 409: end
# File lib/active_ldap/schema.rb, line 461 461: def syntax_description 462: send_to_syntax(nil, :description) 463: end
# 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
# File lib/active_ldap/schema.rb, line 453 453: def type_cast(value) 454: send_to_syntax(value, :type_cast, value) 455: end
# File lib/active_ldap/schema.rb, line 438 438: def valid?(value) 439: validate(value).nil? 440: end
# 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
# 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
# File lib/active_ldap/schema.rb, line 486 486: def attribute(attribute_name, name=@name) 487: @schema.attribute_type(name, attribute_name) 488: end
# 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
# 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
# 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
# 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
# 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
# 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
# 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