deep-kernel
Version:
DEEP Kernel Library
102 lines (75 loc) • 3.23 kB
JavaScript
/**
* Created by AlexanderC on 3/7/16.
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ScopeDriver = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _AbstractDriver2 = require('./AbstractDriver');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
let ScopeDriver = exports.ScopeDriver = function (_AbstractDriver) {
_inherits(ScopeDriver, _AbstractDriver);
/**
* @param {String} key
*/
function ScopeDriver(key) {
_classCallCheck(this, ScopeDriver);
var _this = _possibleConstructorReturn(this, (ScopeDriver.__proto__ || Object.getPrototypeOf(ScopeDriver)).call(this));
_this._scope = global || {};
_this._key = key;
return _this;
}
/**
* @returns {Object|*}
*/
_createClass(ScopeDriver, [{
key: 'setScope',
/**
* @param {Object} scope
* @returns {ScopeDriver}
*/
value: function setScope(scope) {
this._scope = scope;
return this;
}
/**
* @returns {String}
*/
}, {
key: 'setKey',
/**
* @param {String} key
* @returns {ScopeDriver}
*/
value: function setKey(key) {
this._key = key;
return this;
}
/**
* @param {String} key
* @private
*/
}, {
key: '_load',
value: function _load() {
let key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
this._key = key || this._key;
this._scope.hasOwnProperty(this._key) ? this.loaded(this._scope[this._key]) : this.fail(`Unable to load configuration from scope: No such key '${this._key}' exists`);
}
}, {
key: 'scope',
get: function get() {
return this._scope;
}
}, {
key: 'key',
get: function get() {
return this._key;
}
}]);
return ScopeDriver;
}(_AbstractDriver2.AbstractDriver);