Sha256: 6a64c3264be53f7a0df8a60eca3e5340fce276fd93b3473bfe6ac38cc26eb8bf
Contents?: true
Size: 744 Bytes
Versions: 1
Compression:
Stored size: 744 Bytes
Contents
class Settings def initialize(attributes={}) attributes.each do |key, value| self[key] = value end end def [](name) fetch(name, nil) end def fetch(name, *args) setting = settings.find { |setting| setting.name == name } return setting.value if setting raise KeyError, "key not found: #{name.inspect}" if args.empty? args.first end def []=(name, value) setting = settings.find { |setting| setting.name == name } settings << (setting = Setting.new(name: name)) unless setting setting.value = value end def save! settings.each do |setting| setting.save if setting.changed? end end private def settings @settings ||= Setting.all end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
houston-core-0.5.0.beta1 | app/models/settings.rb |