Skip to content

Commit

Permalink
Simplify methods with the new Generator.extend inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Dec 30, 2013
1 parent 63d9d51 commit 4788adf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
7 changes: 1 addition & 6 deletions lib/env/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ Store.prototype.getGeneratorsMeta = function getGeneratorsMeta () {

Store.prototype.normalizeGenerator = function normalizeGenerator (namespace, Generator) {
if (isRaw(Generator)) {
var newGenerator = function () {
Base.apply(this, arguments);
};
util.inherits(newGenerator, Base);
newGenerator.prototype.exec = Generator;
Generator = newGenerator;
Generator = Base.extend({ exec: Generator });
}
_.extend(Generator, this._meta[namespace]);
return Generator;
Expand Down
16 changes: 5 additions & 11 deletions lib/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,11 @@ helpers.mockPrompt = function (generator, answers) {
// Create a simple, dummy generator
//
helpers.createDummyGenerator = function () {
var dummy = function Dummy() {
generators.Base.apply(this, arguments);
};

util.inherits(dummy, generators.Base);

dummy.prototype.test = function () {
this.shouldRun = true;
};

return dummy;
return generators.Base.extend({
test: function () {
this.shouldRun = true;
}
});
};

// Create a generator, using the given dependencies and controller arguments
Expand Down
4 changes: 2 additions & 2 deletions test/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ var util = require('util');
var assert = require('assert');
var sinon = require('sinon');
var generators = require('..');
var Base = generators.Base;
var helpers = generators.test;
var events = require('events');
var TerminalAdapter = require('../lib/env/adapter');
var Base = generators.Base;
var Environment = require('../lib/env');
var Store = require('../lib/env/store');

Expand Down Expand Up @@ -315,7 +315,7 @@ describe('Environment', function () {
});

it('extend simple function with Base', function () {
assert.ok(this.env.get('dummy:simple').super_ === Base);
helpers.assertImplement(this.env.get('dummy:simple'), Base);
this.env.run('dummy:simple');
assert.ok(this.simpleDummy.calledOnce);
});
Expand Down

0 comments on commit 4788adf

Please sign in to comment.