| 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: value = value.to_s unless value.is_a?(String)
50: if value[-1, 1] == ' ' or binary_value?(value)
51: result << ":"
52: value = [value].pack("m").gsub(/\n/, '')
53: end
54: result << " "
55:
56: first_line_value_size = SIZE - result.size
57: if value.size > first_line_value_size
58: first_line_value = value[0, first_line_value_size]
59: rest_value = value[first_line_value_size..-1]
60: else
61: first_line_value = value
62: rest_value = nil
63: end
64:
65: result << "#{first_line_value}\n"
66: return result if rest_value.nil?
67:
68: rest_value.scan(/.{1,#{SIZE - 1}}/).each do |line| # FIXME
69: result << " #{line}\n"
70: end
71: result
72: end
# File lib/active_ldap/ldif.rb, line 74
74: def normalize_value(value, result=[])
75: case value
76: when Array
77: value.each {|val| normalize_value(val, result)}
78: when Hash
79: value.each do |option, val|
80: normalize_value(val).each do |options, v|
81: result << [[option] + options, v]
82: end
83: end
84: result
85: else
86: result << [[], value]
87: end
88: result
89: end