dansguardian 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changelog +4 -0
- data/lib/dansguardian.rb +1 -1
- data/lib/dansguardian/config/filtergroup.rb +1 -1
- data/lib/dansguardian/updater.rb +14 -1
- metadata +3 -3
data/Changelog
CHANGED
data/lib/dansguardian.rb
CHANGED
data/lib/dansguardian/updater.rb
CHANGED
@@ -4,6 +4,9 @@ autoload :FileUtils, 'fileutils'
|
|
4
4
|
module DansGuardian
|
5
5
|
module Updater
|
6
6
|
|
7
|
+
# Update the configuration file +file+ with the +data+ Hash,
|
8
|
+
# preserving the origin file layout, including comments.
|
9
|
+
# The spacial value +:remove!+ comments out the 'key = ...' line.
|
7
10
|
def self.update!(file, data)
|
8
11
|
tmp = Tempfile.new 'ruby_dansguardian_updater'
|
9
12
|
update file, data do |line|
|
@@ -14,6 +17,8 @@ module DansGuardian
|
|
14
17
|
tmp.unlink
|
15
18
|
end
|
16
19
|
|
20
|
+
# Like update! but also accept IO objects and yields updated lines
|
21
|
+
# instead of actually writing to a file.
|
17
22
|
def self.update(io_or_file, data)
|
18
23
|
if io_or_file.is_a? IO
|
19
24
|
io = io_or_file
|
@@ -50,7 +55,11 @@ module DansGuardian
|
|
50
55
|
yield "#{key} = #{val}"
|
51
56
|
end
|
52
57
|
else
|
53
|
-
|
58
|
+
if new_value == :remove!
|
59
|
+
yield "# #{line}"
|
60
|
+
else
|
61
|
+
yield "#{key} = #{new_value}"
|
62
|
+
end
|
54
63
|
end
|
55
64
|
already_written << key
|
56
65
|
# next # "optimized out"
|
@@ -62,6 +71,10 @@ module DansGuardian
|
|
62
71
|
|
63
72
|
to_be_written =
|
64
73
|
data.keys.map{|k| k.to_sym} - already_written.map{|k| k.to_sym}
|
74
|
+
to_be_written.select!{|k| data[k.to_s] || data[k.to_sym]} # reject nil values
|
75
|
+
to_be_written.reject! do |k|
|
76
|
+
(data[k.to_s] || data[k.to_sym]) == :remove!
|
77
|
+
end
|
65
78
|
if to_be_written.length > 0
|
66
79
|
yield ""
|
67
80
|
yield "# Added by ::#{self} :"
|