UNPKG

1.45 kBJavaScriptView Raw
1'use strict';
2var DomainError, Fixture, FixtureLoader, debug;
3
4DomainError = require('./lib/domain-error');
5
6FixtureLoader = require('./fixture-loader');
7
8debug = null;
9
10
11/**
12load data from directory and generates fixtures
13only available in Node.js
14
15@class Fixture
16@module base-domain
17 */
18
19Fixture = (function() {
20
21 /**
22 @constructor
23 @param {Object} [options]
24 @param {String|Array} [options.dirname='./fixtures'] director(y|ies) to have fixture files. /data, /tsvs should be included in the directory.
25 @param {String} [options.debug] if true, shows debug log
26 */
27 function Fixture(facade, options) {
28 var debugMode, ref;
29 this.facade = facade;
30 if (options == null) {
31 options = {};
32 }
33 debugMode = (ref = options.debug) != null ? ref : !!this.facade.debug;
34 if (debugMode) {
35 require('debug').enable('base-domain:fixture');
36 }
37 debug = require('debug')('base-domain:fixture');
38 this.dirnames = options.dirname != null ? Array.isArray(options.dirname) ? options.dirname : [options.dirname] : [__dirname + '/fixtures'];
39 }
40
41
42 /**
43 inserts data to datasource
44
45 @method insert
46 @param {Array} names list of fixture models to insert data
47 @public
48 @return {Promise(EntityPool)}
49 */
50
51 Fixture.prototype.insert = function(names) {
52 return new FixtureLoader(this.facade, this.dirnames).load({
53 async: true,
54 names: names
55 });
56 };
57
58 return Fixture;
59
60})();
61
62module.exports = Fixture;