All files / core Controller.ts

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 5/5
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 306x                   6x       1x         11x                 6x  
import { camel } from 'change-case';
 
// Provides a base class for controllers. Includes auto-naming functionality.  
abstract class Controller {
 
  // Name of the controller's application.
  public static app: string;
  public static name: string;
 
  // Internal name of the controller.
  private static _controller: string = null;
 
  // Sets the private controller variable.
  public static set controller(name: string) {
    this._controller = name;
  }
 
  // Returns the name of the controller if set, otherwise a modified constructor name.
  public static get controller(): string {
    return this._controller || camel(this.name.replace(/(Ctrl|Controller)/i, ''));
  }
 
  // Instance variables set by the dispatch middleware.
  public name: string;
  public action: string;
  public app: string;
}
 
export { Controller as default };