Module | ActiveLdap::Ldif::Attribute |
In: |
lib/active_ldap/ldif.rb
|
SIZE | = | 75 |
# File lib/active_ldap/ldif.rb, line 34 34: def binary_value?(value) 35: if value.respond_to?(:encoding) 36: return true if value.encoding == Encoding.find("ascii-8bit") 37: end 38: if /\A#{Parser::SAFE_STRING}\z/ =~ value 39: false 40: else 41: true 42: end 43: end
# File lib/active_ldap/ldif.rb, line 45 45: def encode(name, value) 46: return "#{name}:\n" if value.blank? 47: result = "#{name}:" 48: 49: if value[-1, 1] == ' ' or binary_value?(value) 50: result << ":" 51: value = [value].pack("m").gsub(/\n/, '') 52: end 53: result << " " 54: 55: first_line_value_size = SIZE - result.size 56: if value.size > first_line_value_size 57: first_line_value = value[0, first_line_value_size] 58: rest_value = value[first_line_value_size..-1] 59: else 60: first_line_value = value 61: rest_value = nil 62: end 63: 64: result << "#{first_line_value}\n" 65: return result if rest_value.nil? 66: 67: rest_value.scan(/.{1,#{SIZE - 1}}/).each do |line| # FIXME 68: result << " #{line}\n" 69: end 70: result 71: end
# File lib/active_ldap/ldif.rb, line 73 73: def normalize_value(value, result=[]) 74: case value 75: when Array 76: value.each {|val| normalize_value(val, result)} 77: when Hash 78: value.each do |option, val| 79: normalize_value(val).each do |options, v| 80: result << [[option] + options, v] 81: end 82: end 83: result 84: else 85: result << [[], value] 86: end 87: result 88: end