README.md in sprig-0.2.0 vs README.md in sprig-0.3.0

- old
+ new

@@ -12,34 +12,47 @@ Add into your Gemfile ```ruby gem "sprig" ``` -Use `rails generate sprig:install` to create environment-specific seed directories. +Use `rails generate sprig:install` to create environment-specific and shared seed directories. -##The Sprig Directive +## The Sprig Directive Within your seed file, you can use the `sprig` directive to initiate Sprig's dark magicks. A simple directive might look like this. ```ruby # seeds.rb include Sprig::Helpers sprig [User, Post, Comment] + +For shared seeds: +sprig_shared [User, Post, Comment] ``` This directive tells Sprig to go find your datafiles for the `User`, `Post`, and `Comment` seed resources, build records from the data entries, and insert them into the database. Sprig will automatically detect known datafile types like `.yml`, `.json`, or `.csv` within your environment-specific seed directory. -##Environment +## Environment Seed files are unique to the environment in which your Rails application is running. Within `db/seeds` create an environment-specific directory (i.e. `/development` for your 'development' environment). -Todo: [Support for shared seed files] +### Shared -##Seed files +Shared seed files default directory is `shared` (eg `db/seeds/shared`) +You can change it by settings` +To insert env specific together with shared seeds use: +```ruby +sprig [User] +sprig_shared [User] +``` +This will insert `:env/users` and `shared/users` seeds + +## Seed files + Hang your seed definitions on a `records` key for *yaml* and *json* files. Examples: ```yaml @@ -48,11 +61,11 @@ records: - sprig_id: 1 first_name: 'Lawson' last_name: 'Kurtz' username: 'lawdawg' - - sprig_id: 2 + - sprig_id: 'ryan' # Note: Sprig IDs can be integers or strings first_name: 'Ryan' last_name: 'Foster' username: 'mc_rubs' ``` @@ -94,24 +107,24 @@ For `has_and_belongs_to_many` (HABTM) relationships, you may define relation ids in array format. So if `Post` `has_and_belongs_to_many :tags`, you could write: ```yaml #posts.yml records: - - sprig_id: 1 + - sprig_id: 42 title: 'All About Brains' content: 'Lorem ipsum...' tag_ids: - '<%= sprig_record(Tag, 1).id %>' - '<%= sprig_record(Tag, 2).id %>' ``` ```yaml #tags.yml records: - - sprig_id: 1 + - sprig_id: 'bio' name: 'Biology' - - sprig_id: 2 + - sprig_id: 'neuro' name: 'Neuroscience' ``` **Note: For namespaced or STI classes, you'll need to include the namespace with the class name in the seed file name. For example `Users::HeadManager` would need to be `users_head_managers.yml`** ### Special Options @@ -144,11 +157,11 @@ - sprig_id: 1 body: "Yaml Post body" published_at: "<%= 1.week.ago %>" ``` -##Custom Sources and Parsers +## Custom Sources and Parsers If all your data is in `.wat` files, fear not. You can tell Sprig where to look for your data, and point it toward a custom parser class for turning your data into records. The example below tells Sprig to read `User` seed data from a Google Spreadsheet, and parse it accordingly. ```ruby require 'open-uri' @@ -164,17 +177,18 @@ Post, Comment ] ``` -##Configuration +## Configuration When Sprig conventions don't suit, just add a configuration block to your seed file. ```ruby Sprig.configure do |c| c.directory = 'seed_files' + c.shared_directory = 'shared' end ``` ## Populate Seed Files from Database @@ -184,5 +198,13 @@ details on usage. ## License This project rocks and uses MIT-LICENSE. + +*** + +<a href="http://code.viget.com"> + <img src="http://code.viget.com/github-banner.png" alt="Code At Viget"> +</a> + +Visit [code.viget.com](http://code.viget.com) to see more projects from [Viget.](https://viget.com)