Class: MKConfig::Config

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

Constant Summary collapse

CONFIG_FILE =
'lib/mkconfig.yml'

Class Method Summary collapse

Class Method Details

.get(path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mkconfig.rb', line 19

def self.get path 
	values = MKConfig::Data.where('path = ?', path)
	return values[0].value if values.count > 0

	params = get_file
	parts = path.split("/")
	return_value = ""

	parts.each do |part|
		if return_value == ''
			return_value = params[part]
		else
			return_value = return_value[part]
		end
	end

	return_value.to_s
end

.get_fileObject



10
11
12
13
14
15
16
17
# File 'lib/mkconfig.rb', line 10

def self.get_file
	params = {}		
if(File.exist?(CONFIG_FILE))
	params = YAML::load(File.open(CONFIG_FILE))
end

return params
end

.store(path, value) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/mkconfig.rb', line 38

def self.store(path, value)
	values = MKConfig::Data.where('path = ?', path)
	if values.count > 0
		values[0].update_attributes!(:path => path, :value => value)
	else
		MKConfig::Data.create!(:path => path, :value => value)
	end
	value
end