Code coverage report for kobold-core/index.js

Statements: 36.84% (7 / 19)      Branches: 0% (0 / 8)      Functions: 0% (0 / 2)      Lines: 36.84% (7 / 19)      Ignored: none     

All files » kobold-core/ » index.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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115      1 1   1 1 1             1                                                                                                                                                                                                   1  
// Copyright 2014, Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
 
var ConnectionAdapter = require('./lib/connectionAdapter/connectionAdapter');
var RiakConnectionAdapter = require('./lib/connectionAdapter/riakConnectionAdapter');
 
var StorageAdapter = require('./lib/storageAdapter/storageAdapter');
var FileStorageAdapter = require('./lib/storageAdapter/fileStorageAdapter');
var KeyValueStorageAdapter = require('./lib/storageAdapter/keyValueStorageAdapter');
 
/**
 * Exported values
 *
 * @type {object}
 */
var core = {
 
	/**
	 * Abstract storage adapter class
	 *
	 * @property StorageAdapter
	 * @type {StorageAdapter}
	 */
	StorageAdapter: StorageAdapter,
 
	/**
	 * List of storage adapters
	 *
	 * @property storageAdapters
	 * @type {object}
	 */
	storageAdapters: {
		"File": FileStorageAdapter,
		"KeyValue": KeyValueStorageAdapter
	},
 
	/**
	 * Builds a storage adapter
	 *
	 * @method createStorageAdapter
	 * @param {string} build
	 * @param {object} config
	 * @param {string} config.type
	 * @param {object} [config.options]
	 * @param {ConnectionAdapter} [config.connection]
	 * @return {StorageAdapter}
	 */
	buildStorageAdapter: function (build, config) {
		var type = config.type,
			adapterOptions = config.options || {},
			AdapterClass;
 
		if (typeof type == 'string') {
			AdapterClass = core.storageAdapters[type];
			if (config.connection) {
				adapterOptions.connection = this.createConnectionAdapter(config.connection);
			}
			return new AdapterClass(build, adapterOptions);
		} else {
			return type; // Use as instance instead
		}
	},
 
 
	/**
	 * Abstract connection adapter class
	 *
	 * @property ConnectionAdapter
	 * @type {ConnectionAdapter}
	 */
	ConnectionAdapter: ConnectionAdapter,
 
	/**
	 * List of connection adapters
	 *
	 * @property connectionAdapters
	 * @type {object}
	 */
	connectionAdapters: {
		"Riak": RiakConnectionAdapter
	},
 
	/**
	 * Builds a connection adapter
	 *
	 * @method createConnectionAdapter
	 * @param {object} config
	 * @param {string} config.type
	 * @param {object} [config.options]
	 * @return {ConnectionAdapter}
	 */
	buildConnectionAdapter: function (config) {
		var type = config.type,
			adapterOptions = config.options,
			AdapterClass;
 
		if (typeof type == 'string') {
			AdapterClass = core.connectionAdapters[type];
			return new AdapterClass(adapterOptions);
		} else {
			return type; // Use as instance instead
		}
	},
 
 
	/**
	 * Version of package
	 *
	 * @property version
	 * @type {string}
	 */
	version: require('./package.json').version
};
module.exports = core;