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 CHANGED
@@ -1,3 +1,7 @@
1
+ 0.5.0 (2011-02.20)
2
+
3
+ * Updater: the special :remove! value and other fixes
4
+
1
5
  0.4.1 (2011-02-20)
2
6
 
3
7
  * filtergroup: default value for :weightedphrasemode
@@ -5,7 +5,7 @@ autoload :Set, 'set'
5
5
  require 'configfiles'
6
6
 
7
7
  module DansGuardian
8
- VERSION = '0.4.1'
8
+ VERSION = '0.5.0'
9
9
 
10
10
  autoload :Config, 'dansguardian/config'
11
11
  autoload :Parser, 'dansguardian/parser'
@@ -60,7 +60,7 @@ module DansGuardian
60
60
 
61
61
  # may override the main config file
62
62
  parameter :weightedphrasemode,
63
- '0' => false,
63
+ '0' => :disabled,
64
64
  '1' => :normal,
65
65
  '2' => :singular
66
66
  default :weightedphrasemode, :inherit
@@ -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
- yield "#{key} = #{new_value}"
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} :"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
8
- - 1
9
- version: 0.4.1
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Guido De Rosa