Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pack interface cleanup #633

Merged
merged 1 commit into from
Mar 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
3 changes: 1 addition & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
13 changes: 5 additions & 8 deletions test/integration/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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'); } });
Expand Down