Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrumpClone/9af270c781d9377cafe5872a6897f660 to your computer and use it in GitHub Desktop.
Save TrumpClone/9af270c781d9377cafe5872a6897f660 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
# @see https://github.com/rails/rails/blob/4-2-stable/activerecord/lib/active_record/store.rb
module ActiveRecord::Store::ClassMethods
def multi_store_accessor(store_attributes, *keys, store_host: nil)
store_host = store_attributes.first unless store_host
keys = keys.flatten
_store_accessors_module.module_eval do
keys.each do |key|
define_method("#{key}=") do |value|
store_attributes.each do |store_attribute|
write_store_attribute(store_attribute, key, value)
end
end
define_method(key) do
read_store_attribute(store_host, key)
end
end
end
self.local_stored_attributes ||= {}
store_attributes.each do |store_attribute|
self.local_stored_attributes[store_attribute] ||= []
self.local_stored_attributes[store_attribute] |= keys
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment