Class: Gbwd::Commands
- Inherits:
-
Object
- Object
- Gbwd::Commands
- Defined in:
- lib/gbwd/commands.rb
Instance Method Summary collapse
- #add(options = {}) ⇒ Object
- #disable(options = {}) ⇒ Object
- #enable(options = {}) ⇒ Object
-
#initialize ⇒ Commands
constructor
A new instance of Commands.
- #list(options = {}) ⇒ Object
- #remove(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Commands
Returns a new instance of Commands.
5 6 7 8 |
# File 'lib/gbwd/commands.rb', line 5 def initialize @hosts_file_path = '/etc/hosts' @ip_address = '69.55.54.215' end |
Instance Method Details
#add(options = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/gbwd/commands.rb', line 10 def add( = {}) modify() do |domains, domain| domains << [ip_address, domain].join(' ') "You added #{domain}." end end |
#disable(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/gbwd/commands.rb', line 35 def disable( = {}) modify() do |domains, domain| domains.map! do |line| "#" + line end "All domains have been disabled." end end |
#enable(options = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/gbwd/commands.rb', line 26 def enable( = {}) modify() do |domains, domain| domains.map! do |line| line[1..-1] if line.start_with?('#') end "All domains have been enabled." end end |
#list(options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gbwd/commands.rb', line 44 def list( = {}) install unless installed? domains = get_domains_from_file if domains.size == 0 [ "You do not have any blocked domains. You can add one by using the add command.", " ex. ~ sudo gbwd add -d www.youtube.com" ].join("\n") else domains = domains.map do |line| line.split(' ')[1] end "The following domains are currenlty being blocked:\n" + domains.join("\n") end end |
#remove(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/gbwd/commands.rb', line 17 def remove( = {}) modify() do |domains, domain| domains.select! do |domain_to_check| (Regexp.new(domain) =~ domain_to_check).nil? end "You removed #{domain}." end end |