inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
55 lines • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class AbstractObjectDefinitionInspector {
constructor() {
this.relevantClasses = [];
this.namePatterns = [];
this.inspectAll = false;
}
addInterestedClass(clazz) {
this.relevantClasses.push(clazz);
}
addNamePattern(nameOrRegex) {
this.namePatterns.push(nameOrRegex);
}
inspect(objectDefinition) {
if (this.interestedIn(objectDefinition)) {
return this.doInspect(objectDefinition);
}
return null;
}
/**
* Indicates whether this inspector is interested in this ObjectDefinition
* @param objectDefinition ObjectDefinition The object definition to possibly modify
* @return boolean Whether it's interested or not in this ObjectDefinition
*/
interestedIn(objectDefinition) {
if (this.inspectAll) {
return true;
}
const relevantClass = this.relevantClasses.find((clazz) => objectDefinition.getProducedClass() === clazz);
if (relevantClass) {
return true;
}
const relevantPattern = this.namePatterns.find((nameOrPattern) => {
if (nameOrPattern instanceof RegExp) {
if (nameOrPattern.test(objectDefinition.getName())) {
return true;
}
}
else if (nameOrPattern === objectDefinition.getName()) {
return true;
}
return false;
});
if (relevantPattern) {
return true;
}
return false;
}
setInspectAll(inspectAll) {
this.inspectAll = inspectAll;
}
}
exports.AbstractObjectDefinitionInspector = AbstractObjectDefinitionInspector;
//# sourceMappingURL=AbstractObjectDefinitionInspector.js.map