Rails plugin that gives extra power to the ActiveRecord#serialize method.
It creates setters and getters for the fake columns, and cast values to the appropriate class.
Tested using shoulda.
NOTE: 1) There are a lot of similar plugins out there. I wrote my own because it is the only one that supports classes + defaults + tested. Some ideas (like support.rb) were taken from mongomapper. 2) For now the only accepted classes are Boolean, String, Integer, and Float. Why? …it’s what I need…
In your model:
# Given the following model # User(id: integer, username: string, serialized_data: text, created_at: datetime) super_serialize :male, Boolean, :default => true super_serialize :occupation, String super_serialize :age, Integer super_serialize :weight, Float # Gives you setters and getters to do the following user = User.new(:username => 'ary', :male => true, :age => '25') user.occupation = 'professional fútbol player' user.username == 'ary' # => true # Integer user.age = 'ary' # => 0 user.age = 10.8 # => 10 user.age = nil # => nil # Float user.weight = 135 # => 135.0 user.weight = '61.2 kg' # => 61.2 user.weight = nil # => nil # String user.occupation = true # => 'true' user.occupation = 10.2 # => '10.2' user.occupation = nil # => nil # Boolean user.male = 'true' # => true user.male = 't' # => true user.male = 1 # => true # Also gives you a #{name}? method user.male? # => true
None.
./script/plugin install git://github.com/arydjmal/super_serialize.git
Copyright © 2010 Ary Djmal, released under the MIT license