Skip to content

Instantly share code, notes, and snippets.

@jimryan
Last active Mar 24, 2017
Embed
What would you like to do?
Restore lederman-rails-settings global Settings
# Restores lederman-rails-settings 1.x global Settings interface
class Settings < ActiveRecord::Base
serialize :value
def self.[](var)
find_by_var(var).try :value
end
def self.[]=(var, value)
setting = find_or_initialize_by(var: var)
setting.value = value
setting.save!
value
end
def self.method_missing(meth, *args, &block)
if [:find_by_var, :find_or_initialize_by].include?(meth)
super
elsif meth =~ /=\Z/
self[meth.to_s.chop] = args[0]
else
self[meth]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment