Class: CloudAlign::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Config

Returns a new instance of Config.



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

def initialize(path = nil)
  @config = {}
  load path
end

Instance Method Details

#get(key, default = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/cloudalign/config.rb', line 15

def get(key, default = nil)
  p = @config
  key.split('.').each do |part|
    return default unless p.has_key? part
    p = p[part]
  end

  p
end

#load(path = nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/cloudalign/config.rb', line 25

def load(path = nil)
  if path.nil?
    config_paths = [Pathname.new(Dir.home).join('.cloudalign', 'config.yml').to_s]
    path = config_paths.detect{|p| ::File.exists?(p)}
  end

  @config = YAML.load_file(path)
end

#set(key, value) ⇒ Object



11
12
13
# File 'lib/cloudalign/config.rb', line 11

def set(key, value)
  set_recursive(key, value, @config)
end