From 91943cbbb583d6f9efe64d1fbba3783f3b8170b5 Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Mon, 4 Mar 2013 13:32:19 -0800 Subject: [PATCH] pack interface cleanup --- lib/defaults.js | 8 ++++++++ lib/pack.js | 2 +- lib/schema.js | 2 +- lib/server.js | 3 +-- test/integration/pack.js | 13 +++++-------- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/defaults.js b/lib/defaults.js index 6232e07c7..b4e9f5050 100755 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -58,6 +58,14 @@ exports.server = { server: null // Determines how long to wait for server request processing. Disabled by default }, + // Pack + + pack: { + name: 'default', // Default name + labels: [], // Default labels + autoLabel: true // Automatically add 'secure' and 'cached' labels + }, + // Optional components // false -> null, true -> defaults, {} -> override defaults diff --git a/lib/pack.js b/lib/pack.js index a97e93590..b2742baef 100755 --- a/lib/pack.js +++ b/lib/pack.js @@ -67,7 +67,7 @@ internals.Pack.prototype.server = function (name, server, options) { // Add standard labels - if (options.autoLabel !== false) { // Defaults to true + if (options.autoLabel) { if (server.settings.tls) { serverLabels.push('secure'); } diff --git a/lib/schema.js b/lib/schema.js index 19b233cbc..73b4ef503 100755 --- a/lib/schema.js +++ b/lib/schema.js @@ -155,5 +155,5 @@ internals.serverSchema = { }).allow(false).allow(true).optional()], app: T.Object().optional().nullOk(), plugins: T.Object().optional().nullOk(), - plugin: T.Object().optional().nullOk() + pack: T.Object().optional().nullOk() }; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index af49ecf2e..789298da0 100755 --- a/lib/server.js +++ b/lib/server.js @@ -278,8 +278,7 @@ internals.Server.prototype._plugin = function () { var Pack = require('./pack'); // Delayed required to avoid circular dependencies this._pack = new Pack(); - var options = this.settings.plugin; - this._pack.server((options && options.name) || 'default', this, options); + this._pack.server(this.settings.pack.name, this, this.settings.pack); this._pack.list = {}; return this._pack; }; diff --git a/test/integration/pack.js b/test/integration/pack.js index 8230ebe4c..d63e5eaa0 100755 --- a/test/integration/pack.js +++ b/test/integration/pack.js @@ -150,7 +150,7 @@ describe('Pack', function () { it('requires multiple plugins using array', function (done) { - var server = new Hapi.Server({ plugin: { labels: 'test' } }); + var server = new Hapi.Server({ pack: { labels: 'test' } }); server.plugin.require(['./pack/--test1', './pack/--test2'], function (err) { expect(err).to.not.exist; @@ -161,7 +161,7 @@ describe('Pack', function () { it('requires multiple plugins using object', function (done) { - var server = new Hapi.Server({ plugin: { labels: 'test' } }); + var server = new Hapi.Server({ pack: { labels: 'test' } }); server.plugin.require({ './pack/--test1': {}, './pack/--test2': {} }, function (err) { expect(err).to.not.exist; @@ -263,7 +263,7 @@ describe('Pack', function () { it('invalidates missing name', function (done) { var pack = new Hapi.Pack({ a: 1 }); - var err = pack.validate({ version: '0.0.0', hapi: { plugin: '1.x.x' }, register: function (pack, options, next) { next(); } }); + var err = pack.validate({ version: '0.0.0', register: function (pack, options, next) { next(); } }); expect(err).to.exist; expect(err.message).to.equal('Plugin missing name'); @@ -273,7 +273,7 @@ describe('Pack', function () { it('invalidates missing version', function (done) { var pack = new Hapi.Pack({ a: 1 }); - var err = pack.validate({ name: 'test', hapi: { plugin: '1.x.x' }, register: function (pack, options, next) { next(); } }); + var err = pack.validate({ name: 'test', register: function (pack, options, next) { next(); } }); expect(err).to.exist; expect(err.message).to.equal('Plugin missing version'); @@ -283,7 +283,7 @@ describe('Pack', function () { it('invalidates missing register method', function (done) { var pack = new Hapi.Pack({ a: 1 }); - var err = pack.validate({ name: 'test', version: '0.0.0', hapi: { plugin: '1.x.x' } }); + var err = pack.validate({ name: 'test', version: '0.0.0' }); expect(err).to.exist; expect(err.message).to.equal('Plugin missing register() method'); @@ -295,9 +295,6 @@ describe('Pack', function () { var plugin = { name: 'test', version: '3.0.0', - hapi: { - plugin: '1.x.x' - }, register: function (pack, options, next) { pack.route({ method: 'GET', path: '/b', handler: function () { this.reply('b'); } });