blocklist 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.3'
7
- s.date = '2009-09-16'
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"
@@ -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
- new_domains = [nil, 'www', subdomain].uniq.map {|sub| [sub, domain_base, tld].compact.join(".")} - domains
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>
@@ -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 a domain and its www-subdomain to a block's lines" do
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 www.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 www.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 www.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.3
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-16 00:00:00 +02:00
12
+ date: 2009-09-18 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15