Skip to content

Commit

Permalink
refactor: extract non custom tag keys metadata keys module
Browse files Browse the repository at this point in the history
  • Loading branch information
notaphplover committed Apr 15, 2021
1 parent e1cecbc commit dc501ab
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
13 changes: 13 additions & 0 deletions src/constants/metadata_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ export const DESIGN_PARAM_TYPES = "design:paramtypes";

// used to identify postConstruct functions
export const POST_CONSTRUCT = "post_construct";

function getNonCustomTagKeys(): string[] {
return [
INJECT_TAG,
MULTI_INJECT_TAG,
NAME_TAG,
UNMANAGED_TAG,
NAMED_TAG,
OPTIONAL_TAG,
];
}

export const NON_CUSTOM_TAG_KEYS: string[] = getNonCustomTagKeys();
22 changes: 8 additions & 14 deletions src/planning/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,9 @@ class Target implements interfaces.Target {
}

public isTagged(): boolean {
return this.metadata.some((m) =>
(m.key !== METADATA_KEY.INJECT_TAG) &&
(m.key !== METADATA_KEY.MULTI_INJECT_TAG) &&
(m.key !== METADATA_KEY.NAME_TAG) &&
(m.key !== METADATA_KEY.UNMANAGED_TAG) &&
(m.key !== METADATA_KEY.NAMED_TAG) &&
(m.key !== METADATA_KEY.OPTIONAL_TAG));
return this.metadata.some(
(metadata) => METADATA_KEY.NON_CUSTOM_TAG_KEYS.every((key) => metadata.key !== key),
);
}

public isOptional(): boolean {
Expand All @@ -86,14 +82,12 @@ class Target implements interfaces.Target {

public getCustomTags(): interfaces.Metadata[] | null {
if (this.isTagged()) {
return this.metadata.filter((m) =>
(m.key !== METADATA_KEY.INJECT_TAG) &&
(m.key !== METADATA_KEY.MULTI_INJECT_TAG) &&
(m.key !== METADATA_KEY.NAME_TAG) &&
(m.key !== METADATA_KEY.UNMANAGED_TAG) &&
(m.key !== METADATA_KEY.NAMED_TAG));
return this.metadata.filter(
(metadata) => METADATA_KEY.NON_CUSTOM_TAG_KEYS.every((key) => metadata.key !== key),
);
} else {
return null;
}
return null;
}

public matchesNamedTag(name: string): boolean {
Expand Down
23 changes: 23 additions & 0 deletions test/planning/target.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ describe("Target", () => {
target3.metadata.push(new Metadata("power", 5), new Metadata("speed", 5));
expect(target3.isTagged()).to.be.eql(true);

const target4 = new Target(TargetTypeEnum.Variable, "", "Katana");
target4.metadata.push(new Metadata(METADATA_KEY.INJECT_TAG, "Katana"))
expect(target4.isTagged()).to.be.eql(false);

const target5 = new Target(TargetTypeEnum.Variable, "", "Katana");
target5.metadata.push(new Metadata(METADATA_KEY.MULTI_INJECT_TAG, "Katana"))
expect(target5.isTagged()).to.be.eql(false);

const target6 = new Target(TargetTypeEnum.Variable, "katanaName", "Katana");
target6.metadata.push(new Metadata(METADATA_KEY.NAME_TAG, "katanaName"))
expect(target6.isTagged()).to.be.eql(false);

const target7 = new Target(TargetTypeEnum.Variable, "", "Katana");
target7.metadata.push(new Metadata(METADATA_KEY.UNMANAGED_TAG, true))
expect(target7.isTagged()).to.be.eql(false);

const target8 = new Target(TargetTypeEnum.Variable, "katanaName", "Katana");
target8.metadata.push(new Metadata(METADATA_KEY.NAMED_TAG, "katanaName"))
expect(target8.isTagged()).to.be.eql(false);

const target9 = new Target(TargetTypeEnum.Variable, "", "Katana");
target9.metadata.push(new Metadata(METADATA_KEY.OPTIONAL_TAG, true))
expect(target9.isTagged()).to.be.eql(false);
});

it("Should be able to match tagged metadata", () => {
Expand Down

0 comments on commit dc501ab

Please sign in to comment.