File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 44# to and from LDIF strings and Net::LDAP::Entry objects.
55class Net ::LDAP ::Dataset < Hash
66 ##
7- # Dataset object comments.
8- attr_reader :comments
7+ # Dataset object version, comments.
8+ attr_accessor :version
9+ attr_reader :comments
910
1011 def initialize ( *args , &block ) # :nodoc:
1112 super
13+ @version = nil
1214 @comments = [ ]
1315 end
1416
@@ -17,6 +19,12 @@ def initialize(*args, &block) # :nodoc:
1719 # entries.
1820 def to_ldif
1921 ary = [ ]
22+
23+ if version
24+ ary << "version: #{ version } "
25+ ary << ""
26+ end
27+
2028 ary += @comments unless @comments . empty?
2129 keys . sort . each do |dn |
2230 ary << "dn: #{ dn } "
@@ -125,6 +133,9 @@ def read_ldif(io)
125133 if line =~ /^#/
126134 ds . comments << line
127135 yield :comment , line if block_given?
136+ elsif line =~ /^version:[\s ]*([0-9]+)$/i
137+ ds . version = $1
138+ yield :version , line if block_given?
128139 elsif line =~ /^dn:[\s ]*/i
129140 dn = $'
130141 ds [ dn ] = Hash . new { |k , v | k [ v ] = [ ] }
Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ def test_empty_ldif
1313 assert_equal ( true , ds . empty? )
1414 end
1515
16+ def test_ldif_with_version
17+ io = StringIO . new ( "version: 1" )
18+ ds = Net ::LDAP ::Dataset . read_ldif ( io )
19+ assert_equal "1" , ds . version
20+ end
21+
1622 def test_ldif_with_comments
1723 str = [ "# Hello from LDIF-land" , "# This is an unterminated comment" ]
1824 io = StringIO . new ( str [ 0 ] + "\r \n " + str [ 1 ] )
@@ -76,4 +82,11 @@ def test_to_ldif
7682 assert_equal ( entries . size , ds . size )
7783 assert_equal ( entries . sort , ds . to_ldif . grep ( /^dn:\s */ ) { $'. chomp } )
7884 end
85+
86+ def test_to_ldif_with_version
87+ ds = Net ::LDAP ::Dataset . new
88+ ds . version = "1"
89+
90+ assert_equal "version: 1" , ds . to_ldif_string . chomp
91+ end
7992end
You can’t perform that action at this time.
0 commit comments