src/hooks/decorators/Setup.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 22
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 15
mnd 0
bc 0
fnc 1
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A Setup.ts ➔ Setup 0 17 1
1
import { ExpressBean } from '@/ExpressBeansTypes';
2 5
import { logger, registeredMethods } from '@/core';
3 5
import { Executor } from '@/core/Executor';
4
5
/**
6
   * Hook a function to initialization phase.
7
   * @decorator
8
   */
9 5
export function Setup<This>(
10
  method: () => any,
11
  context: ClassMethodDecoratorContext<This, () => any>,
12
) {
13 2
  logger.debug(`Registering setup function ${String(context.name)}`);
14 2
  Executor.setExecution('routing', () => {
15 2
    const bean = registeredMethods.get(method) as ExpressBean;
16 2
    logger.debug(`Initializing ${bean._className}.${String(context.name)} as setup function`);
17 2
    Executor.setExecution('init', () => method.bind(bean)());
18
  });
19
20 2
  return method;
21
}
22