Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Factory builder for Mongoose & Seed

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG.md
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.md
Octocat-spinner-32 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)

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.