all files / addon/utils/ dsl-route-extend.js

100% Statements 16/16
87.5% Branches 7/8
100% Functions 6/6
100% Lines 16/16
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 31 32 33 34 35 36 37                  11×                        
import Ember from 'ember';
export default {
  routeMetadata: null,
  oldRoute: Ember.RouterDSL.prototype.route,
  init (metaDataService) {
    this.setRouterDSLProto();
    let oldRoute = this.oldRoute;
    this.route = function (name, options = {}) {
      oldRoute.call(this, ...arguments);
      name = getFullName(this, name, options.resetNamespace);
      Eif (arguments.length >= 2 && typeof options !== 'function') {
        metaDataService._registerRoute(name, options);
      }
    };
    this.setRouterDSLProto();
  },
  destroy() {
    Ember.RouterDSL.prototype.route = this.oldRoute;
  },
  setRouterDSLProto() {
    Ember.RouterDSL.prototype.route = this.route;
  }
};
 
function canNest(dsl) {
  return dsl.parent !== 'application';
}
 
function getFullName(dsl, name, resetNamespace) {
  if (canNest(dsl) && resetNamespace !== true) {
    return `${dsl.parent}.${name}`;
  } else {
    return name;
  }
}