Sha256: 8e3282f72f81a9c66bbeb2345ff6b7d16f04dedf03ce5bec50cb961f617404e3
Contents?: true
Size: 853 Bytes
Versions: 5
Compression:
Stored size: 853 Bytes
Contents
module ConfigManager module Settings module Yaml def self.included(base) base.extend ClassMethods end module ClassMethods #def to_yaml(path) # File.open(path, 'w') do |file| # settings_hash = all.map(&:to_hash) # YAML.dump(settings_hash, file) # end #end def to_yaml YAML.dump(all.map(&:to_hash)) end 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 end end end end
Version data entries
5 entries across 5 versions & 1 rubygems