All files / src artifacts_objects.ts

100% Statements 14/14
100% Branches 8/8
100% Functions 2/2
100% Lines 14/14

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 30  1x 1x   1x       5046x 1x     5046x 5x   5041x         1x 1x 106x 106x 103x 103x        
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 = [];
    for (const key in Objects) {
      const list: any = Objects;
      if (typeof list[key] === "function") {
        const obj = new list[key]("DUMMY_NAME");
        this.objectMap[obj.getType()] = list[key];
      }
    }
  }
}