Module: ConfigManager::Settings::Yaml::ClassMethods

Defined in:
lib/config_manager/settings/yaml.rb

Instance Method Summary collapse

Instance Method Details

#from_yaml(path) ⇒ Object



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

def from_yaml(path)
	settings = YAML::load(File.open path)
	settings.reduce([0,0]) do |memo, hash|
		begin
			setting = create(hash.symbolize_keys)
			if setting.valid?
				memo[0] += 1
			else
				Rails.logger.error "Bad setting definition. #{setting.message}"
				memo[1] += 1
			end
		rescue RuntimeError
			Rails.logger.error "Bad setting definition. #{$!}"
			memo[1] += 1
		end

		memo
	end
end

#to_yamlObject

def to_yaml(path) File.open(path, ‘w’) do |file| settings_hash = all.map(&:to_hash) YAML.dump(settings_hash, file) end end



15
16
17
# File 'lib/config_manager/settings/yaml.rb', line 15

def to_yaml
	YAML.dump(all.map(&:to_hash))
end