module ConfigManager::Settings::Yaml::ClassMethods

Public Instance Methods

from_yaml(path) click to toggle source
# 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_yaml() click to toggle source

def to_yaml(path)

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

end

# File lib/config_manager/settings/yaml.rb, line 15
def to_yaml
        YAML.dump(all.map(&:to_hash))
end