Install with:
$ sudo gem install property
You then need to create a migration to add a ‘text’ field named ‘properties’ to
your model. Something like this:
class AddPropertyToContact < ActiveRecord::Migration def self.up add_column :contacts, :properties, :text end def self.down remove_column :contacts, :properties end end
Once your database is ready, you need to declare the property columns:
class Contact < ActiveRecord::Base include Property property do |p| p.string 'first_name', 'name', 'phone' p.datetime 'contacted_at', :default => Proc.new {Time.now} p.string 'encoding', :default => :get_encoding end end
You can now read property values with:
@contact.prop['first_name'] @contact.first_name
And set them with:
@contact.update_attributes('first_name' => 'Mahatma') @contact.prop['name'] = 'Gandhi' @contact.name = 'Gandhi'
If you want to read as fast as possible, prop['attribute']
is your friend.