Class: Deployku::Config

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

Constant Summary collapse

HOME =
File::expand_path('~deployku')
FROM =
'pejuko/rvm-base'
PACKAGES =
['git']
DEFAULT_ENGINE =
'docker'
DEFAULT_PORT =
80

Class Method Summary collapse

Class Method Details

.deep_merge!(hash1, hash2) ⇒ Object



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

def deep_merge!(hash1, hash2)
  hash2.each do |key, value|
    k = key.to_s
    unless hash1[k]
      hash1[k] = value
    else
      if hash1[k].kind_of?(Hash)
        deep_merge!(hash1[k], value)
      elsif hash1[k].kind_of?(Array)
        hash1[k] = hash1[k] + value
      else
        hash1[k] = value
      end
    end
  end
end

.engineObject



20
21
22
# File 'lib/deployku/config.rb', line 20

def engine
  (@config && @config['engine']) ? @config['engine'] : DEFAULT_ENGINE
end

.fromObject



24
25
26
# File 'lib/deployku/config.rb', line 24

def from
  (@config && @config['from']) ? @config['from'] : FROM
end

.homeObject



16
17
18
# File 'lib/deployku/config.rb', line 16

def home
  HOME
end

.load(path = File.join(HOME, '.deployku.yaml')) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/deployku/config.rb', line 73

def load(path=File.join(HOME, '.deployku.yaml'))
  if File.exists?(path)
    deployku_config = YAML.load_file(path)
    Deployku::Config.merge!(deployku_config)
    true
  else
    false
  end
end

.merge!(opts) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/deployku/config.rb', line 41

def merge!(opts)
  unless @config
    @config = {
      'from' => FROM,
      'packages' => PACKAGES,
      'engine' => DEFAULT_ENGINE
    }
  end
  deep_merge!(@config, opts)
end

.method_missing(method, *args) ⇒ Object



36
37
38
39
# File 'lib/deployku/config.rb', line 36

def method_missing(method, *args)
  return nil unless @config
  return @config[method.to_s]
end

.packagesObject



28
29
30
# File 'lib/deployku/config.rb', line 28

def packages
  (@config && @config['packages']) ? @config['packages'] : PACKAGES
end

.portObject



32
33
34
# File 'lib/deployku/config.rb', line 32

def port
  (@config && @config['port']) ? @config['port'] : DEFAULT_PORT
end

.save(path = File.join(HOME, '.deployku.yaml')) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/deployku/config.rb', line 83

def save(path=File.join(HOME, '.deployku.yaml'))
  if @config
    File.open(path, 'w') do |f|
      f << @config.to_yaml
    end
  end
end

.set_opts(key, opts) ⇒ Object



69
70
71
# File 'lib/deployku/config.rb', line 69

def set_opts(key, opts)
  @config[key.to_s] = opts[key.to_s] if opts[key.to_s]
end