Class: Masquito::Resolver
- Inherits:
-
Object
- Object
- Masquito::Resolver
- Defined in:
- lib/masquito/resolver.rb
Constant Summary collapse
- RESOLVER_TEMPLATE_PATH =
File.join(GEM_PATH, 'config', 'masquito.erb')
- RESOLVERS_PATH =
Pathname.new('/etc/resolver')
Instance Method Summary collapse
- #copy_configs ⇒ Object
-
#initialize(config_path) ⇒ Resolver
constructor
A new instance of Resolver.
- #remove_configs ⇒ Object
- #reset ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(config_path) ⇒ Resolver
Returns a new instance of Resolver.
8 9 10 |
# File 'lib/masquito/resolver.rb', line 8 def initialize(config_path) @config_path = config_path end |
Instance Method Details
#copy_configs ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/masquito/resolver.rb', line 24 def copy_configs resolver = ERB.new File.read(RESOLVER_TEMPLATE_PATH) template = resolver.result(binding) Masquito::Settings.new(CONFIG_PATH).domains.each do |domain| File.open(RESOLVERS_PATH.join(domain.to_s), 'w') { |f| f.write(template) } end end |
#remove_configs ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/masquito/resolver.rb', line 32 def remove_configs Dir.foreach(RESOLVERS_PATH) do |name| next if name == '.' or name == '..' path = RESOLVERS_PATH.join(name) if File.new(path).readline == %Q(# Masquito magic comment\n) FileUtils.rm_rf(path) end end end |
#reset ⇒ Object
19 20 21 22 |
# File 'lib/masquito/resolver.rb', line 19 def reset remove_configs copy_configs end |
#start ⇒ Object
12 13 14 15 16 17 |
# File 'lib/masquito/resolver.rb', line 12 def start reset fsevent = FSEvent.new fsevent.watch(@config_path) { reset } fsevent.run end |