Skip to content

Commit

Permalink
Added mapping of opts to the scaffolder object
Browse files Browse the repository at this point in the history
  • Loading branch information
Damon Oehlman committed Jun 17, 2012
1 parent 13b756c commit 28fd2b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/scaffolder.js
Expand Up @@ -48,6 +48,14 @@ function Scaffolder(opts) {
// create the out helper function
this.out = opts.silent ? function() {} : out;

// map the opts to the scaffolder which can allow objects to access
for (var key in opts) {
// only map if it doesn't already exist in the object or the prototype
if (typeof this[key] == 'undefined') {
this[key] = opts[key];
}
}

// if we have a target module, then find the package
if (this.targetModule) {
debug('crawling tree to find package.json, starting at: ' + this.targetModule.filename);
Expand Down
23 changes: 22 additions & 1 deletion test/initialization.js
Expand Up @@ -5,7 +5,8 @@ var scaffolder = require('../'),
scaffolderOpts = {
argv: [],
silent: true
};
},
_ = require('underscore');

describe('scaffolder initialization tests', function() {
it('should be able to detect the package path for the current app', function(done) {
Expand All @@ -14,4 +15,24 @@ describe('scaffolder initialization tests', function() {
done();
});
});

it('should be able to map an object onto the scaffolder', function(done) {
var s = scaffolder(_.extend({ test: true }, scaffolderOpts));
s.on('ready', function() {
expect(this.test).to.equal(true);
done();
});
});

it('should be able to map an function onto the scaffolder', function(done) {
var s = scaffolder(_.extend({
test: function() { return true; }
}, scaffolderOpts));

s.on('ready', function() {
expect(typeof this.test).to.equal('function');
expect(this.test()).to.equal(true);
done();
});
});
});

0 comments on commit 28fd2b7

Please sign in to comment.