[Groonga-commit] groonga/gcs [master] Implement MemoryStorage (for testing)

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Dec 7 13:37:14 JST 2012


YUKI Hiroshi	2012-12-07 13:37:14 +0900 (Fri, 07 Dec 2012)

  New Revision: 0e4f62eae04f68f341856ffcbcf6a5523a8fbf68
  https://github.com/groonga/gcs/commit/0e4f62eae04f68f341856ffcbcf6a5523a8fbf68

  Log:
    Implement MemoryStorage (for testing)

  Modified files:
    lib/database/domain.js
    lib/database/storage.js

  Modified: lib/database/domain.js (+1 -1)
===================================================================
--- lib/database/domain.js    2012-12-07 13:17:36 +0900 (905b653)
+++ lib/database/domain.js    2012-12-07 13:37:14 +0900 (66876d3)
@@ -11,7 +11,7 @@ var nroonga = require('../wrapped-nroonga');
 var ValidationError = require('../errors').ValidationError;
 var MultiplexedValidationError = require('../errors').MultiplexedValidationError;
 var IndexField = require('./index-field').IndexField;
-var Storage = require('./storage').Storage;
+var storage = require('./storage');
 
 var MINIMUM_NAME_LENGTH =
       exports.MINIMUM_NAME_LENGTH =

  Modified: lib/database/storage.js (+26 -4)
===================================================================
--- lib/database/storage.js    2012-12-07 13:17:36 +0900 (105ba81)
+++ lib/database/storage.js    2012-12-07 13:37:14 +0900 (5db15cd)
@@ -6,13 +6,13 @@ var mkdirp = require('mkdirp');
 var rmRSync = require('../rm').rmRSync;
 var crypto = require('crypto');
 
-function Storage(args) {
+function FileStorage(args) {
   this.initialize(args);
 }
-Storage.prototype = {
+FileStorage.prototype = {
   initialize: function(args) {
     this.name = args.name;
-    this.basePath = args.basePath;
+    this.basePath = args.basePath || '/tmp';
   },
 
   get directoryPath() {
@@ -79,5 +79,27 @@ Storage.prototype = {
     return path.existsSync(this.directoryPath);
   }
 };
+exports.FileStorage = FileStorage;
 
-exports.Storage = Storage;
+
+function MemoryStorage() {
+  this._storage = {};
+}
+MemoryStorage.prototype = {
+  saveSync: function(document) {
+    this._storage[document.id] = document;
+  },
+
+  readSync: function(id) {
+    return this._storage[id] || null;
+  },
+
+  deleteSync: function(id) {
+    delete this._storage[id];
+  },
+
+  clearSync: function() {
+    this._storage = {};
+  }
+};
+exports.MemoryStorage = MemoryStorage;
-------------- next part --------------
HTML����������������������������...
Download 



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