Narnach-blocklist 0.1.2 → 0.1.3
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/blocklist.gemspec +1 -1
- data/lib/blocklist/cli.rb +7 -2
- data/spec/blocklist/cli_spec.rb +22 -4
- metadata +1 -1
data/blocklist.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.name = 'blocklist'
|
4
4
|
s.summary = "Blocklist manages /etc/hosts"
|
5
5
|
s.description = "Blocklist manages /etc/hosts with the goal of routing distracting websites to localhost. It also works well as an ad blocker."
|
6
|
-
s.version = '0.1.
|
6
|
+
s.version = '0.1.3'
|
7
7
|
s.date = '2009-09-16'
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Wes Oldenbeuving"]
|
data/lib/blocklist/cli.rb
CHANGED
@@ -32,7 +32,10 @@ class Blocklist
|
|
32
32
|
block = Blocklist::Block.new(block_name)
|
33
33
|
@bl.blocks << block
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
|
+
commented_lines = block.lines.inject(0) {|sum, line| line.commented ? sum + 1 : sum}
|
37
|
+
uncommented_lines = block.lines.size - commented_lines
|
38
|
+
comment_new_lines = commented_lines > uncommented_lines
|
36
39
|
|
37
40
|
domains = block.lines.map {|line| line.domains}.flatten
|
38
41
|
saved_domains = @argv.map do |domain|
|
@@ -45,7 +48,9 @@ class Blocklist
|
|
45
48
|
subdomain = dom_no_tld.size == 1 ? nil : dom_no_tld[0...-1].join(".")
|
46
49
|
new_domains = [nil, 'www', subdomain].uniq.map {|sub| [sub, domain_base, tld].compact.join(".")} - domains
|
47
50
|
if new_domains.size > 0
|
48
|
-
|
51
|
+
new_line = Blocklist::Line.new('127.0.0.1', *new_domains)
|
52
|
+
new_line.commented = comment_new_lines
|
53
|
+
block.lines << new_line
|
49
54
|
domains.concat(new_domains)
|
50
55
|
end
|
51
56
|
new_domains
|
data/spec/blocklist/cli_spec.rb
CHANGED
@@ -19,6 +19,12 @@ describe Blocklist::Cli do
|
|
19
19
|
def fake_hosts(content='')
|
20
20
|
File.open('/etc/hosts','w') {|f| f.puts content}
|
21
21
|
end
|
22
|
+
|
23
|
+
def run(cmd)
|
24
|
+
cli = Blocklist::Cli.new(cmd.split(" "))
|
25
|
+
cli.run
|
26
|
+
cli
|
27
|
+
end
|
22
28
|
|
23
29
|
it 'should display help when no command is given' do
|
24
30
|
fake_hosts
|
@@ -45,8 +51,7 @@ describe Blocklist::Cli do
|
|
45
51
|
fake_hosts <<-STR
|
46
52
|
# localhost
|
47
53
|
STR
|
48
|
-
|
49
|
-
cli.run
|
54
|
+
run 'add localhost example.org'
|
50
55
|
File.read('/etc/hosts').should == <<-STR
|
51
56
|
# localhost
|
52
57
|
127.0.0.1 example.org www.example.org
|
@@ -58,8 +63,7 @@ describe Blocklist::Cli do
|
|
58
63
|
# localhost
|
59
64
|
127.0.0.1 localhost
|
60
65
|
STR
|
61
|
-
|
62
|
-
cli.run
|
66
|
+
run 'add example example.org'
|
63
67
|
File.read('/etc/hosts').should == <<-STR
|
64
68
|
# localhost
|
65
69
|
127.0.0.1 localhost
|
@@ -68,5 +72,19 @@ describe Blocklist::Cli do
|
|
68
72
|
127.0.0.1 example.org www.example.org
|
69
73
|
STR
|
70
74
|
end
|
75
|
+
|
76
|
+
|
77
|
+
it 'should add a domain commented-out if there are more commented-out domains in the block' do
|
78
|
+
fake_hosts <<-STR
|
79
|
+
# localhost
|
80
|
+
# 127.0.0.1 localhost
|
81
|
+
STR
|
82
|
+
run 'add localhost example.org'
|
83
|
+
File.read('/etc/hosts').should == <<-STR
|
84
|
+
# localhost
|
85
|
+
# 127.0.0.1 localhost
|
86
|
+
# 127.0.0.1 example.org www.example.org
|
87
|
+
STR
|
88
|
+
end
|
71
89
|
end
|
72
90
|
end
|