UNPKG

deep-package-manager

Version:
78 lines (60 loc) 1.73 kB
/** * Created by AlexanderC on 11/24/15. */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractMatcher = undefined; var _deepCore = require('deep-core'); var _deepCore2 = _interopRequireDefault(_deepCore); var _Undeploy = require('../Undeploy'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class AbstractMatcher extends _deepCore2.default.OOP.Interface { constructor() { super(['match']); } /** * @param {Object} rawResourcesObj * @returns {Object} */ filter(rawResourcesObj) { let resourcesObj = {}; for (let type in rawResourcesObj) { if (!rawResourcesObj.hasOwnProperty(type) || !AbstractMatcher.isKnownType(type)) { continue; } let appResources = rawResourcesObj[type]; for (let appHash in appResources) { if (!appResources.hasOwnProperty(appHash)) { continue; } let resourcesObjStack = appResources[appHash]; for (let resourceId in resourcesObjStack) { if (!resourcesObjStack.hasOwnProperty(resourceId) || !this.match(type, resourceId)) { continue; } if (!resourcesObj.hasOwnProperty(type)) { resourcesObj[type] = {}; } resourcesObj[type][resourceId] = resourcesObjStack[resourceId]; } } } return resourcesObj; } /** * @param {String} type * @returns {Boolean} */ static isKnownType(type) { return AbstractMatcher.TYPES.indexOf(type) !== -1; } /** * @returns {String[]} */ static get TYPES() { return _Undeploy.Undeploy.SERVICES; } } exports.AbstractMatcher = AbstractMatcher;