Class: Disloku::Config::YamlConfig

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#yamlObject

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

Returns:

  • (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_sObject



44
45
46
# File 'lib/disloku/config/YamlConfig.rb', line 44

def to_s()
	return value().to_s()
end

#to_yamlObject



48
49
50
# File 'lib/disloku/config/YamlConfig.rb', line 48

def to_yaml()
	return @yaml.to_yaml()
end

#valueObject



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