Last active
March 24, 2017 01:37
-
-
Save jimryan/1ff3d6a19f9ec1abd6612864a05e3185 to your computer and use it in GitHub Desktop.
Restore lederman-rails-settings global Settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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