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 4
4
# to and from LDIF strings and Net::LDAP::Entry objects.
5
5
class Net ::LDAP ::Dataset < Hash
6
6
##
7
- # Dataset object comments.
8
- attr_reader :comments
7
+ # Dataset object version, comments.
8
+ attr_accessor :version
9
+ attr_reader :comments
9
10
10
11
def initialize ( *args , &block ) # :nodoc:
11
12
super
13
+ @version = nil
12
14
@comments = [ ]
13
15
end
14
16
@@ -17,6 +19,12 @@ def initialize(*args, &block) # :nodoc:
17
19
# entries.
18
20
def to_ldif
19
21
ary = [ ]
22
+
23
+ if version
24
+ ary << "version: #{ version } "
25
+ ary << ""
26
+ end
27
+
20
28
ary += @comments unless @comments . empty?
21
29
keys . sort . each do |dn |
22
30
ary << "dn: #{ dn } "
@@ -125,6 +133,9 @@ def read_ldif(io)
125
133
if line =~ /^#/
126
134
ds . comments << line
127
135
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?
128
139
elsif line =~ /^dn:[\s ]*/i
129
140
dn = $'
130
141
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
13
13
assert_equal ( true , ds . empty? )
14
14
end
15
15
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
+
16
22
def test_ldif_with_comments
17
23
str = [ "# Hello from LDIF-land" , "# This is an unterminated comment" ]
18
24
io = StringIO . new ( str [ 0 ] + "\r \n " + str [ 1 ] )
@@ -76,4 +82,11 @@ def test_to_ldif
76
82
assert_equal ( entries . size , ds . size )
77
83
assert_equal ( entries . sort , ds . to_ldif . grep ( /^dn:\s */ ) { $'. chomp } )
78
84
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
79
92
end
You can’t perform that action at this time.
0 commit comments