Comparing version 1.3.0 to 1.3.1
@@ -1,2 +0,2 @@ | ||
/*! factory-js 1.3.0 */ | ||
/*! factory-js 1.3.1 */ | ||
var Factory, | ||
@@ -3,0 +3,0 @@ __hasProp = {}.hasOwnProperty, |
@@ -1,2 +0,2 @@ | ||
/*! factory-js 1.3.0 */ | ||
/*! factory-js 1.3.1 */ | ||
var Factory,__hasProp={}.hasOwnProperty,__extends=function(a,b){function c(){this.constructor=a}for(var d in b)__hasProp.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},__slice=[].slice;Factory=function(){function a(){}var b;return a.Adapter=b=function(){function a(a){this.factory=a}return a.prototype.build=function(a,b){return b},a.prototype.create=function(a,b){return b},a.prototype.push=function(a,b){return this[a].push(b)},a}(),a.factories={},a.adapter=a.Adapter,a.clear=function(){return this.factories={},this.adapter=a.Adapter},a.reset=function(){var a,b,c,d;c=this.factories,d=[];for(b in c)a=c[b],d.push(a.sequences={});return d},a.define=function(a,b){var c,d;if(c=new FactoryDefinition(a),"function"==typeof b)b.call(c);else for(d in b)c.attr(d,b[d]);return this.factories[a]=c},a.getFactory=function(a){var b;return b=this.factories[a],null!=b?b:{factory:function(){throw new Error('undefined factory "'+a+'"')}()}},a.getTrait=function(a,b){var c;return c=a.traits[b],null!=c?c:{trait:function(){throw new Error('undefined trait "'+b+'" for factory "'+this.name+'"')}.call(this)}},a.abstractBuild=function(a,b,c){var d,e,f,g,h;return b=b.split(/\s+/),f=b[0],e=this.getFactory(f),h=b.slice(1,+b.length+1||9e9).map(function(a){return function(b){return a.getTrait(e,b)}}(this)),d=e.attributes(c,h),g=e.build(a,f,d.withoutIgnored),h.unshift(e),h.map(function(a){return a.applyCallbacks(g,d.withIgnored)}),g},a.abstractBuildList=function(a,b,c,d){var e;return"number"==typeof c?function(){e=[];for(var a=0;0<=c?a<c:a>c;0<=c?a++:a--)e.push(a);return e}.apply(this).map(function(c){return function(){return c.abstractBuild(a,b,d)}}(this)):c instanceof Array?c.map(function(c){return function(e){return"string"==typeof e?c.abstractBuild(a,""+b+" "+e,d):e.constructor===Object?c.abstractBuild(a,b,c.hash.merge({},d,e)):e}}(this)):void 0},a.attributes=function(a,b){return this.abstractBuild("attributes",a,b)},a.build=function(a,b){return this.abstractBuild("build",a,b)},a.create=function(a,b){return this.abstractBuild("create",a,b)},a.buildList=function(a,b,c){return this.abstractBuildList("build",a,b,c)},a.createList=function(a,b,c){return this.abstractBuildList("create",a,b,c)},a.setupForEmber=function(b){if(null==b)throw new Error('undefined "'+b+'"');return a.EmberDataAdapter=function(a){function c(){return c.__super__.constructor.apply(this,arguments)}return __extends(c,a),c.prototype.build=function(a,c){return Ember.run(function(){return b.__container__.lookup("store:main").createRecord(a,c)})},c.prototype.create=function(a,b){return this.build(a,b)},c.prototype.push=function(a,b){return Ember.run(function(c){return function(){return c.get(a).addObject(b)}}(this))},c}(a.Adapter),a.adapter=a.EmberDataAdapter},a.hash={merge:function(){var a,b,c,d,e,f,g;for(a=arguments[0],d=2<=arguments.length?__slice.call(arguments,1):[],f=0,g=d.length;f<g;f++){c=d[f];for(b in c)e=c[b],a[b]=e}return a},evaluate:function(a){var b,c;c=[];for(b in a)c.push(a[b]="function"==typeof a[b]?a[b]():a[b]);return c}},a}(),("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=Factory:window.Factory=Factory;var FactoryDefinition;FactoryDefinition=function(){function a(a){this.name=a,this.buildAdapter=new Factory.adapter(this),this.attrs={},this.ignores={},this.sequences={},this.traits={},this.callbacks=[]}return a.prototype.adapter=function(a){return this.buildAdapter=new a(this),this},a.prototype.build=function(a,b,c){return this.buildAdapter[a]?this.buildAdapter[a](b,c):c},a.prototype.after=function(a){return this.callbacks.push(a),this},a.prototype.attr=function(a,b){return this.attrs[a]="function"==typeof b?b:function(){return b},this},a.prototype.hasMany=function(a,b){return this.ignore(a,[]),this.after(function(c,d){return this[a]instanceof Array||(this[a]=[]),Factory.buildList(b,c[a]).forEach(function(b){return function(c){return d.buildAdapter.push.call(b,a,c)}}(this))}),this},a.prototype.ignore=function(a,b){return this.ignores[a]="function"==typeof b?b:function(){return b},this},a.prototype.sequence=function(a,b){var c;return c=this,b=b||function(a){return a},this.attrs[a]=function(){return c.sequences[a]=c.sequences[a]||0,b.call(this,++c.sequences[a])},this},a.prototype.trait=function(b,c){var d;return d=new a(b),"function"==typeof c&&c.call(d),this.traits[b]=d,this},a.prototype.attributes=function(a,b){var c,d,e;d=Factory.hash.merge({},a),e={},b.forEach(function(a){var b,c;c=[];for(b in a.attrs)c.push(d[b]=a.attrs[b]);return c});for(c in this.attrs)d.hasOwnProperty(c)||(d[c]=this.attrs[c]);for(c in this.ignores)e[c]=d.hasOwnProperty(c)?d[c]:this.ignores[c],delete d[c];return Factory.hash.evaluate(d),Factory.hash.evaluate(e),{withIgnored:Factory.hash.merge({},d,e),withoutIgnored:d}},a.prototype.applyCallbacks=function(a,b){return this.callbacks.forEach(function(c){return function(d){return d.call(a,b,c)}}(this))},a}(); |
{ | ||
"name": "factory-js", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Building JavaScript objects inspired by rosie and factory_girl", | ||
"main": "./dist/factory.js", | ||
"license": "MIT", | ||
"author": "Tomasz Bak <t.bak@selleo.com>", | ||
"keywords": [ | ||
@@ -10,3 +14,12 @@ "factory", | ||
], | ||
"main": "./dist/factory.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/tb/factory-js" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/tb/factory-js/issues" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
}, | ||
"devDependencies": { | ||
@@ -24,6 +37,3 @@ "grunt": "~0.4.2", | ||
"chai": "~1.9.1" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
} | ||
} |
@@ -8,29 +8,23 @@ # Factory [![Build Status](https://travis-ci.org/tb/factory.svg)](https://travis-ci.org/tb/factory) | ||
## Setup for Ember.js | ||
Call `Factory.setupForEmber(App)` before factory definitions. See live example at [jsbin](http://emberjs.jsbin.com/serolule/edit) | ||
NOTE: You need to call `Factory.reset()` to reset sequences for each test run. | ||
## Usage | ||
Factory.define('vote', function() { | ||
this.sequence('id'); | ||
this.attr('value', 0); | ||
this.trait('up', function() { | ||
Factory | ||
.define('vote') | ||
.sequence('id'); | ||
.attr('value', 0); | ||
.trait('up', function() { | ||
return this.attr('value', 1); | ||
}); | ||
return this.trait('down', function() { | ||
this.trait('down', function() { | ||
return this.attr('value', -1); | ||
}); | ||
}); | ||
Factory.define('post', function() { | ||
this.sequence('id'); | ||
this.sequence('title', function(i) { | ||
Factory.define('post') | ||
.sequence('id'); | ||
.sequence('title', function(i) { | ||
return "Post " + i; | ||
}); | ||
this.attr('content', null); | ||
this.hasMany('votes', 'vote'); | ||
return this.after(function() { | ||
.attr('content', null); | ||
.hasMany('votes', 'vote'); | ||
.after(function() { | ||
if (!this.content) { | ||
@@ -40,18 +34,13 @@ return this.content = "" + this.title + " content"; | ||
}); | ||
}); | ||
Factory.define('category', function() { | ||
this.sequence('id'); | ||
this.sequence('name', function(i) { | ||
Factory.define('category') | ||
.sequence('id'); | ||
.sequence('name', function(i) { | ||
return "Category " + i; | ||
}); | ||
this.ignore('postsCount', 0); | ||
return this.after(function(attributes) { | ||
.ignore('postsCount', 0); | ||
.after(function(attributes) { | ||
return this.posts = Factory.buildList('post', attributes.postsCount); | ||
}); | ||
}); | ||
NOTE: looks better with CoffeeScript ;-) | ||
### Build with no attributes | ||
@@ -159,2 +148,8 @@ | ||
## Setup for Ember.js | ||
Call `Factory.setupForEmber(App)` before factory definitions. See live example at [jsbin](http://emberjs.jsbin.com/serolule/edit) | ||
NOTE: You need to call `Factory.reset()` to reset sequences for each test run. | ||
## Contributing | ||
@@ -161,0 +156,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
43093
1
0
158