Added Dataset::to_ldif
This commit is contained in:
parent
c423ced9e2
commit
7a0da7c9bc
|
@ -60,7 +60,7 @@ class Dataset < Hash
|
|||
# $1 is the attribute name
|
||||
# $2 is a colon iff the attr-value is base-64 encoded
|
||||
# $' is the attr-value
|
||||
#attrvalue = ($2 == ":") ? Base64.decode64($') : $'
|
||||
# Avoid the Base64 class because not all Ruby versions have it.
|
||||
attrvalue = ($2 == ":") ? $'.unpack('m').shift : $'
|
||||
ds[dn][$1.downcase.intern] << attrvalue
|
||||
end
|
||||
|
@ -78,6 +78,28 @@ class Dataset < Hash
|
|||
end
|
||||
|
||||
|
||||
def to_ldif
|
||||
ary = []
|
||||
ary += (@comments || [])
|
||||
|
||||
keys.sort.each {|dn|
|
||||
ary << "dn: #{dn}"
|
||||
|
||||
self[dn].keys.map {|sym| sym.to_s}.sort.each {|attr|
|
||||
self[dn][attr.intern].each {|val|
|
||||
ary << "#{attr}: #{val}"
|
||||
}
|
||||
}
|
||||
|
||||
ary << ""
|
||||
}
|
||||
|
||||
block_given? and ary.each {|line| yield line}
|
||||
|
||||
ary
|
||||
end
|
||||
|
||||
|
||||
end # Dataset
|
||||
|
||||
end # LDAP
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
|
||||
$:.unshift "lib"
|
||||
|
||||
require 'test/unit'
|
||||
require 'tests/testber'
|
||||
require 'tests/testldif'
|
||||
require 'tests/testldap'
|
||||
|
||||
require 'net/ldap'
|
||||
require 'net/ldif'
|
||||
|
||||
|
@ -51,6 +56,16 @@ class TestLdif < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
# TODO, need some tests.
|
||||
# Must test folded lines and base64-encoded lines as well as normal ones.
|
||||
def test_to_ldif
|
||||
File.open( TestLdifFilename, "r" ) {|f|
|
||||
ds = Net::LDAP::Dataset::read_ldif( f )
|
||||
ds.to_ldif
|
||||
assert_equal( true, false ) # REMOVE WHEN WE HAVE SOME TESTS HERE.
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue