module ActiveLdap::Populate

def ensure_ou(name, options={})

def ensure_ou(name, options={})
  if options.is_a?(Class)
    base_class = options
    options = {}
  else
    base_class = options[:base_class] || Base
  end
  name = name.to_s if name.is_a?(DN)
  name = name.gsub(/\Aou\s*=\s*/i, '')
  ou_class = Class.new(base_class)
  ou_class.ldap_mapping(:dn_attribute => "ou",
                        :prefix => "",
                        :classes => ["top", "organizationalUnit"])
  ou_class.base = options[:base]
  return if ou_class.exist?(name)
  ou_class.new(name).save!
end