Class: MetaCon::Config
- Inherits:
-
Object
- Object
- MetaCon::Config
- Defined in:
- lib/metacon/config.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#declared ⇒ Object
Returns the value of attribute declared.
Instance Method Summary collapse
- #[](context) ⇒ Object
-
#initialize(root) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(root) ⇒ Config
Returns a new instance of Config.
4 5 6 7 8 9 10 11 |
# File 'lib/metacon/config.rb', line 4 def initialize(root) # TODO: Ability to explicitly set mconf files in .metacon settings require 'yaml' conf_files = Dir[root + '/**/*.mconf'] @data = [] @declared = {:rtc=>{}, :role=>{}, :os=>{}, :host=>{}} conf_files.each{|cf| update_with(cf) } end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/metacon/config.rb', line 3 def data @data end |
#declared ⇒ Object
Returns the value of attribute declared.
3 4 5 |
# File 'lib/metacon/config.rb', line 3 def declared @declared end |
Instance Method Details
#[](context) ⇒ Object
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 |
# File 'lib/metacon/config.rb', line 13 def [](context) rtc,role,os,host = [:rtc,:role,:os,:host].map{|k| context.delete(k) || '*'} relevant = @data.select do |keys,fc| (rtc == '*' || keys[0] == '*' || rtc == keys[0]) && (role== '*' || keys[1] == '*' || role== keys[1]) && (os == '*' || keys[2] == '*' || os == keys[2]) && (host== '*' || keys[3] == '*' || host== keys[3]) end res = {} relevant.each do |k, fc| fam, content = fc if res.has_key?(fam) currv = res[fam] if content.is_a?(Array) && currv.is_a?(Array) res[fam] = currv | content elsif content.is_a?(Hash) && currv.is_a?(Hash) res[fam] = currv.merge(content) else # TODO: Think through more merge scenarios raise "Could not combine conf parameters for #{fam}" end else res[fam] = content end end return res end |