Class: Blockr::Manager
- Inherits:
-
Object
- Object
- Blockr::Manager
- Defined in:
- lib/blockr/manager.rb
Constant Summary collapse
- HOSTS_FILE =
"/etc/hosts"
- KEY_STATUS =
"status"
- KEY_NON_BLOCKR_LINES =
"non_blockr_lines"
- KEY_BLOCKR_HOSTNAMES =
"blocked_hostnames"
- FILE_EDITED_BY_BLOCKR_HEADER =
"# NOTE: following entries were added by blockr, please DON'T manually edit this or any of the following lines ; "
- ACTIVATED =
"activated"
- DEACTIVATED =
"deactivated"
- LINE_EDITED_BY_BLOCKR =
"# XXX: added by blockr ;"
- DISABLED_BLOCKR_LINE_PREFIX =
"# "
- DUMMY_IP =
"127.0.0.1"
Instance Attribute Summary collapse
-
#parsed_data ⇒ Object
readonly
for testing.
Instance Method Summary collapse
- #activate ⇒ Object
- #block(hostnames) ⇒ Object
- #deactivate ⇒ Object
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #unblock(hostnames) ⇒ Object
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
25 26 27 |
# File 'lib/blockr/manager.rb', line 25 def initialize @parsed_data = parse_file(HOSTS_FILE) end |
Instance Attribute Details
#parsed_data ⇒ Object (readonly)
for testing
23 24 25 |
# File 'lib/blockr/manager.rb', line 23 def parsed_data @parsed_data end |
Instance Method Details
#activate ⇒ Object
45 46 47 48 |
# File 'lib/blockr/manager.rb', line 45 def activate() enable() serialize() end |
#block(hostnames) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/blockr/manager.rb', line 29 def block(hostnames) return if blank?(hostnames) hostnames.each do |h| @parsed_data[KEY_BLOCKR_HOSTNAMES].push(h) if !blank?(h) end serialize() end |
#deactivate ⇒ Object
50 51 52 53 |
# File 'lib/blockr/manager.rb', line 50 def deactivate() disable() serialize() end |
#unblock(hostnames) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/blockr/manager.rb', line 38 def unblock(hostnames) return if blank?(hostnames) @parsed_data[KEY_BLOCKR_HOSTNAMES].reject! { |h| hostnames.include?(h)} serialize() end |