From 28fd2b76bc225bf1dfe25cf89ffb08cea5da0611 Mon Sep 17 00:00:00 2001 From: Damon Oehlman Date: Sun, 17 Jun 2012 20:45:08 +1000 Subject: [PATCH] Added mapping of opts to the scaffolder object --- lib/scaffolder.js | 8 ++++++++ test/initialization.js | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/scaffolder.js b/lib/scaffolder.js index 796bd57..4728e64 100644 --- a/lib/scaffolder.js +++ b/lib/scaffolder.js @@ -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); diff --git a/test/initialization.js b/test/initialization.js index 17b6575..a7bff65 100644 --- a/test/initialization.js +++ b/test/initialization.js @@ -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) { @@ -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(); + }); + }); }); \ No newline at end of file