Class: CKnife::Config

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

Class Method Summary collapse

Class Method Details

.[](s) ⇒ Object



40
41
42
# File 'lib/cknife/config.rb', line 40

def self.[](s)
  get(s)
end

.configObject



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
# File 'lib/cknife/config.rb', line 12

def self.config
  return @config if @config

  @config = {
    :key => ENV["KEY"] || ENV['AMAZON_ACCESS_KEY_ID'],
    :secret => ENV["SECRET"] || ENV['AMAZON_SECRET_ACCESS_KEY']
  }

  config_file = nil
  Pathname.new(Dir.getwd).tap do |here|
    config_file = [["cknife.yml"], ["tmp", "cknife.yml"]].map { |args|
      here.join(*args)
    }.select { |path|
      File.exists?(path)
    }.first
  end

  if config_file
    begin
      @config.merge!(YAML.load(config_file.read))
    rescue
      puts "Found, but could not parse config: #{config_file}"
    end
  end

  @config
end

.get(path) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cknife/config.rb', line 44

def self.get(path)
  cur = config
  path.to_s.split('.').each do |segment|
    cur = cur[segment.force_encoding('UTF-8').to_s] if cur
  end

  if cur.nil?
    cur = ENV[path]
  end

  cur
end