Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Factory builder for Mongoose & Seed
JavaScript Makefile
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
Makefile
README.md
package.json

README.md

Build Status

Seed Forge

Seed Forge is a powerful factory builder for Seed and Mongoose

Synopsis

Public methods

var define     = require('seed-forge').define;
var list       = require('seed-forge').list;
var build      = require('seed-forge').build;
var factory    = require('seed-forge').factory;
var attributes = require('seed-forge').attributes;

Define a factory

define(User)
  .set('name', 'Name')
  .set('url', function () {
    return 'http://example.com';
  })
  .set('eyes.left', 'blue')
  .set('eyes.right', 'green')
  .set('email', function (n) {
    return 'example' + n + '@example.com'
  })
  .set('age', 33)
  .set('admin', false);

Inheritance

define('Admin', User)
  .extend('User')
  .set('age', 44)
  .set('admin', true)
  .set('disabled', false);

define('DisabledAdmin', User)
  .extend('Admin')
  .set('disabled', true);

Create a record from factory

factory('User', fn);
factory('User', { override: 'attributes' }, fn);

Create multiple records

list('User', 10, fn); // Will create 10 users.

Build a record, without saving it

var user = build('User');
var user = build('User', { override: 'attributes' });

Use hooks for creating relationships

define('Account', Account)
  .hook('pre:save', function(obj, next) {
    if (!obj.get('owner')) { // if (!obj.owner) {
      factory('User', function(err, user) {
        if (err) return next(err);
        obj.set('owner', user);
        next();
      });
    } else {
      next();
    }
  })

Get model attributes from a factory

var attrs = attributes('User');

Install

$ npm install seed-forge

License

MIT License

Something went wrong with that request. Please try again.