diff options
author | Joost Baaij <joost@spacebabies.nl> | 2012-03-13 16:14:20 +0100 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-18 23:49:48 -0300 |
commit | 757f7231cccd2bcbfb83fba5cb203fb320f3e613 (patch) | |
tree | bd16dbccdaa0d54e2ad579c626c5a3ea5afbd49b /activerecord/lib | |
parent | df2104e06784a4b98d8f30cb3ea4eee69304e768 (diff) | |
download | rails-757f7231cccd2bcbfb83fba5cb203fb320f3e613.tar.gz rails-757f7231cccd2bcbfb83fba5cb203fb320f3e613.tar.bz2 rails-757f7231cccd2bcbfb83fba5cb203fb320f3e613.zip |
Remember the stored attributes in a config attribute.
This allows you to retrieve the list of attributes you've defined.
Usable for e.g. selects in the view, or interators based on the
attributes you wish to store in the serialized column.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/store.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/store.rb b/activerecord/lib/active_record/store.rb index 542cb3187a..f5c7a9f034 100644 --- a/activerecord/lib/active_record/store.rb +++ b/activerecord/lib/active_record/store.rb @@ -1,3 +1,4 @@ +require 'active_support/concern' require 'active_support/core_ext/hash/indifferent_access' module ActiveRecord @@ -33,9 +34,18 @@ module ActiveRecord # class SuperUser < User # store_accessor :settings, :privileges, :servants # end + # + # The stored attribute names can be retrieved using +stored_attributes+. + # + # User.stored_attributes[:settings] # [:color, :homepage] module Store extend ActiveSupport::Concern + included do + config_attribute :stored_attributes + self.stored_attributes = {} + end + module ClassMethods def store(store_attribute, options = {}) serialize store_attribute, IndifferentCoder.new(options[:coder]) @@ -55,6 +65,8 @@ module ActiveRecord send(store_attribute)[key] end end + + self.stored_attributes[store_attribute] = keys.flatten end end |