Kouhei Sutou
null+****@clear*****
Mon Jul 22 23:21:29 JST 2013
Kouhei Sutou 2013-07-22 23:21:29 +0900 (Mon, 22 Jul 2013) New Revision: 8824cfda364d678513bdfb52340823ad4f917fc8 https://github.com/groonga/express-droonga/commit/8824cfda364d678513bdfb52340823ad4f917fc8 Message: model.REST -> model.HTTPCommand Because the model should handle all generic HTTP commands. Modified files: lib/adapter/api/rest.js lib/adapter/http.js lib/model.js test/adapter/rest.test.js test/adapter/socket.io.test.js test/express-adapter.test.js Modified: lib/adapter/api/rest.js (+8 -8) =================================================================== --- lib/adapter/api/rest.js 2013-07-22 23:04:09 +0900 (30a003e) +++ lib/adapter/api/rest.js 2013-07-22 23:21:29 +0900 (02ecb7f) @@ -2,42 +2,42 @@ var model = require('../../model'); var requestBuilders = require('./rest-request-builder'); module.exports = { -// 'status': new model.REST({ +// 'status': new model.HTTPCommand({ // path: '/status/:target', // toBackend: requestBuilders.status // }), - 'search': new model.REST({ + 'search': new model.HTTPCommand({ path: '/tables/:tableName', toBackend: function(event, request) { return [event, requestBuilders.search(request)]; } }) //, -// 'createtable': new model.REST({ +// 'createtable': new model.HTTPCommand({ // method: 'PUT', // path: '/tables/:tableName', // toBackend: requestBuilders.createTable // }), -// 'removetable': new model.REST({ +// 'removetable': new model.HTTPCommand({ // method: 'DELETE', // path: '/tables/:tableName', // toBackend: requestBuilders.removeTable // }), -// 'createcolumn': new model.REST({ +// 'createcolumn': new model.HTTPCommand({ // method: 'PUT', // path: '/tables/:tableName/columns/:columnName', // toBackend: requestBuilders.createColumn // }), -// 'removecolumn': new model.REST({ +// 'removecolumn': new model.HTTPCommand({ // method: 'DELETE', // path: '/tables/:tableName/columns/:columnName', // toBackend: requestBuilders.removeColumn // }), -// 'loadrecord': new model.REST({ +// 'loadrecord': new model.HTTPCommand({ // method: 'PUT', // path: '/tables/:tableName/records/:key', // toBackend: requestBuilders.loadRecord // }), -// 'loadrecords': new model.REST({ +// 'loadrecords': new model.HTTPCommand({ // method: 'PUT', // path: '/tables/:tableName/records', // toBackend: requestBuilders.loadRecords Modified: lib/adapter/http.js (+2 -2) =================================================================== --- lib/adapter/http.js 2013-07-22 23:04:09 +0900 (81e1ad0) +++ lib/adapter/http.js 2013-07-22 23:21:29 +0900 (a2415d7) @@ -70,7 +70,7 @@ exports.register = function(application, params) { commandSets.forEach(function(commandSet) { Object.keys(commandSet).forEach(function(commandName) { var definition = commandSet[commandName]; - if (!model.REST.isInstance(definition)) + if (!model.HTTPCommand.isInstance(definition)) return; unifiedCommandSet[commandName] = definition; }); @@ -79,7 +79,7 @@ exports.register = function(application, params) { var registeredCommands = []; Object.keys(unifiedCommandSet).forEach(function(commandName) { var definition = unifiedCommandSet[commandName]; - if (!model.REST.isInstance(definition)) + if (!model.HTTPCommand.isInstance(definition)) return; var method = getRegisterationMethod(definition.method); var handler = createHandler({ Modified: lib/model.js (+7 -7) =================================================================== --- lib/model.js 2013-07-22 23:04:09 +0900 (7a0f087) +++ lib/model.js 2013-07-22 23:21:29 +0900 (7f38255) @@ -38,23 +38,23 @@ exports.PublishSubscribe = PublishSubscribe; -function REST(options) { +function HTTPCommand(options) { RequestResponse.apply(this, arguments); - this._modelTypes.push(REST); + this._modelTypes.push(HTTPCommand); // default handler this._options.toBackend = this._options.toBackend || function(event, request) { return [event, {}]; }; } -REST.prototype = new RequestResponse(); -REST.isInstance = RequestResponse.isInstance; -Object.defineProperty(REST.prototype, 'path', { +HTTPCommand.prototype = new RequestResponse(); +HTTPCommand.isInstance = RequestResponse.isInstance; +Object.defineProperty(HTTPCommand.prototype, 'path', { get: function() { return this._options.path; } }); -Object.defineProperty(REST.prototype, 'method', { +Object.defineProperty(HTTPCommand.prototype, 'method', { get: function() { return this._options.method || 'GET'; } }); -exports.REST = REST; +exports.HTTPCommand = HTTPCommand; Modified: test/adapter/rest.test.js (+7 -7) =================================================================== --- test/adapter/rest.test.js 2013-07-22 23:04:09 +0900 (817016a) +++ test/adapter/rest.test.js 2013-07-22 23:21:29 +0900 (1e93d17) @@ -12,29 +12,29 @@ var restAPI = require('../../lib/adapter/api/rest'); suite('HTTP Adapter', function() { test('registeration of plugin commands', function() { var basePlugin = { - getCommand: new model.REST({ + getCommand: new model.HTTPCommand({ path: '/get' }), - putCommand: new model.REST({ + putCommand: new model.HTTPCommand({ method: 'PUT', path: '/put' }), - postCommand: new model.REST({ + postCommand: new model.HTTPCommand({ method: 'POST', path: '/post' }), - deleteCommand: new model.REST({ + deleteCommand: new model.HTTPCommand({ method: 'DELETE', path: '/delete' }), ignored: new model.SocketCommand() }; var overridingPlugin = { - postCommand: new model.REST({ + postCommand: new model.HTTPCommand({ method: 'POST', path: '/post/overridden' }), - deleteCommand: new model.REST({ + deleteCommand: new model.HTTPCommand({ method: 'DELETE', path: '/delete/overridden' }) @@ -71,7 +71,7 @@ suite('HTTP Adapter', function() { suite('registeration', function() { var testPlugin = { - adapter: new model.REST({ + adapter: new model.HTTPCommand({ path: '/path/to/adapter', toBackend: function(event, request) { return [event, 'adapter requested']; }, toClient: function(event, data) { return [event, 'adapter OK']; } Modified: test/adapter/socket.io.test.js (+1 -1) =================================================================== --- test/adapter/socket.io.test.js 2013-07-22 23:04:09 +0900 (6bb8daf) +++ test/adapter/socket.io.test.js 2013-07-22 23:21:29 +0900 (a38e22b) @@ -58,7 +58,7 @@ suite('Socket.IO Adapter', function() { putCommand: new model.SocketRequestResponse(), postCommand: new model.SocketRequestResponse(), deleteCommand: new model.SocketRequestResponse(), - ignored: new model.REST() + ignored: new model.HTTPCommand() }; var overridingPlugin = { postCommand: new model.SocketRequestResponse(), Modified: test/express-adapter.test.js (+1 -1) =================================================================== --- test/express-adapter.test.js 2013-07-22 23:04:09 +0900 (54b9bcd) +++ test/express-adapter.test.js 2013-07-22 23:21:29 +0900 (31abd92) @@ -10,7 +10,7 @@ var model = require('../lib/model'); suite('Adaption for express application', function() { var testRestPlugin = { - api: new model.REST({ + api: new model.HTTPCommand({ path: '/path/to/api', toBackend: function(event, request) { return [event, 'api requested']; }, toClient: function(event, data) { return [event, 'api OK']; } -------------- next part -------------- HTML����������������������������...Download