property

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

contents

description

The Property gem lets you define “properties” for your models. Properties behave like normal rails attributes with the following differences:

what you gain

  • they should be faster (less type casting)
  • you can add properties to sub-classes without affecting the parent class
  • you can dynamically define properties in model instances when needed (virtual classes)
  • you can use roles to group attributes together
  • you can easily define complex indices

what you loose

  • they are harder to use in queries (must use index tables)
  • you could directly index the json data, but that might not be optimal

Properties are stored into a single database column and are declared from within the model or by using roles).

This class is 100% compatible with ActiveRecord. This means that if you have been using a model with normal attributes, you should be able migrate the data and copy paste the table definition from the schema into your model and it should work as before, except for sql queries of course.

source code

The code is on github