Class: Landrush::ResolverConfig
- Inherits:
-
Object
- Object
- Landrush::ResolverConfig
- Defined in:
- lib/landrush/resolver_config.rb
Class Attribute Summary collapse
Instance Method Summary collapse
- #config_dir ⇒ Object
- #config_file ⇒ Object
- #contents_match? ⇒ Boolean
- #desired_contents ⇒ Object
- #ensure_config_exists! ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(env = {}) ⇒ ResolverConfig
constructor
A new instance of ResolverConfig.
- #osx? ⇒ Boolean
- #sudo ⇒ Object
- #write_config! ⇒ Object
Constructor Details
#initialize(env = {}) ⇒ ResolverConfig
Returns a new instance of ResolverConfig.
17 18 19 |
# File 'lib/landrush/resolver_config.rb', line 17 def initialize(env={}) @env = env end |
Class Attribute Details
.config_dir ⇒ Object
13 14 15 |
# File 'lib/landrush/resolver_config.rb', line 13 def self.config_dir @config_dir ||= Pathname('/etc/resolver') end |
.sudo ⇒ Object
9 10 11 |
# File 'lib/landrush/resolver_config.rb', line 9 def self.sudo @sudo ||= 'sudo' end |
Instance Method Details
#config_dir ⇒ Object
36 37 38 |
# File 'lib/landrush/resolver_config.rb', line 36 def config_dir self.class.config_dir end |
#config_file ⇒ Object
40 41 42 |
# File 'lib/landrush/resolver_config.rb', line 40 def config_file config_dir.join(@env[:machine].config.landrush.tld) end |
#contents_match? ⇒ Boolean
44 45 46 |
# File 'lib/landrush/resolver_config.rb', line 44 def contents_match? config_file.exist? && File.read(config_file) == desired_contents end |
#desired_contents ⇒ Object
25 26 27 28 29 30 |
# File 'lib/landrush/resolver_config.rb', line 25 def desired_contents; <<-EOS.gsub(/^ /, '') # Generated by landrush, a vagrant plugin nameserver 127.0.0.1 port #{Server.port} EOS end |
#ensure_config_exists! ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/landrush/resolver_config.rb', line 59 def ensure_config_exists! if contents_match? info "Host DNS resolver config looks good." else info "Need to configure the host." write_config! end end |
#info(msg) ⇒ Object
21 22 23 |
# File 'lib/landrush/resolver_config.rb', line 21 def info(msg) @env[:ui].info("[landrush] #{msg}") end |
#osx? ⇒ Boolean
32 33 34 |
# File 'lib/landrush/resolver_config.rb', line 32 def osx? `uname`.chomp == 'Darwin' end |
#sudo ⇒ Object
68 69 70 |
# File 'lib/landrush/resolver_config.rb', line 68 def sudo self.class.sudo end |
#write_config! ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/landrush/resolver_config.rb', line 48 def write_config! info "Momentarily using sudo to put the host config in place..." system "#{self.class.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 |