module ActiveLdap::Ldif::Attribute
def binary_value?(value)
def binary_value?(value) if value.respond_to?(:encoding) return true if value.encoding == Encoding.find("ascii-8bit") end if /\A#{Parser::SAFE_STRING}\z/ =~ value false else true end end
def encode(name, value)
def encode(name, value) return "#{name}:\n" if value.blank? result = "#{name}:" value = value.to_s unless value.is_a?(String) if value[-1, 1] == ' ' or binary_value?(value) result << ":" value = [value].pack("m").gsub(/\n/, '') end result << " " first_line_value_size = SIZE - result.size if value.size > first_line_value_size first_line_value = value[0, first_line_value_size] rest_value = value[first_line_value_size..-1] else first_line_value = value rest_value = nil end result << "#{first_line_value}\n" return result if rest_value.nil? rest_value.scan(/.{1,#{SIZE - 1}}/).each do |line| # FIXME result << " #{line}\n" end result end
def normalize_value(value, result=[])
def normalize_value(value, result=[]) case value when Array value.each {|val| normalize_value(val, result)} when Hash value.each do |option, val| normalize_value(val).each do |options, v| result << [[option] + options, v] end end result else result << [[], value] end result end