README.md in evil-seed-0.1.1 vs README.md in evil-seed-0.1.2
- old
+ new
@@ -1,6 +1,8 @@
-[![Gem Version](https://badge.fury.io/rb/evil-seed.svg)](https://rubygems.org/gems/evil-seed) [![Build Status](https://travis-ci.org/evilmartians/evil-seed.svg?branch=master)](https://travis-ci.org/evilmartians/evil-seed)
+[![Gem Version](https://badge.fury.io/rb/evil-seed.svg)](https://rubygems.org/gems/evil-seed)
+[![Build Status](https://travis-ci.org/evilmartians/evil-seed.svg?branch=master)](https://travis-ci.org/evilmartians/evil-seed)
+[![Cult of Martians](http://cultofmartians.com/assets/badges/badge.svg)](http://cultofmartians.com/tasks/evil-seed.html)
# EvilSeed
EvilSeed is a tool for creating partial anonymized dump of your database based on your app models.
@@ -38,11 +40,11 @@
## Usage
### Configuration
```ruby
-require 'evil-seed'
+require 'evil_seed'
EvilSeed.configure do |config|
# First, you should specify +root models+ and their +constraints+ to limit the number of dumped records:
# This is like Forum.where(featured: true).all
config.root('Forum', featured: true) do |root|
@@ -88,11 +90,11 @@
### Creating dump
Just call the `#dump` method and pass a path where you want your SQL dump file to appear!
```ruby
-require 'evil-seed'
+require 'evil_seed'
EvilSeed.dump('path/to/new_dump.sql')
```
### Caveats, tips, and tricks
@@ -118,9 +120,56 @@
Association path for `User.has_and_belongs_to_many :roles` is `user.users_roles.role`, but should be `user.roles`
2. Test coverage is poor
3. Some internal refactoring is required
+
+
+## Standalone usage
+
+If you want to use it as a standalone application, you can place exerything in a single file like this:
+
+```ruby
+#!/usr/bin/env ruby
+
+require 'bundler/inline'
+
+gemfile do
+ source 'https://rubygems.org'
+ gem 'activerecord'
+ gem 'evil-seed'
+ gem 'mysql2'
+end
+
+# Describe your database layout with ActiveRecord models.
+# See http://guides.rubyonrails.org/active_record_basics.html
+
+class Category < ActiveRecord::Base
+ has_many :translations, class_name: "Category::Translation"
+end
+
+class Category::Translation < ActiveRecord::Base
+ belongs_to :category, inverse_of: :translations
+end
+
+# Configure evil-seed itself
+EvilSeed.configure do |config|
+ config.root("Category", "id < ?", 1000)
+end
+
+# Connect to your database.
+# See http://guides.rubyonrails.org/configuring.html#configuring-a-database)
+ActiveRecord::Base.establish_connection(ENV.fetch("DATABASE_URL"))
+
+# Create dump in dump.sql file in the same directory as this script
+EvilSeed.dump(File.join(__dir__, "dump.sql").to_s)
+```
+
+And launch it like so:
+
+```sh
+DATABASE_URL=mysql2://user:pass@host/db ruby path/to/your/script.rb
+```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.