All files / src artifacts_objects.ts

100% Statements 30/30
100% Branches 7/7
100% Functions 2/2
100% Lines 30/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 301x 1x 1x 1x 1x 1x 1x 1x 7415x 1x 1x 7415x 7415x 5x 7415x 7410x 7410x 7415x 1x 1x 1x 1x 1x 152x 149x 149x 149x 152x 1x 1x
import {IObject} from "./objects/_iobject";
import * as Objects from "./objects";
import {UnknownObject} from "./objects/_unknown_object";
 
export class ArtifactsObjects {
  private static objectMap: any;
 
  public static newObject(name: string, type: string): IObject {
    if (this.objectMap === undefined) {
      this.buildObjectMap();
    }
 
    if (type === undefined || this.objectMap[type] === undefined) {
      return new UnknownObject(name, type);
    } else {
      return new this.objectMap[type](name);
    }
  }
 
  private static buildObjectMap() {
    this.objectMap = [];
    const list: any = Objects;
    for (const key in Objects) {
      if (typeof list[key] === "function") {
        const obj = new list[key]("DUMMY_NAME");
        this.objectMap[obj.getType()] = list[key];
      }
    }
  }
}