Class: Proxy::Dns::Dnsmasq::PluginConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_dns_dnsmasq/dns_dnsmasq_configuration.rb

Constant Summary collapse

BACKENDS =
%i(openwrt default).freeze

Instance Method Summary collapse

Instance Method Details

#load_classesObject



3
4
5
6
# File 'lib/smart_proxy_dns_dnsmasq/dns_dnsmasq_configuration.rb', line 3

def load_classes
  require 'dns_common/dns_common'
  require 'smart_proxy_dns_dnsmasq/dns_dnsmasq_main'
end

#load_dependency_injection_wirings(container_instance, settings) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/smart_proxy_dns_dnsmasq/dns_dnsmasq_configuration.rb', line 9

def load_dependency_injection_wirings(container_instance, settings)
  backend = settings[:backend] || :default
  backend = backend.to_s.downcase.to_sym

  unless BACKENDS.include? backend
    raise ::Proxy::Error::ConfigurationError, "Unknown DNS backend #{backend}, available backends are; #{BACKENDS}"
  end

  begin
    require "smart_proxy_dns_dnsmasq/backend/#{backend}"
  rescue LoadError, e
    raise ::Proxy::Error::ConfigurationError, e, "Failed to load #{backend} backend"
  end

  klass = case backend
          when :openwrt
            ::Proxy::Dns::Dnsmasq::Openwrt
          when :default
            ::Proxy::Dns::Dnsmasq::Default
          end

  container_instance.dependency :dns_provider, (lambda do
    klass.new(
      settings[:config_path],
      settings[:reload_cmd],
      settings[:dns_ttl]
    )
  end)
end