Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cmeiklejohn/seedable
Allows for quick serialization/deserialization of objects for moving between environments.
https://github.com/cmeiklejohn/seedable
Last synced: about 2 months ago
JSON representation
Allows for quick serialization/deserialization of objects for moving between environments.
- Host: GitHub
- URL: https://github.com/cmeiklejohn/seedable
- Owner: cmeiklejohn
- License: mit
- Created: 2011-06-30T00:31:03.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-09-23T04:44:28.000Z (over 13 years ago)
- Last Synced: 2024-04-24T01:41:33.479Z (8 months ago)
- Language: Ruby
- Homepage: https://github.com/cmeiklejohn/seedable
- Size: 120 KB
- Stars: 2
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: LICENSE
Awesome Lists containing this project
README
= 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:Seedable.from_seedable(garage_json) # Returns Garage object.
or, an array of different object types:
json = [@garage, @car, @garage2, @bike].to_seedable
Seedable.from_seedable(json) # Returns array of [Garage, Car, Garage, Bike]== Caveats
This is the first release, and yes, there are a bunch of caveats.
=== Compatibility
1. Compatible and tested under rails 3.1 and rails-master.
2. Compatible and tested under ruby 1.9.2.=== Exporting with primary keys
1. Importing objects with associated objects by primary key will only
work on rails master. This is because the code relies on mass
assignment changes/abstractions destined for rails-3.2.x.== License
Seedable is Copyright © 2011 Christopher Meiklejohn. It is free software, and may be redistributed under the terms specified in the LICENSE file.
== About
The seedable gem was written by {Christopher Meiklejohn}[mailto:[email protected]] from {Swipely, Inc.}[http://www.swipely.com].