class ROM::LDAP::LDIF::Exporter

Export Entry objects as LDIF files.

@param tuple [Array<Hash>]

@api private

Public Instance Methods

to_ldif() click to toggle source

@return [String]

# File lib/rom/ldap/ldif/exporter.rb, line 22
def to_ldif
  tuples.map { |tuple| create_entry(tuple) }.join(NEW_LINE)
end

Private Instance Methods

create_entry(tuple) click to toggle source

@param tuple [Hash]

@return [Array<String>]

# File lib/rom/ldap/ldif/exporter.rb, line 32
def create_entry(tuple)
  ary = []
  tuple.each do |key, values|
    values.each { |value| ary << key_value_pair(key, value) }
  end
  ary << NEW_LINE
  ary
end
key_value_pair(key, value) click to toggle source

@param key [String] @param value [String]

@return [String]

# File lib/rom/ldap/ldif/exporter.rb, line 46
def key_value_pair(key, value)
  if /userpassword/i.match?(key)
    value = Functions[:to_base64].call(value)
    "#{key}:: #{value}"
  elsif value_is_binary?(value)
    value = Functions[:to_base64].call(value, strict: false)
    value = value.gsub(/#{NEW_LINE}/m, "#{NEW_LINE} ")
    "#{key}:: #{value}"
  else
    "#{key}: #{value}"
  end
end
value_is_binary?(value) click to toggle source
jpegphoto:<file:///tmp/myphoto.jpg
userpassword::qwerty

@param value [String]

@return [Boolean]

# File lib/rom/ldap/ldif/exporter.rb, line 65
def value_is_binary?(value)
  return true if value.start_with?(':', '<')

  value.each_byte do |byte|
    return true if (byte < 32) || (byte > 126)
  end
  false
end