Code coverage report for istanbul/lib/store/memory.js

Statements: 100% (15 / 15)      Branches: 100% (2 / 2)      Functions: 100% (6 / 6)      Lines: 100% (15 / 15)      Ignored: none     

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