usage

An article by Gaspard Bucher
  1. action
  2. ajax
  3. API
    1. zafu
    2. query builder
    3. rubyless
    4. gold
    5. property
    6. versions
    7. remote
    8. zazen
    9. console
  4. classes
  5. common attributes
  6. conditions
  7. context
  8. dates
  9. display
  10. forms
  11. i18n
  12. meta
  13. SQLiss
  14. urls


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.