Class: StackingConfig

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ops = {}) ⇒ StackingConfig

Returns a new instance of StackingConfig.



4
5
6
7
8
# File 'lib/stacking_config.rb', line 4

def initialize(ops = {})
  @parents = []
  @data = {}
  @location = ops.delete(:location)
end

Class Method Details

.load(file) ⇒ Object



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

def self.load(file)
  config = new(:location => file)
  if File.exist? file
    data = YAML.load_file(file)
    data.each {|k,v| config[k] = v }
  end
  config
end

Instance Method Details

#<<(other) ⇒ Object



10
11
12
13
# File 'lib/stacking_config.rb', line 10

def << (other)
  @parents = [other] + @parents
  self
end

#[](key) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
# File 'lib/stacking_config.rb', line 15

def [](key)
  raise ArgumentError, "Expected key to be a symbol, or string" unless key.respond_to? :to_sym
  @data[key.to_sym] || get_first_parent_result(key.to_sym)
end

#[]=(key, value) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
# File 'lib/stacking_config.rb', line 20

def []=(key, value)
  raise ArgumentError, "Expected key to be a symbol, or string" unless key.respond_to? :to_sym
  @data[key.to_sym] = value
end

#get_first_parent_result(k) ⇒ Object



34
35
36
37
38
39
# File 'lib/stacking_config.rb', line 34

def get_first_parent_result(k)
  @parents.each do |p|
    return p[k] if p[k]
  end
  nil
end