README.rdoc

Seedable

Data import and export for rails, to assist in seeding development
databases from production.

What is Seedable?

Seedable is a mixin to select groups of objects, and export them via
serialized JSON, to be reimported later. The goal, is less to maintain a
consistent database state, but for quick dumping and restoring of data
between environments, to seed your database.

Usage

Using Seedable is easy!

How do I include it?

Add the gem.

gem 'seedable'

Include the module:

include Seedable

In the models you want to export together, place the following:

seedable

Exporting records

To export, call:

json = @garage.to_seedable

By default, seedable will traverse all active_record associations and
export all of their attributes. To exclude associations, do the following:

seedable :include_associations => [:cars, :bikes]

You can also call it after the fact:

Garage.include_associations([:cars])

To filter attributes:

seedable :filter_attributes => [:id]

You can also call it after the fact:

Garage.filter_attributes([:id])

You can also export an array of disperse object types:

[@garage, @car, @garage2, @bike].to_seedable

Importing records

To import:

Garage.from_seedable(json)

or, if you have JSON from a unknown object type and want it to return the
proper object type: