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.
Class Method Summary collapse
-
.resolver_files(ip, port, tlds) {|filename, content| ... } ⇒ Object
Generate the resolved config.
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 |
Class Method Details
.resolver_files(ip, port, tlds) {|filename, content| ... } ⇒ Object
Generate the resolved config.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vagrant-dns/installers/mac.rb', line 19 def self.resolver_files(ip, port, tlds) tlds.each do |tld| contents = "# This file is generated by vagrant-dns\n" \ "nameserver #{ip}\n" \ "port #{port}" yield tld, contents end end |
Instance Method Details
#exec(*commands) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vagrant-dns/installers/mac.rb', line 63 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
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vagrant-dns/installers/mac.rb', line 30 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
53 54 55 56 57 |
# File 'lib/vagrant-dns/installers/mac.rb', line 53 def purge! require 'fileutils' uninstall! FileUtils.rm_r(tmp_path) end |
#registered_resolvers ⇒ Object
59 60 61 |
# File 'lib/vagrant-dns/installers/mac.rb', line 59 def registered_resolvers Dir[File.join(tmp_path, "resolver", "*")] end |
#uninstall! ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/vagrant-dns/installers/mac.rb', line 44 def uninstall! commands = registered_resolvers.map do |r| installed_resolver = File.join(install_path, File.basename(r)) ['rm', '-rf', installed_resolver] end exec(*commands) end |