Class: Rancher::Shell::Config

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

Class Method Summary collapse

Class Method Details

.get(key) ⇒ Object



44
45
46
# File 'lib/rancher/shell/config.rb', line 44

def self.get key
  @data[key]
end

.get_allObject



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

def self.get_all
  @data
end

.load(options = {}) ⇒ Object



7
8
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
38
39
40
41
42
# File 'lib/rancher/shell/config.rb', line 7

def self.load options = {}
  config_file_paths = [
    "#{ENV['HOME']}/.rancher-shell.yml",
    "#{Dir.pwd}/.rancher-shell.yml",
  ]
  @data = {}
  @data['options'] ||= options.dup
  @data['projects'] ||= {}
  config_file_paths.each do |file_path|
    next unless File.exists? file_path
    config = YAML.load_file file_path
    if config
      if config['options']
        config['options'].each do |key, value|
          @data['options'][key] = value unless options[key]
        end
        config.delete('options')
      end
      @data.deep_merge! config
    end
  end
  return unless @data['options']['project']
  @data['project'] = @data['projects'][@data['options']['project']]
  if @data['project']['options']
    @data['project']['options'].each do |key, value|
      @data['options'][key] = value unless options[key]
    end
  end
  if @data['options']['stack'] && @data['project']['stacks'] && @data['project']['stacks'][@data['options']['stack']]
    if @data['project']['stacks'][@data['options']['stack']]['options']
      @data['project']['stacks'][@data['options']['stack']]['options'].each do |key, value|
        @data['options'][key] = value unless options[key]
      end
    end
  end
end