[Groonga-commit] groonga/express-kotoumi [master] Rename too short method: model.isA => model.(class).isInstance

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Feb 8 14:59:06 JST 2013


YUKI Hiroshi	2013-02-08 14:59:06 +0900 (Fri, 08 Feb 2013)

  New Revision: 9a74a42e1c83e1d499b6b071eb515e9799d90753
  https://github.com/groonga/express-kotoumi/commit/9a74a42e1c83e1d499b6b071eb515e9799d90753

  Log:
    Rename too short method: model.isA => model.(class).isInstance

  Modified files:
    lib/frontend/rest-adaptor.js
    lib/frontend/socket.io-adaptor.js
    lib/model.js
    test/test-utils.js

  Modified: lib/frontend/rest-adaptor.js (+2 -2)
===================================================================
--- lib/frontend/rest-adaptor.js    2013-02-07 19:32:16 +0900 (bd9281e)
+++ lib/frontend/rest-adaptor.js    2013-02-08 14:59:06 +0900 (161df48)
@@ -64,7 +64,7 @@ exports.register = function(application, params) {
   commandSets.forEach(function(commandSet) {
     Object.keys(commandSet).forEach(function(commandName) {
       var definition = commandSet[commandName];
-      if (!model.isA(definition, model.REST))
+      if (!model.REST.isInstance(definition))
         return;
       unifiedCommandSet[commandName] = definition;
     });
@@ -73,7 +73,7 @@ exports.register = function(application, params) {
   var registeredCommands = [];
   Object.keys(unifiedCommandSet).forEach(function(commandName) {
     var definition = unifiedCommandSet[commandName];
-    if (!model.isA(definition, model.REST))
+    if (!model.REST.isInstance(definition))
       return;
     var method = getRegisterationMethod(definition.method);
     var handler = createHandler({

  Modified: lib/frontend/socket.io-adaptor.js (+4 -4)
===================================================================
--- lib/frontend/socket.io-adaptor.js    2013-02-07 19:32:16 +0900 (01ca4f7)
+++ lib/frontend/socket.io-adaptor.js    2013-02-08 14:59:06 +0900 (505f56a)
@@ -44,7 +44,7 @@ exports.register = function(application, server, params) {
 
       var callback = null;
       var options = {};
-      if (model.isA(commandDefinition, model.RequestResponse)) {
+      if (model.RequestResponse.isInstance(commandDefinition)) {
         callback = function(envelope) {
           var event = envelope.type;
           var data = envelope.body;
@@ -92,7 +92,7 @@ exports.register = function(application, server, params) {
   commandSets.forEach(function(commandSet) {
     Object.keys(commandSet).forEach(function(commandName) {
       var definition = commandSet[commandName];
-      if (!model.isA(definition, model.SocketCommand))
+      if (!model.SocketCommand.isInstance(definition))
         return;
       unifiedCommandSet[commandName] = definition;
     });
@@ -101,7 +101,7 @@ exports.register = function(application, server, params) {
   var registeredCommands = [];
   Object.keys(unifiedCommandSet).forEach(function(commandName) {
     var definition = unifiedCommandSet[commandName];
-    if (!model.isA(definition, model.SocketCommand))
+    if (!model.SocketCommand.isInstance(definition))
       return;
     registeredCommands.push({ name:       commandName,
                               definition: definition });
@@ -116,7 +116,7 @@ exports.register = function(application, server, params) {
       socket.on(command.name,
                 createClientMessageHandler(command.name, socket));
 
-      if (model.isA(command.definition, model.PublishSubscribe)) {
+      if (model.PublishSubscribe.isInstance(command.definition)) {
         var publishedMessageHandler = createPublishedMessageHandler(command.name, socket);
         connection.on(command.name, publishedMessageHandler);
       }

  Modified: lib/model.js (+8 -5)
===================================================================
--- lib/model.js    2013-02-07 19:32:16 +0900 (e47e2bd)
+++ lib/model.js    2013-02-08 14:59:06 +0900 (d14ad8e)
@@ -10,15 +10,13 @@ CommandModel.prototype = {
     return this._options.toClient;
   }
 };
-
-function isA(modelInstance, modelType) {
+CommandModel.isInstance = function(modelInstance) {
   return (
     modelInstance &&
     modelInstance._modelTypes &&
-    modelInstance._modelTypes.indexOf(modelType) > -1
+    modelInstance._modelTypes.indexOf(this) > -1
   );
-}
-exports.isA = isA;
+};
 
 
 function RequestResponse(options) {
@@ -26,6 +24,7 @@ function RequestResponse(options) {
   this._modelTypes.push(RequestResponse);
 }
 RequestResponse.prototype = new CommandModel();
+RequestResponse.isInstance = CommandModel.isInstance;
 exports.RequestResponse = RequestResponse;
 
 
@@ -34,6 +33,7 @@ function PublishSubscribe(options) {
   this._modelTypes.push(PublishSubscribe);
 }
 PublishSubscribe.prototype = new CommandModel();
+PublishSubscribe.isInstance = CommandModel.isInstance;
 exports.PublishSubscribe = PublishSubscribe;
 
 
@@ -47,6 +47,7 @@ function REST(options) {
   };
 }
 REST.prototype = new RequestResponse();
+REST.isInstance = RequestResponse.isInstance;
 Object.defineProperty(REST.prototype, 'path', {
   get: function() { return this._options.path; }
 });
@@ -68,6 +69,7 @@ function SocketRequestResponse(options) {
   this._modelTypes.push(SocketRequestResponse);
 }
 SocketRequestResponse.prototype = new RequestResponse();
+SocketRequestResponse.isInstance = RequestResponse.isInstance;
 exports.SocketRequestResponse = SocketRequestResponse;
 
 
@@ -77,4 +79,5 @@ function SocketPublishSubscribe(options) {
   this._modelTypes.push(SocketPublishSubscribe);
 }
 SocketPublishSubscribe.prototype = new PublishSubscribe();
+SocketRequestResponse.isInstance = PublishSubscribe.isInstance;
 exports.SocketPublishSubscribe = SocketPublishSubscribe;

  Modified: test/test-utils.js (+1 -1)
===================================================================
--- test/test-utils.js    2013-02-07 19:32:16 +0900 (27bf02f)
+++ test/test-utils.js    2013-02-08 14:59:06 +0900 (f73eb66)
@@ -144,7 +144,7 @@ function createMockedBackendConnection(socketCommands) {
   var onMessageControllers = {};
   Object.keys(socketCommands).forEach(function(commandName) {
     var command = socketCommands[commandName];
-    if (model.isA(command, model.PublishSubscribe)) {
+    if (model.PublishSubscribe.isInstance(command)) {
       onMessageControllers[commandName] = {};
       connection = connection
         .mock('on')
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index