[Groonga-commit] groonga/express-droonga at 62a0bd8 [master] Rename "model" to "command"

アーカイブの一覧に戻る

YUKI Hiroshi null+****@clear*****
Thu Aug 1 11:56:32 JST 2013


YUKI Hiroshi	2013-08-01 11:56:32 +0900 (Thu, 01 Aug 2013)

  New Revision: 62a0bd85c279ac9100a72c8da7afab80de7783da
  https://github.com/groonga/express-droonga/commit/62a0bd85c279ac9100a72c8da7afab80de7783da

  Message:
    Rename "model" to "command"

  Modified files:
    lib/adapter/api/groonga.js
    lib/adapter/api/rest.js
    lib/adapter/api/socket.io.js
    lib/adapter/http.js
    lib/adapter/socket.io.js
    test/adapter/rest.test.js
    test/adapter/socket.io.test.js
    test/express-adapter.test.js
  Renamed files:
    lib/adapter/command.js
      (from lib/adapter/api/model.js)

  Modified: lib/adapter/api/groonga.js (+2 -2)
===================================================================
--- lib/adapter/api/groonga.js    2013-07-31 18:49:00 +0900 (f7dbf3b)
+++ lib/adapter/api/groonga.js    2013-08-01 11:56:32 +0900 (2f660f1)
@@ -1,7 +1,7 @@
-var model = require('./model');
+var command = require('../command');
 
 module.exports = {
-  'groonga': new model.HTTPCommand({
+  'groonga': new command.HTTPCommand({
     path: '/d/:commandName',
     requestConverter: function(commandName, request) {
       return [request.params.commandName, request.query];

  Modified: lib/adapter/api/rest.js (+9 -9)
===================================================================
--- lib/adapter/api/rest.js    2013-07-31 18:49:00 +0900 (79337a0)
+++ lib/adapter/api/rest.js    2013-08-01 11:56:32 +0900 (a17627a)
@@ -1,43 +1,43 @@
-var model = require('./model');
+var command = require('../command');
 var requestBuilders = require('./rest-request-builder');
 
 module.exports = {
-//  'status': new model.HTTPCommand({
+//  'status': new command.HTTPCommand({
 //    path: '/status/:target',
 //    requestConverter: requestBuilders.status
 //  }),
-  'search': new model.HTTPCommand({
+  'search': new command.HTTPCommand({
     path: '/tables/:tableName',
     requestConverter: function(event, request) {
       return [event, requestBuilders.search(request)];
     }
   }) //,
-//  'createtable': new model.HTTPCommand({
+//  'createtable': new command.HTTPCommand({
 //    method: 'PUT',
 //    path: '/tables/:tableName',
 //    requestConverter: requestBuilders.createTable
 //  }),
-//  'removetable': new model.HTTPCommand({
+//  'removetable': new command.HTTPCommand({
 //    method: 'DELETE',
 //    path: '/tables/:tableName',
 //    requestConverter: requestBuilders.removeTable
 //  }),
-//  'createcolumn': new model.HTTPCommand({
+//  'createcolumn': new command.HTTPCommand({
 //    method: 'PUT',
 //    path: '/tables/:tableName/columns/:columnName',
 //    requestConverter: requestBuilders.createColumn
 //  }),
-//  'removecolumn': new model.HTTPCommand({
+//  'removecolumn': new command.HTTPCommand({
 //    method: 'DELETE',
 //    path: '/tables/:tableName/columns/:columnName',
 //    requestConverter: requestBuilders.removeColumn
 //  }),
-//  'loadrecord': new model.HTTPCommand({
+//  'loadrecord': new command.HTTPCommand({
 //    method: 'PUT',
 //    path: '/tables/:tableName/records/:key',
 //    requestConverter: requestBuilders.loadRecord
 //  }),
-//  'loadrecords': new model.HTTPCommand({
+//  'loadrecords': new command.HTTPCommand({
 //    method: 'PUT',
 //    path: '/tables/:tableName/records',
 //    requestConverter: requestBuilders.loadRecords

  Modified: lib/adapter/api/socket.io.js (+2 -2)
===================================================================
--- lib/adapter/api/socket.io.js    2013-07-31 18:49:00 +0900 (ae46165)
+++ lib/adapter/api/socket.io.js    2013-08-01 11:56:32 +0900 (e77119d)
@@ -1,8 +1,8 @@
-var model = require('./model');
+var command = require('../command');
 
 module.exports = {
 //  'status': {},
-  'search': new model.SocketRequestResponse()//,
+  'search': new command.SocketRequestResponse()//,
 //  'createtable': {},
 //  'removetable': {},
 //  'createcolumn': {},

  Renamed: lib/adapter/command.js (+31 -23) 55%
===================================================================
--- lib/adapter/api/model.js    2013-07-31 18:49:00 +0900 (8d4d300)
+++ lib/adapter/command.js    2013-08-01 11:56:32 +0900 (854967b)
@@ -1,52 +1,60 @@
-function CommandModel(options) {
+var util = require('util');
+
+function Command(options) {
   this._options = options || {};
-  this._modelTypes = [];
+  this._commandTypes = [];
 }
-CommandModel.prototype = {
+Command.prototype = {
   get requestConverter() {
     return this._options.requestConverter;
   },
   get responseConverter() {
     return this._options.responseConverter;
+  },
+  isInstanceOf: function(commandType) {
+    return (
+      commandType &&
+      this._commandTypes.indexOf(commandType) > -1
+    );
   }
 };
-CommandModel.isInstance = function(modelInstance) {
+Command.isInstance = function(modelInstance) {
   return (
     modelInstance &&
-    modelInstance._modelTypes &&
-    modelInstance._modelTypes.indexOf(this) > -1
+    modelInstance._commandTypes &&
+    modelInstance._commandTypes.indexOf(this) > -1
   );
 };
 
 
 function RequestResponse(options) {
-  CommandModel.apply(this, arguments);
-  this._modelTypes.push(RequestResponse);
+  Command.apply(this, arguments);
+  this._commandTypes.push(RequestResponse);
 }
-RequestResponse.prototype = new CommandModel();
-RequestResponse.isInstance = CommandModel.isInstance;
+util.inherits(RequestResponse, Command);
+RequestResponse.isInstance = Command.isInstance;
 exports.RequestResponse = RequestResponse;
 
 
 function PublishSubscribe(options) {
-  CommandModel.apply(this, arguments);
-  this._modelTypes.push(PublishSubscribe);
+  Command.apply(this, arguments);
+  this._commandTypes.push(PublishSubscribe);
 }
-PublishSubscribe.prototype = new CommandModel();
-PublishSubscribe.isInstance = CommandModel.isInstance;
+util.inherits(PublishSubscribe, Command);
+PublishSubscribe.isInstance = Command.isInstance;
 exports.PublishSubscribe = PublishSubscribe;
 
 
 
 function HTTPCommand(options) {
   RequestResponse.apply(this, arguments);
-  this._modelTypes.push(HTTPCommand);
+  this._commandTypes.push(HTTPCommand);
   // default handler
   this._options.requestConverter = this._options.requestConverter || function(event, request) {
     return [event, {}];
   };
 }
-HTTPCommand.prototype = new RequestResponse();
+util.inherits(HTTPCommand, RequestResponse);
 HTTPCommand.isInstance = RequestResponse.isInstance;
 Object.defineProperty(HTTPCommand.prototype, 'path', {
   get: function() { return this._options.path; }
@@ -60,25 +68,25 @@ exports.HTTPCommand = HTTPCommand;
 
 function SocketCommand() {
 }
-SocketCommand.isInstance = CommandModel.isInstance;
+SocketCommand.isInstance = Command.isInstance;
 exports.SocketCommand = SocketCommand;
 
 
 function SocketRequestResponse(options) {
   RequestResponse.apply(this, arguments);
-  this._modelTypes.push(SocketCommand);
-  this._modelTypes.push(SocketRequestResponse);
+  this._commandTypes.push(SocketCommand);
+  this._commandTypes.push(SocketRequestResponse);
 }
-SocketRequestResponse.prototype = new RequestResponse();
+util.inherits(SocketRequestResponse, RequestResponse);
 SocketRequestResponse.isInstance = RequestResponse.isInstance;
 exports.SocketRequestResponse = SocketRequestResponse;
 
 
 function SocketPublishSubscribe(options) {
   PublishSubscribe.apply(this, arguments);
-  this._modelTypes.push(SocketCommand);
-  this._modelTypes.push(SocketPublishSubscribe);
+  this._commandTypes.push(SocketCommand);
+  this._commandTypes.push(SocketPublishSubscribe);
 }
-SocketPublishSubscribe.prototype = new PublishSubscribe();
+util.inherits(SocketPublishSubscribe, PublishSubscribe);
 SocketRequestResponse.isInstance = PublishSubscribe.isInstance;
 exports.SocketPublishSubscribe = SocketPublishSubscribe;

  Modified: lib/adapter/http.js (+3 -3)
===================================================================
--- lib/adapter/http.js    2013-07-31 18:49:00 +0900 (6331dcb)
+++ lib/adapter/http.js    2013-08-01 11:56:32 +0900 (1dbe30b)
@@ -1,6 +1,6 @@
 var debug = require('../debug');
 
-var model = require('./api/model');
+var command = require('./command');
 var restAPI = require('./api/rest');
 var groongaAPI = require('./api/groonga');
 
@@ -71,7 +71,7 @@ exports.register = function(application, params) {
   commandSets.forEach(function(commandSet) {
     Object.keys(commandSet).forEach(function(commandName) {
       var definition = commandSet[commandName];
-      if (!model.HTTPCommand.isInstance(definition))
+      if (!command.HTTPCommand.isInstance(definition))
         return;
       unifiedCommandSet[commandName] = definition;
     });
@@ -80,7 +80,7 @@ exports.register = function(application, params) {
   var registeredCommands = [];
   Object.keys(unifiedCommandSet).forEach(function(commandName) {
     var definition = unifiedCommandSet[commandName];
-    if (!model.HTTPCommand.isInstance(definition))
+    if (!command.HTTPCommand.isInstance(definition))
       return;
     var method = getRegisterationMethod(definition.method);
     var handler = createHandler({

  Modified: lib/adapter/socket.io.js (+6 -6)
===================================================================
--- lib/adapter/socket.io.js    2013-07-31 18:49:00 +0900 (4488230)
+++ lib/adapter/socket.io.js    2013-08-01 11:56:32 +0900 (f3b1696)
@@ -1,5 +1,5 @@
 var socketIo = require('socket.io');
-var model = require('./api/model');
+var command = require('./command');
 var defaultAPI = require('./api/socket.io');
 
 var DEFAULT_TIMEOUT = 10 * 1000;
@@ -54,7 +54,7 @@ exports.register = function(application, server, params) {
 
       var callback = null;
       var options = {};
-      if (model.RequestResponse.isInstance(commandDefinition)) {
+      if (command.RequestResponse.isInstance(commandDefinition)) {
         callback = function(error, envelope) {
           if (error) {
             socket.emit('error', error);
@@ -76,7 +76,7 @@ exports.register = function(application, server, params) {
           socket.emit(responseEvent, responseData);
         };
         options.timeout = DEFAULT_TIMEOUT;
-      } else if (model.PublishSubscribe.isInstance(commandDefinition)) {
+      } else if (command.PublishSubscribe.isInstance(commandDefinition)) {
         event += '.subscribe';
       }
 
@@ -113,7 +113,7 @@ exports.register = function(application, server, params) {
   commandSets.forEach(function(commandSet) {
     Object.keys(commandSet).forEach(function(commandName) {
       var definition = commandSet[commandName];
-      if (!model.SocketCommand.isInstance(definition))
+      if (!command.SocketCommand.isInstance(definition))
         return;
       unifiedCommandSet[commandName] = definition;
     });
@@ -122,7 +122,7 @@ exports.register = function(application, server, params) {
   var registeredCommands = [];
   Object.keys(unifiedCommandSet).forEach(function(commandName) {
     var definition = unifiedCommandSet[commandName];
-    if (!model.SocketCommand.isInstance(definition))
+    if (!command.SocketCommand.isInstance(definition))
       return;
     registeredCommands.push({ name:       commandName,
                               definition: definition });
@@ -135,7 +135,7 @@ exports.register = function(application, server, params) {
     var events = [];
     var handlers = {};
     registeredCommands.forEach(function(command) {
-      if (model.PublishSubscribe.isInstance(command.definition)) {
+      if (command.PublishSubscribe.isInstance(command.definition)) {
         socket.on(command.name + '.subscribe',
                   createClientMessageHandler(command.name, socket));
 

  Modified: test/adapter/rest.test.js (+9 -9)
===================================================================
--- test/adapter/rest.test.js    2013-07-31 18:49:00 +0900 (df53cd9)
+++ test/adapter/rest.test.js    2013-08-01 11:56:32 +0900 (c65ef7e)
@@ -6,36 +6,36 @@ var utils = require('../test-utils');
 
 var express = require('express');
 var httpAdapter = require('../../lib/adapter/http');
-var model = require('../../lib/adapter/api/model');
+var command = require('../../lib/adapter/command');
 var restAPI = require('../../lib/adapter/api/rest');
 var groongaAPI = require('../../lib/adapter/api/groonga');
 
 suite('HTTP Adapter', function() {
   test('registeration of plugin commands', function() {
     var basePlugin = {
-      getCommand: new model.HTTPCommand({
+      getCommand: new command.HTTPCommand({
         path: '/get'
       }),
-      putCommand: new model.HTTPCommand({
+      putCommand: new command.HTTPCommand({
         method: 'PUT',
         path: '/put'
       }),
-      postCommand: new model.HTTPCommand({
+      postCommand: new command.HTTPCommand({
         method: 'POST',
         path: '/post'
       }),
-      deleteCommand: new model.HTTPCommand({
+      deleteCommand: new command.HTTPCommand({
         method: 'DELETE',
         path: '/delete'
       }),
-      ignored: new model.SocketCommand()
+      ignored: new command.SocketCommand()
     };
     var overridingPlugin = {
-      postCommand: new model.HTTPCommand({
+      postCommand: new command.HTTPCommand({
         method: 'POST',
         path: '/post/overridden'
       }),
-      deleteCommand: new model.HTTPCommand({
+      deleteCommand: new command.HTTPCommand({
         method: 'DELETE',
         path: '/delete/overridden'
       })
@@ -74,7 +74,7 @@ suite('HTTP Adapter', function() {
 
   suite('registeration', function() {
     var testPlugin = {
-      adapter: new model.HTTPCommand({
+      adapter: new command.HTTPCommand({
         path: '/path/to/adapter',
         requestConverter: function(event, request) { return [event, 'adapter requested']; },
         responseConverter: function(event, data) { return [event, 'adapter OK']; }

  Modified: test/adapter/socket.io.test.js (+14 -14)
===================================================================
--- test/adapter/socket.io.test.js    2013-07-31 18:49:00 +0900 (8761562)
+++ test/adapter/socket.io.test.js    2013-08-01 11:56:32 +0900 (8bd3f2d)
@@ -6,7 +6,7 @@ var express = require('express');
 var utils = require('../test-utils');
 
 var socketIoAdapter = require('../../lib/adapter/socket.io');
-var model = require('../../lib/adapter/api/model');
+var command = require('../../lib/adapter/command');
 var scoketIoAPI = require('../../lib/adapter/api/socket.io');
 
 suite('Socket.IO Adapter', function() {
@@ -16,21 +16,21 @@ suite('Socket.IO Adapter', function() {
   var backend;
 
   var testPlugin = {
-    'reqrep': new model.SocketRequestResponse(),
-    'reqrep-mod-event': new model.SocketRequestResponse({
+    'reqrep': new command.SocketRequestResponse(),
+    'reqrep-mod-event': new command.SocketRequestResponse({
       requestConverter: function(event, data) { return [event + '.mod', data]; },
       responseConverter: function(event, data) { return [event + '.mod', data]; }
     }),
-    'reqrep-mod-body': new model.SocketRequestResponse({
+    'reqrep-mod-body': new command.SocketRequestResponse({
       requestConverter: function(event, data) { return [event, 'modified request']; },
       responseConverter: function(event, data) { return [event, 'modified response']; }
     }),
-    'pubsub': new model.SocketPublishSubscribe(),
-    'pubsub-mod-event': new model.SocketPublishSubscribe({
+    'pubsub': new command.SocketPublishSubscribe(),
+    'pubsub-mod-event': new command.SocketPublishSubscribe({
       requestConverter: function(event, data) { return [event + '.mod', data]; },
       responseConverter: function(event, data) { return [event + '.mod', data]; }
     }),
-    'pubsub-mod-body': new model.SocketPublishSubscribe({
+    'pubsub-mod-body': new command.SocketPublishSubscribe({
       requestConverter: function(event, data) { return [event, 'modified request']; },
       responseConverter: function(event, data) { return [event, 'modified response']; }
     })
@@ -53,15 +53,15 @@ suite('Socket.IO Adapter', function() {
 
   test('registration of plugin commands', function(done) {
     var basePlugin = {
-      getCommand: new model.SocketRequestResponse(),
-      putCommand: new model.SocketRequestResponse(),
-      postCommand: new model.SocketRequestResponse(),
-      deleteCommand: new model.SocketRequestResponse(),
-      ignored: new model.HTTPCommand()
+      getCommand: new command.SocketRequestResponse(),
+      putCommand: new command.SocketRequestResponse(),
+      postCommand: new command.SocketRequestResponse(),
+      deleteCommand: new command.SocketRequestResponse(),
+      ignored: new command.HTTPCommand()
     };
     var overridingPlugin = {
-      postCommand: new model.SocketRequestResponse(),
-      deleteCommand: new model.SocketRequestResponse()
+      postCommand: new command.SocketRequestResponse(),
+      deleteCommand: new command.SocketRequestResponse()
     };
 
     var application = express();

  Modified: test/express-adapter.test.js (+3 -3)
===================================================================
--- test/express-adapter.test.js    2013-07-31 18:49:00 +0900 (fe67f3c)
+++ test/express-adapter.test.js    2013-08-01 11:56:32 +0900 (7fc9902)
@@ -6,18 +6,18 @@ var express = require('express');
 var utils = require('./test-utils');
 
 var adapter = require('../index');
-var model = require('../lib/adapter/api/model');
+var command = require('../lib/adapter/command');
 
 suite('Adaption for express application', function() {
   var testRestPlugin = {
-    api: new model.HTTPCommand({
+    api: new command.HTTPCommand({
       path: '/path/to/api',
       requestConverter: function(event, request) { return [event, 'api requested']; },
       responseConverter: function(event, data) { return [event, 'api OK']; }
     })
   };
   var testSocketPlugin = {
-    api: new model.SocketRequestResponse({
+    api: new command.SocketRequestResponse({
       requestConverter: function(event, data) { return [event, 'api requested']; },
       responseConverter: function(event, data) { return [event, 'api OK']; }
     })
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る