UNPKG

regard

Version:

Sugar-interface to access multiple data sources.

40 lines (26 loc) 728 B
var _ = require('lodash'), AbstractManager = require('./abstract'); exports = module.exports = EndpointsManager; function EndpointsManager() { if (!(this instanceof EndpointsManager)) { return new EndpointsManager(); } AbstractManager.call(this); } EndpointsManager.prototype = _.create(AbstractManager.prototype); EndpointsManager.prototype.getParent = function (endpoint) { var key = endpoint; if (_.isObject(endpoint)) { key = endpoint.key; } if (!_.isString(key)) { return; } var breadcrumb = key.split('/'), parent; do { breadcrumb.pop(); parent = this.get(breadcrumb.join('/')); } while (_.isUndefined(parent) && breadcrumb.length > 1); return parent; };