Created
August 27, 2011 19:58
-
-
Save rwilcox/1175801 to your computer and use it in GitHub Desktop.
An awesome way forward with serialized attributes
This file contains hidden or 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
| # WITH HASHIE (https://github.com/intridea/hashie) | |
| # ###################################################### | |
| class User | |
| before_create :default_preferences_value | |
| serialize :preferences_hash | |
| delegate :full_name, :to => :preferences_hash | |
| delegate :full_name=, :to => :preferences_hash | |
| delegate :timezone, :to => :preferences_hash | |
| delegate :timezone=, :to => :preferences_hash | |
| delegate :favorite_color, :to => :preferences_hash | |
| delegate :favorite_color=, :to => :preferences_hash | |
| def default_preferences_value | |
| self.preferences_hash = Hashie::Mash.new if preferences_hash.nil? | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PS: yes, I know about simple_eav. I also have a long history of trying to get simple_eav working on projects. This is a reasonable fallback, or when the needs expand beyond simple eav (for example, hashie's coercion)