Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "rosie", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "factory for building JavaScript objects, mostly useful for setting up test data. Inspired by factory_girl", | ||
@@ -11,3 +11,5 @@ "keywords": [ | ||
"author": "Brandon Keepers <brandon@opensoul.org>", | ||
"contributors": [], | ||
"contributors": [ | ||
"Brian Donovan <me@brian-donovan.com>" | ||
], | ||
"dependencies": {}, | ||
@@ -14,0 +16,0 @@ "devDependencies": { |
# Rosie | ||
[](https://travis-ci.org/rosiejs/rosie) | ||
 | ||
@@ -9,6 +11,6 @@ | ||
Define your factory, giving it a name and optionally a constructor function: | ||
Define your factory, giving it a name and optionally a constructor function (`Game` in this example): | ||
```js | ||
Factory.define('game', Game) | ||
Factory.define('game'/*, Game*/) | ||
.sequence('id') | ||
@@ -88,2 +90,51 @@ .attr('is_over', false) | ||
### Node.js | ||
To use Rosie in node, you'll need to require it first: | ||
```js | ||
var Factory = require('rosie').Factory; | ||
``` | ||
You might also choose to use unregistered factories, as it fits better with node's module pattern: | ||
```js | ||
// factories/game.js | ||
var Factory = require('rosie').Factory; | ||
module.exports = new Factory() | ||
.sequence('id') | ||
.attr('is_over', false) | ||
// etc | ||
``` | ||
To use the unregistered `Game` factory defined above: | ||
```js | ||
var Game = require('./factories/game'); | ||
var game = Game.build({is_over: true}); | ||
``` | ||
#### ES6 | ||
Unregistered factories are even more natural in ES6: | ||
```js | ||
// factories/game.js | ||
import { Factory } from 'rosie'; | ||
export default new Factory() | ||
.sequence('id') | ||
.attr('is_over', false) | ||
// etc | ||
// index.js | ||
import Game from './factories/game'); | ||
const game = Game.build({is_over: true}); | ||
``` | ||
A tool like [babel](https://babeljs.io) is currently required to use this syntax. | ||
## Contributing | ||
@@ -90,0 +141,0 @@ |
@@ -431,4 +431,8 @@ /** | ||
if (typeof exports !== 'undefined') { | ||
if (typeof exports === 'object' && typeof module !== 'undefined') { | ||
exports.Factory = Factory; | ||
} else if (typeof define === 'function' && define.amd) { | ||
define([], Factory); | ||
} else if (this) { | ||
this.Factory = Factory; | ||
} |
18533
407
151