Class: VagrantDNS::Installers::Mac
- Inherits:
-
Object
- Object
- VagrantDNS::Installers::Mac
- Defined in:
- lib/vagrant-dns/installers/mac.rb
Constant Summary collapse
- EXEC_STYLES =
%i{osa sudo}
Instance Attribute Summary collapse
-
#exec_style ⇒ Object
Returns the value of attribute exec_style.
-
#install_path ⇒ Object
Returns the value of attribute install_path.
-
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
Instance Method Summary collapse
- #exec(*commands) ⇒ Object
-
#initialize(tmp_path, options = {}) ⇒ Mac
constructor
A new instance of Mac.
- #install! ⇒ Object
- #purge! ⇒ Object
- #registered_resolvers ⇒ Object
- #uninstall! ⇒ Object
Constructor Details
#initialize(tmp_path, options = {}) ⇒ Mac
Returns a new instance of Mac.
8 9 10 11 12 |
# File 'lib/vagrant-dns/installers/mac.rb', line 8 def initialize(tmp_path, = {}) self.tmp_path = tmp_path self.install_path = .fetch(:install_path, "/etc/resolver") self.exec_style = .fetch(:exec_style, :osa) end |
Instance Attribute Details
#exec_style ⇒ Object
Returns the value of attribute exec_style.
6 7 8 |
# File 'lib/vagrant-dns/installers/mac.rb', line 6 def exec_style @exec_style end |
#install_path ⇒ Object
Returns the value of attribute install_path.
6 7 8 |
# File 'lib/vagrant-dns/installers/mac.rb', line 6 def install_path @install_path end |
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
6 7 8 |
# File 'lib/vagrant-dns/installers/mac.rb', line 6 def tmp_path @tmp_path end |
Instance Method Details
#exec(*commands) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vagrant-dns/installers/mac.rb', line 49 def exec(*commands) return if !commands || commands.empty? case exec_style when :osa cmd_script = commands.map {|line| line.join ' ' }.join($/) system 'osascript', '-e', "do shell script \"#{cmd_script}\" with administrator privileges" when :sudo commands.each do |c| system 'sudo', *c end else raise ArgumentError, "Unsupported execution style: #{exec_style}. Use one of #{EXEC_STYLES.map(&:inspect).join(' ')}" end end |
#install! ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vagrant-dns/installers/mac.rb', line 14 def install! require 'fileutils' commands = [ ['mkdir', '-p', install_path] ] commands += registered_resolvers.map do |resolver| ['ln', '-sf', resolver.shellescape, install_path.shellescape] end exec(*commands) end |
#purge! ⇒ Object
39 40 41 42 43 |
# File 'lib/vagrant-dns/installers/mac.rb', line 39 def purge! require 'fileutils' uninstall! FileUtils.rm_r(tmp_path) end |
#registered_resolvers ⇒ Object
45 46 47 |
# File 'lib/vagrant-dns/installers/mac.rb', line 45 def registered_resolvers Dir[File.join(tmp_path, "resolver", "*")] end |
#uninstall! ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vagrant-dns/installers/mac.rb', line 28 def uninstall! require 'fileutils' commands = registered_resolvers.map do |r| installed_resolver = File.join(install_path, File.basename(r)) ['rm', '-rf', installed_resolver] end exec(*commands) end |