blocklist 0.1.3 → 0.1.4
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 +2 -2
- data/lib/blocklist/cli.rb +6 -3
- data/spec/blocklist/cli_spec.rb +17 -5
- metadata +2 -2
data/blocklist.gemspec
CHANGED
|
@@ -3,8 +3,8 @@ 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.
|
|
7
|
-
s.date = '2009-09-
|
|
6
|
+
s.version = '0.1.4'
|
|
7
|
+
s.date = '2009-09-18'
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
9
|
s.authors = ["Wes Oldenbeuving"]
|
|
10
10
|
s.email = "narnach@gmail.com"
|
data/lib/blocklist/cli.rb
CHANGED
|
@@ -27,6 +27,7 @@ class Blocklist
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def add
|
|
30
|
+
auto_add = @argv.delete('-a')
|
|
30
31
|
block_name = @argv.shift
|
|
31
32
|
unless block = @bl.block(block_name)
|
|
32
33
|
block = Blocklist::Block.new(block_name)
|
|
@@ -46,7 +47,9 @@ class Blocklist
|
|
|
46
47
|
dom_no_tld = dom_segments[0...-tld_size]
|
|
47
48
|
domain_base = dom_no_tld.last
|
|
48
49
|
subdomain = dom_no_tld.size == 1 ? nil : dom_no_tld[0...-1].join(".")
|
|
49
|
-
|
|
50
|
+
subdomains_to_add = [subdomain]
|
|
51
|
+
subdomains_to_add += [nil, 'www'] if auto_add
|
|
52
|
+
new_domains = subdomains_to_add.uniq.map {|sub| [sub, domain_base, tld].compact.join(".")} - domains
|
|
50
53
|
if new_domains.size > 0
|
|
51
54
|
new_line = Blocklist::Line.new('127.0.0.1', *new_domains)
|
|
52
55
|
new_line.commented = comment_new_lines
|
|
@@ -85,10 +88,10 @@ Flags:
|
|
|
85
88
|
Quiet mode. Minimizes the output to STDOUT
|
|
86
89
|
|
|
87
90
|
Commands:
|
|
88
|
-
add <block name> [domain1] .. [domainN]
|
|
91
|
+
add [-a] <block name> [domain1] .. [domainN]
|
|
89
92
|
Add a number of domains to the specified block.
|
|
90
|
-
Each domain will automatically be added with the www subdomain and without subdomain.
|
|
91
93
|
Duplicate domains are skipped.
|
|
94
|
+
When -a is given, the base domain and www-subdomain for each domain wil automatically be added.
|
|
92
95
|
list
|
|
93
96
|
Shows a list of all blocks currently defined
|
|
94
97
|
toggle <block name>
|
data/spec/blocklist/cli_spec.rb
CHANGED
|
@@ -20,8 +20,9 @@ describe Blocklist::Cli do
|
|
|
20
20
|
File.open('/etc/hosts','w') {|f| f.puts content}
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def run(cmd)
|
|
23
|
+
def run(cmd, silent=true)
|
|
24
24
|
cli = Blocklist::Cli.new(cmd.split(" "))
|
|
25
|
+
cli.stub!(:puts) if silent
|
|
25
26
|
cli.run
|
|
26
27
|
cli
|
|
27
28
|
end
|
|
@@ -47,14 +48,25 @@ describe Blocklist::Cli do
|
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
describe 'add' do
|
|
50
|
-
it "should add
|
|
51
|
+
it "should add the chosen subdomain to a block's lines" do
|
|
51
52
|
fake_hosts <<-STR
|
|
52
53
|
# localhost
|
|
53
54
|
STR
|
|
54
55
|
run 'add localhost example.org'
|
|
55
56
|
File.read('/etc/hosts').should == <<-STR
|
|
56
57
|
# localhost
|
|
57
|
-
127.0.0.1 example.org
|
|
58
|
+
127.0.0.1 example.org
|
|
59
|
+
STR
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "should add the chosen subdomain, the domain and the www-subdomain to a block's lines when -a is given" do
|
|
63
|
+
fake_hosts <<-STR
|
|
64
|
+
# localhost
|
|
65
|
+
STR
|
|
66
|
+
run 'add -a localhost news.example.org'
|
|
67
|
+
File.read('/etc/hosts').should == <<-STR
|
|
68
|
+
# localhost
|
|
69
|
+
127.0.0.1 news.example.org example.org www.example.org
|
|
58
70
|
STR
|
|
59
71
|
end
|
|
60
72
|
|
|
@@ -69,7 +81,7 @@ describe Blocklist::Cli do
|
|
|
69
81
|
127.0.0.1 localhost
|
|
70
82
|
|
|
71
83
|
# example
|
|
72
|
-
127.0.0.1 example.org
|
|
84
|
+
127.0.0.1 example.org
|
|
73
85
|
STR
|
|
74
86
|
end
|
|
75
87
|
|
|
@@ -83,7 +95,7 @@ describe Blocklist::Cli do
|
|
|
83
95
|
File.read('/etc/hosts').should == <<-STR
|
|
84
96
|
# localhost
|
|
85
97
|
# 127.0.0.1 localhost
|
|
86
|
-
# 127.0.0.1 example.org
|
|
98
|
+
# 127.0.0.1 example.org
|
|
87
99
|
STR
|
|
88
100
|
end
|
|
89
101
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: blocklist
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wes Oldenbeuving
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-09-
|
|
12
|
+
date: 2009-09-18 00:00:00 +02:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|