1 |
|
/* |
2 |
|
Copyright (c) 2012, Yahoo! Inc. All rights reserved. |
3 |
|
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. |
4 |
|
*/ |
5 |
|
|
6 |
1 |
var util = require('util'), |
7 |
|
Store = require('./index'); |
8 |
|
|
9 |
|
/** |
10 |
|
* a `Store` implementation using an in-memory object. |
11 |
|
* |
12 |
|
* Usage |
13 |
|
* ----- |
14 |
|
* |
15 |
|
* var store = require('istanbul').Store.create('memory'); |
16 |
|
* |
17 |
|
* |
18 |
|
* @class MemoryStore |
19 |
|
* @extends Store |
20 |
|
* @constructor |
21 |
|
*/ |
22 |
1 |
function MemoryStore() { |
23 |
9 |
Store.call(this); |
24 |
9 |
this.map = {}; |
25 |
|
} |
26 |
|
|
27 |
1 |
MemoryStore.TYPE = 'memory'; |
28 |
1 |
util.inherits(MemoryStore, Store); |
29 |
|
|
30 |
1 |
Store.mix(MemoryStore, { |
31 |
|
set: function (key, contents) { |
32 |
31 |
this.map[key] = contents; |
33 |
|
}, |
34 |
|
|
35 |
|
get: function (key) { |
36 |
60 |
if (!this.hasKey(key)) { |
37 |
1 |
throw new Error('Unable to find entry for [' + key + ']'); |
38 |
|
} |
39 |
59 |
return this.map[key]; |
40 |
|
}, |
41 |
|
|
42 |
|
hasKey: function (key) { |
43 |
92 |
return this.map.hasOwnProperty(key); |
44 |
|
}, |
45 |
|
|
46 |
|
keys: function () { |
47 |
16 |
return Object.keys(this.map); |
48 |
|
}, |
49 |
|
|
50 |
|
dispose: function () { |
51 |
3 |
this.map = {}; |
52 |
|
} |
53 |
|
}); |
54 |
|
|
55 |
1 |
module.exports = MemoryStore; |
56 |
|
|