Class: Landrush::ResolverConfig
- Inherits:
-
Object
- Object
- Landrush::ResolverConfig
- Defined in:
- lib/landrush/resolver_config.rb
Class Method Summary collapse
- .config_dir ⇒ Object
- .config_file ⇒ Object
- .contents_match? ⇒ Boolean
- .desired_contents ⇒ Object
- .ensure_config_exists(opts = {}) ⇒ Object
- .osx? ⇒ Boolean
- .puts(str) ⇒ Object
- .write_config(opts) ⇒ Object
Class Method Details
.config_dir ⇒ Object
16 17 18 |
# File 'lib/landrush/resolver_config.rb', line 16 def self.config_dir @config_dir ||= Pathname('/etc/resolver') end |
.config_file ⇒ Object
20 21 22 |
# File 'lib/landrush/resolver_config.rb', line 20 def self.config_file config_dir.join('vagrant.dev') end |
.contents_match? ⇒ Boolean
24 25 26 |
# File 'lib/landrush/resolver_config.rb', line 24 def self.contents_match? config_file.exist? && File.read(config_file) == desired_contents end |
.desired_contents ⇒ Object
5 6 7 8 9 10 |
# File 'lib/landrush/resolver_config.rb', line 5 def self.desired_contents; <<-EOS.gsub(/^ /, '') # Generated by landrush, a vagrant plugin nameserver 127.0.0.1 port 10053 EOS end |
.ensure_config_exists(opts = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/landrush/resolver_config.rb', line 40 def self.ensure_config_exists(opts={}) unless osx? puts "Not an OSX machine, so skipping host DNS resolver config." return end if contents_match? puts "Host DNS resolver config looks good." else puts "Need to configure the host." write_config(opts) end end |
.osx? ⇒ Boolean
12 13 14 |
# File 'lib/landrush/resolver_config.rb', line 12 def self.osx? `uname`.chomp == 'Darwin' end |
.puts(str) ⇒ Object
54 55 56 |
# File 'lib/landrush/resolver_config.rb', line 54 def self.puts(str) Kernel.puts("[landrush] #{str}") end |
.write_config(opts) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/landrush/resolver_config.rb', line 28 def self.write_config(opts) puts "Mometarily using sudo to put the host config in place..." sudo = opts.fetch(:sudo, 'sudo') system "#{sudo} mkdir #{config_dir}" unless config_dir.directory? Tempfile.open('vagrant_landrush_host_config') do |f| f.write(desired_contents) f.close system "#{sudo} cp #{f.path} #{config_file}" system "#{sudo} chmod 644 #{config_file}" end end |