[Groonga-commit] droonga/express-droonga at ce50ebe [master] Define builtin APIs as constants

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Oct 16 19:02:17 JST 2013


YUKI Hiroshi	2013-10-16 19:02:17 +0900 (Wed, 16 Oct 2013)

  New Revision: ce50ebecdacf177a89dcafe9e0f3b922908da19b
  https://github.com/droonga/express-droonga/commit/ce50ebecdacf177a89dcafe9e0f3b922908da19b

  Message:
    Define builtin APIs as constants

  Added files:
    lib/adapter/api.js
  Modified files:
    application.js
    index.js
    lib/adapter/http.js
    lib/adapter/socket.io.js

  Modified: application.js (+4 -9)
===================================================================
--- application.js    2013-10-16 18:34:37 +0900 (a880996)
+++ application.js    2013-10-16 19:02:17 +0900 (88db307)
@@ -4,11 +4,6 @@ var express = require('express'),
     droonga = require('./index'),
     http = require('http');
 
-var builtInRestAPI = require('./lib/adapter/api/rest');
-var builtInSocketIoAPI = require('./lib/adapter/api/socket.io');
-var builtInGroongaAPI = require('./lib/adapter/api/groonga');
-var builtInDroongaAPI = require('./lib/adapter/api/droonga');
-
 var application = express();
 var server = http.createServer(application);
 application.droonga({
@@ -16,10 +11,10 @@ application.droonga({
   defaultDataset: 'example',
   server: server,
   plugins: [
-    builtInRestAPI,
-    builtInSocketIoAPI,
-    builtInGroongaAPI,
-    builtInDroongaAPI
+    droonga.API_REST,
+    droonga.API_SOCKET_IO,
+    droonga.API_GROONGA,
+    droonga.API_DROONGA
   ]
 });
 

  Modified: index.js (+2 -0)
===================================================================
--- index.js    2013-10-16 18:34:37 +0900 (2b84f57)
+++ index.js    2013-10-16 19:02:17 +0900 (4ffe1fc)
@@ -31,4 +31,6 @@ express.application.droonga = function(params) {
   this.emitMessage = connection.emitMessage.bind(connection); // shorthand
 }
 
+requre('./lib/adapter/api').exportTo(exports);
+
 exports.command = require('./lib/adapter/command');

  Added: lib/adapter/api.js (+24 -0) 100644
===================================================================
--- /dev/null
+++ lib/adapter/api.js    2013-10-16 19:02:17 +0900 (e6ae4cd)
@@ -0,0 +1,24 @@
+exports.API_REST      = './api/rest';
+exports.API_SOCKET_IO = './api/socket.io';
+exports.API_GROONGA   = './api/groonga';
+exports.API_DROONGA   = './api/droonga';
+
+exports.exportTo = function(target) {
+  target.API_REST      = exports.API_REST;
+  target.API_SOCKET_IO = exports.API_SOCKET_IO;
+  target.API_GROONGA   = exports.API_GROONGA;
+  target.API_DROONGA   = exports.API_DROONGA;
+};
+
+exports.normalize = function(apis) {
+  apis = apis || [];
+  if (!Array.isArray(apis))
+    apis = [apis];
+  apis = apis.map(function(api) {
+    if (typeof api == 'string')
+      require(api);
+    else
+      api;
+  });
+  return apis;
+};

  Modified: lib/adapter/http.js (+2 -3)
===================================================================
--- lib/adapter/http.js    2013-10-16 18:34:37 +0900 (8ee07fa)
+++ lib/adapter/http.js    2013-10-16 19:02:17 +0900 (a599710)
@@ -2,6 +2,7 @@ var debug = require('../debug');
 
 var command = require('./command');
 var wrapper = require('./wrapper');
+var api = require('./api');
 
 function createHandler(params) {
   params = params || {};
@@ -69,9 +70,7 @@ exports.register = function(application, params) {
   var prefix = params.prefix || '';
   prefix = prefix.replace(/\/$/, '');
 
-  var commandSets = params.plugins || [];
-  if (!Array.isArray(commandSets))
-    commandSets = [commandSets];
+  var commandSets = api.normalize(params.plugins);
 
   var unifiedCommandSet = {};
   commandSets.forEach(function(commandSet) {

  Modified: lib/adapter/socket.io.js (+2 -3)
===================================================================
--- lib/adapter/socket.io.js    2013-10-16 18:34:37 +0900 (39c240d)
+++ lib/adapter/socket.io.js    2013-10-16 19:02:17 +0900 (3204e01)
@@ -1,6 +1,7 @@
 var socketIo = require('socket.io');
 var command = require('./command');
 var wrapper = require('./wrapper');
+var api = require('./api');
 
 var DEFAULT_TIMEOUT = 10 * 1000;
 
@@ -131,9 +132,7 @@ exports.register = function(application, server, params) {
     });
   }
 
-  var commandSets = params.plugins || [];
-  if (!Array.isArray(commandSets))
-    commandSets = [commandSets];
+  var commandSets = api.normalize(params.plugins);
   
   var unifiedCommandSet = {};
   commandSets.forEach(function(commandSet) {
-------------- next part --------------
HTML����������������������������...
Download 



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