An ActiveRecord 3.x Ruby gem for attribute serialization.

"Dy-na-bix, tasty serialization attribute accessors for ActiveRecord"


Dynabix dynamically creates read/write accessors on ActiveRecord models for storing attributes in a serialized Hash.


Add to your Gemfile

gem "dynabix"

Install the gem

bundle install


Get the source

cd workspace

git clone https://github.com/robertwahler/dynabix.git

cd dynabix

Install the dependencies

bundle install

Run the specs

bundle exec rake spec

Autotest with Guard

bundle exec guard

Usage Examples

Ruby 1.8

Add a text column "metadata" to your model migration

class AddMetadataToThings < ActiveRecord::Migration

  def change
    add_column :things, :metadata, :text


Add accessors to your model using the default column name ":metadata", specify the attributes in a separate step.

class Thing < ActiveRecord::Base

  # full accessors
   :breakfast_food, :wheat_products, :needs_milk

  # read-only

Specifying attributes for full attributes accessors in one step

class Thing < ActiveRecord::Base
   :metadata, :breakfast_food, :wheat_products, :needs_milk

Using the new accessors

thing = Thing.new

thing.breakfast_food = 'a wheat like cereal"

# same thing, but not using the hash directly
thing.metadata[:breakfast_food] = 'a wheat like cereal"

Ruby 1.9+

Dynabix under Ruby 1.9+ enables specifying multiple metadata columns on a model.

Add text columns "cows" and "chickens" to your model migration

class AddMetadataToThings < ActiveRecord::Migration

  def change
    add_column :things, :cows, :text
    add_column :things, :chickens, :text


Specifying multiple metadata serializers (Ruby 1.9 only)

class Thing < ActiveRecord::Base
   :chickens, :tasty, :feather_count

  # read-only
  cow_reader :likes_milk, :hates_eggs

  # write-only
  cow_writer :no_wheat_products

  # extra full accessors for chickens
  chicken_accessor :color, :likes_eggs

Runtime dependencies

  • Activerecord 3.x

Development dependencies

Rake tasks

bundle exec rake -T

rake build             # Build dynabix-0.0.2.gem into the pkg directory
rake doc:clean         # Remove generated documenation
rake doc:generate      # Generate YARD Documentation
rake doc:undocumented  # List undocumented objects
rake gemfiles          # Generate .gemfiles via 'git ls-files'
rake install           # Build and install dynabix-0.0.2.gem into system gems
rake release           # Create tag v0.0.2 and build and push dynabix-0.0.2.gem to Rubygems
rake spec              # Run RSpec


Copyright (c) 2012 GearheadForHire, LLC. See LICENSE for details.