Class: Disloku::Config::YamlConfig
- Inherits:
-
Object
- Object
- Disloku::Config::YamlConfig
- Defined in:
- lib/disloku/config/YamlConfig.rb
Instance Attribute Summary collapse
-
#yaml ⇒ Object
Returns the value of attribute yaml.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #get(keys) ⇒ Object
- #has?(key) ⇒ Boolean
-
#initialize(config, isFile = true) ⇒ YamlConfig
constructor
A new instance of YamlConfig.
- #merge(base) ⇒ Object
- #to_s ⇒ Object
- #to_yaml ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(config, isFile = true) ⇒ YamlConfig
Returns a new instance of YamlConfig.
9 10 11 12 13 14 15 |
# File 'lib/disloku/config/YamlConfig.rb', line 9 def initialize(config, isFile = true) if (isFile) @yaml = YAML.load_file(config) else @yaml = config end end |
Instance Attribute Details
#yaml ⇒ Object
Returns the value of attribute yaml.
7 8 9 |
# File 'lib/disloku/config/YamlConfig.rb', line 7 def yaml @yaml end |
Instance Method Details
#[](key) ⇒ Object
33 34 35 |
# File 'lib/disloku/config/YamlConfig.rb', line 33 def [](key) return self.get(key.split('.')) end |
#get(keys) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/disloku/config/YamlConfig.rb', line 25 def get(keys) if (keys.empty?()) return self end current = keys.shift() return @yaml.has_key?(current) ? YamlConfig.new(@yaml[current], false).get(keys) : nil end |
#has?(key) ⇒ Boolean
21 22 23 |
# File 'lib/disloku/config/YamlConfig.rb', line 21 def has?(key) return self[key] != nil end |
#merge(base) ⇒ Object
17 18 19 |
# File 'lib/disloku/config/YamlConfig.rb', line 17 def merge(base) @yaml = base.yaml.recursive_merge(@yaml) end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/disloku/config/YamlConfig.rb', line 44 def to_s() return value().to_s() end |
#to_yaml ⇒ Object
48 49 50 |
# File 'lib/disloku/config/YamlConfig.rb', line 48 def to_yaml() return @yaml.to_yaml() end |
#value ⇒ Object
37 38 39 40 41 42 |
# File 'lib/disloku/config/YamlConfig.rb', line 37 def value() if (@yaml.kind_of?(Array)) return @yaml.map() { |item| YamlConfig.new(item, false) } end return @yaml end |