Class: Pebbles::Productivity10x::SwitchHosts
- Inherits:
-
Object
- Object
- Pebbles::Productivity10x::SwitchHosts
- Defined in:
- lib/pebbles-productivity10x-switch_hosts.rb,
lib/pebbles-productivity10x-switch_hosts/version.rb
Defined Under Namespace
Modules: Default
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Method Summary collapse
- #allow ⇒ Object
- #deny ⇒ Object
- #deny_file ⇒ Object
- #hosts_file ⇒ Object
-
#initialize(opt = {}) ⇒ SwitchHosts
constructor
A new instance of SwitchHosts.
- #original_file ⇒ Object
Constructor Details
#initialize(opt = {}) ⇒ SwitchHosts
Returns a new instance of SwitchHosts.
32 33 34 35 36 37 |
# File 'lib/pebbles-productivity10x-switch_hosts.rb', line 32 def initialize opt = {} @hosts_path = opt[:hosts_path] || Default::HOSTS_PATH @original_extname = opt[:original_extname] || Default::ORIGINAL_EXTNAME @deny_extname = opt[:deny_extname] || Default::DENY_EXTNAME @template = opt[:template] || Default::TEMPLATE end |
Instance Method Details
#allow ⇒ Object
43 44 45 |
# File 'lib/pebbles-productivity10x-switch_hosts.rb', line 43 def allow use(original_file) end |
#deny ⇒ Object
39 40 41 |
# File 'lib/pebbles-productivity10x-switch_hosts.rb', line 39 def deny use(deny_file) end |
#deny_file ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pebbles-productivity10x-switch_hosts.rb', line 59 def deny_file deny_path = @hosts_path + @deny_extname unless File.exist?(deny_path) FileUtils.cp original_file, deny_path, preserve: true File.open(deny_path, 'a') do |f| f << "\n" f << Default::DENY_HOSTS.map { |host| @template.result(binding) }.join end end File.new deny_path end |
#hosts_file ⇒ Object
47 48 49 |
# File 'lib/pebbles-productivity10x-switch_hosts.rb', line 47 def hosts_file File.new(@hosts_path) end |
#original_file ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/pebbles-productivity10x-switch_hosts.rb', line 51 def original_file original_path = @hosts_path + @original_extname unless File.exist?(original_path) FileUtils.cp(hosts_file, original_path, preserve: true) end File.new original_path end |