blockhosts 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3410bf876c4374350ebfe70a76a7f88d3e7575017972acf8843f08d9c3c85488
4
+ data.tar.gz: 73e2f8780d1c634f961a1940c0709f30d7e198e28d6069b76e28984229ffe1ed
5
+ SHA512:
6
+ metadata.gz: 4aa7d87eee37c39784fa31444300016e8fb16f0455cdcd4fa5ee361bc30f8ceea5e6c405af55f1b9b4a4f8d6b8e43f4e7a93e6fa2b7b5205b1bc3295635aaf26
7
+ data.tar.gz: 9ef3feafd803acee6a6cab23efd18eeb776277740c2e55dbb9d59b00b2fb80015a172a4d5125213ed89a4d8c76d38359958490b3397f0d7cca5e2f646074e8e6
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/lib/blockhosts.rb ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: blockhosts.rb
4
+
5
+
6
+ class Host
7
+
8
+ @ip = '127.0.0.1'
9
+
10
+ @file = case RUBY_PLATFORM
11
+ when /linux|darwin/
12
+ '/etc/hosts'
13
+ when /cygwin|mswin|mingw|bccwin|wince|emx/
14
+ 'c:\windows\system32\drivers\etc\hosts'
15
+ else
16
+ '/etc/hosts'
17
+ end
18
+
19
+ def self.add(hostname)
20
+ s = "#{@ip} #{hostname}"
21
+ open(@file, 'a') { |f| f.puts s } unless File.read(@file).include? hostname
22
+ end
23
+
24
+ def self.disable(hostname)
25
+ modify() {|s| s.sub(/^#(#{@ip}\s+#{hostname}[^$]+)$/,'\1')}
26
+ end
27
+
28
+ def self.enable(hostname)
29
+ modify() {|s| s.sub(/^(#{@ip}\s+#{hostname}[^$]+)$/,'#\1')}
30
+ end
31
+
32
+ def self.modify()
33
+
34
+ return unless block_given?
35
+
36
+ s = File.read(@file)
37
+ s2 = yield(s)
38
+ File.write(@file, s2) unless s == s2
39
+
40
+ end
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blockhosts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgxMDIwMjAzOTE4WhcN
15
+ MTkxMDIwMjAzOTE4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC58Ym8
17
+ RHuJe187YQNiIa/YJMwxgzHi2AwnPwocsDC0FZZQopn9HnXPhnIMeL0CzpWpgwxM
18
+ xdPfhKHOfbxt6DuIfZObpDkFQPokpW7CbwtpzJemFQPtDA68euHhzMVUJZUReCvu
19
+ xyQO7sal2jmHCzZ78WjC84A447Y8BfF3vQ9Av/KpNGxXOtl8S+DygdLvQX2Wah3E
20
+ 3WSS2/+gwE3f21WFaJotQJINN51+lNaJOq2cHMeQjTz/yw6h+bgNUruRHig4f8gh
21
+ zoHWd8aBRYpB51e3uedrE3MXNbjLwdtiAkg4tipaARyaReZZMyH/EqqgISn5GQJL
22
+ d6u08PKEwMFk5hKnAGr3EqZ6+LkYt//m4HTSwFDDeC/PsEZQKCDj0tQbQo8M2dgz
23
+ CdytZ4Ixa3t84iS/rRs0R7dLLwf72V1mzJl767qLdBbEKlLoX1U3CiSXSk/9jBvB
24
+ OLYByukrCvhQitRbbl8Af62M7XdDUieKHw5lGVdaJVv8lbp+EBKr6V5tGN8CAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU0mJ2OywN
26
+ BPPaw+tlm1BDY4tPf+0wJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAi5HyYuDmxQLSXqYGaOiTYltry9CfakJyDIvheSMC
29
+ aqoIHC1hWkrWNTQvzT8WiuzlaaaA243QmL23EeJ1V/M8gRyT8Rxc1LYfOs/krT2t
30
+ Wx5c0aZeEkuz37p2ldgTcOWWODIc2Oc3Y//QT2LLQfZEOe+QgRl1AJQlbVIbS7Tr
31
+ lHH9yHHwYkrz7q20VyHRR+Y5TDSBNxmIMjL2Zt41B18U1jcB+vyTRuuMxrjz/TLk
32
+ hOFO9WbJk+PKd9/HkoZi34hQUkt3KG0nv8vAcOXcKG/33wsJxcSKe6T3unOu2eZV
33
+ FJs2cmEacTfjSAGBjDM/DIv6Y+VvO/sPmQhkJ1wfVXyHzEHK02zrJpoipcTDyv97
34
+ TmT/pFDwLFQUQmSJMYbOK8VGdgX6zMgZBqe1c27dDqvwVLuzzTVhXEn9tkukEOCt
35
+ 7vecf9qfrpZt4fjOajWBWWZEUQ3QKHva1uNegE75UqN77YfewLL+A+SrV0ORhL9q
36
+ /sJ0X03RC0pDp5fyhHmUoTyT
37
+ -----END CERTIFICATE-----
38
+ date: 2018-10-20 00:00:00.000000000 Z
39
+ dependencies: []
40
+ description:
41
+ email: james@jamesrobertson.eu
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - lib/blockhosts.rb
47
+ homepage: https://github.com/jrobertson/blockhosts
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.7.6
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Conveniently enables or disables the blocking of hostnames in the /etc/hosts
71
+ file e.g. 127.0.0.1 facebook.com
72
+ test_files: []
metadata.gz.sig ADDED
Binary file