Class: Dory::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/dory/config.rb

Class Method Summary collapse

Class Method Details

.debug?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/dory/config.rb', line 80

def self.debug?
  self.settings[:dory][:debug]
end

.default_settingsObject



48
49
50
# File 'lib/dory/config.rb', line 48

def self.default_settings
  YAML.load(self.default_yaml).with_indifferent_access
end

.default_yamlObject



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
38
39
40
41
42
43
44
45
46
# File 'lib/dory/config.rb', line 10

def self.default_yaml
  %q(---
    dory:
      # Be careful if you change the settings of some of
      # these services.  They may not talk to each other
      # if you change IP Addresses.
      # For example, resolv expects a nameserver listening at
      # the specified address.  dnsmasq normally does this,
      # but if you disable dnsmasq, it
      # will make your system look for a name server that
      # doesn't exist.
      dnsmasq:
        enabled: true
        domains:               # array of domains that will be resolved to the specified address
          - domain: docker     # you can set '#' for a wilcard
            address: 127.0.0.1 # return for queries against the domain
          - domain: dev
            address: 127.0.0.1
        container_name: dory_dnsmasq
        port: 53  # port to listen for dns requests on.  must be 53 on linux. can be anything that's open on macos
        # kill_others: kill processes bound to the port we need (see previous setting 'port')
        #   Possible values:
        #     ask (prompt about killing each time. User can accept/reject)
        #     yes|true (go aheand and kill without asking)
        #     no|false (don't kill, and don't even ask)
        kill_others: ask
      nginx_proxy:
        enabled: true
        container_name: dory_dinghy_http_proxy
        https_enabled: true
        ssl_certs_dir: ''  # leave as empty string to use default certs
      resolv:
        enabled: true
        nameserver: 127.0.0.1
        port: 53  # port where the nameserver listens. On linux it must be 53
  ).split("\n").map{|s| s.sub(' ' * 8, '')}.join("\n")
end

.filenameObject



6
7
8
# File 'lib/dory/config.rb', line 6

def self.filename
  "#{Dir.home}/.dory.yml"
end

.settings(filename = self.filename) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dory/config.rb', line 52

def self.settings(filename = self.filename)
  if File.exist?(filename)
    defaults = self.default_settings.dup
    config_file_settings = YAML.load_file(filename).with_indifferent_access
    [:dnsmasq, :nginx_proxy, :resolv].each do |service|
      defaults[:dory][service].merge!(config_file_settings[:dory][service] || {})
    end
    defaults[:dory][:debug] = config_file_settings[:dory][:debug]
    defaults
  else
    self.default_settings
  end
end

.upgrade(old_hash) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/dory/config.rb', line 84

def self.upgrade(old_hash)
  newsettings = old_hash.dup

  # If there's a single domain and address, upgrade to the array format
  if newsettings[:dory][:dnsmasq][:domain]
    newsettings[:dory][:dnsmasq][:domains] = [{
      domain: newsettings[:dory][:dnsmasq][:domain],
      address: newsettings[:dory][:dnsmasq][:address] || '127.0.0.1'
    }]
    newsettings[:dory][:dnsmasq].delete(:domain)
    newsettings[:dory][:dnsmasq].delete(:address)
  end

  # Add the option to skip prompts
  newsettings[:dory][:dnsmasq][:kill_others] = 'ask'

  newsettings
end

.upgrade_settings_file(filename = self.filename) ⇒ Object



76
77
78
# File 'lib/dory/config.rb', line 76

def self.upgrade_settings_file(filename = self.filename)
  self.write_settings(self.upgrade(self.settings), filename, is_yaml: false)
end

.write_default_settings_file(filename = self.filename) ⇒ Object



72
73
74
# File 'lib/dory/config.rb', line 72

def self.write_default_settings_file(filename = self.filename)
  self.write_settings(self.default_yaml, filename, is_yaml: true)
end

.write_settings(settings, filename = self.filename, is_yaml: false) ⇒ Object



66
67
68
69
70
# File 'lib/dory/config.rb', line 66

def self.write_settings(settings, filename = self.filename, is_yaml: false)
  settings = settings.to_yaml unless is_yaml
  settings.gsub!(/\s*!ruby\/hash:ActiveSupport::HashWithIndifferentAccess/, '')
  File.write(filename, settings)
end