Class: VagrantDNS::Installers::Mac

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-dns/installers/mac.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tmp_path, install_path = "/etc/resolver") ⇒ Mac

Returns a new instance of Mac.



6
7
8
# File 'lib/vagrant-dns/installers/mac.rb', line 6

def initialize(tmp_path, install_path = "/etc/resolver")
  self.tmp_path, self.install_path = tmp_path, install_path
end

Instance Attribute Details

#install_pathObject

Returns the value of attribute install_path.



4
5
6
# File 'lib/vagrant-dns/installers/mac.rb', line 4

def install_path
  @install_path
end

#tmp_pathObject

Returns the value of attribute tmp_path.



4
5
6
# File 'lib/vagrant-dns/installers/mac.rb', line 4

def tmp_path
  @tmp_path
end

Instance Method Details

#install!Object



10
11
12
13
14
15
16
17
18
# File 'lib/vagrant-dns/installers/mac.rb', line 10

def install!
  require 'fileutils'

  command = "mkdir -p #{install_path}\n"
  registered_resolvers.each do |resolver|
    command += "ln -sf #{resolver} #{install_path}\n"
  end
  `osascript -e 'do shell script \"#{command}\" with administrator privileges'`
end

#registered_resolversObject



31
32
33
# File 'lib/vagrant-dns/installers/mac.rb', line 31

def registered_resolvers
  Dir[File.join(tmp_path, "resolver", "*")]
end

#uninstall!Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-dns/installers/mac.rb', line 20

def uninstall!
  require 'fileutils'

  command = ""
  registered_resolvers.each do |r|
    installed_resolver = File.join(install_path, File.basename(r))
    command += "rm -rf #{installed_resolver}\n"
  end
  `osascript -e 'do shell script \"#{command}\" with administrator privileges'`
end