all files / lib/strategy/ ExtendConfigStrategy.js

95.24% Statements 20/21
90.91% Branches 20/22
100% Functions 2/2
95.24% Lines 20/21
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                                                 
'use strict';
 
var extend = require('../helpers/clone-extend').extend;
 
/**
 * Represents a strategy that extends the configuration.
 *
 * @class
 */
function ExtendConfigStrategy (extendWith) {
  this.extendWith = extendWith;
}
 
ExtendConfigStrategy.prototype.process = function (config, callback) {
  extend(config, this.extendWith);
 
  // TODO: FIX HACK! Resolve this in a more generic/re-usable way, perhaps
  // using a different object extension library.
  Eif (this.extendWith) {
    var extendWith = this.extendWith;
 
    if(extendWith.cacheOptions && extendWith.cacheOptions.client){
      config.cacheOptions.client = extendWith.cacheOptions.client;
    }
 
    Iif(extendWith.requestExecutor){
      config.requestExecutor = extendWith.requestExecutor;
    }
 
    // TODO: HACK! Fix issue with extend library extending arrays
    // instead of overwriting them.
    if (extendWith.web) {
      var web = extendWith.web;
 
      if (web.produces) {
        config.web.produces = web.produces;
      }
 
      if (web.login && web.login.form && web.login.form.fieldOrder) {
        config.web.login.form.fieldOrder = web.login.form.fieldOrder;
      }
 
      if (web.register && web.register.form && web.register.form.fieldOrder) {
        config.web.register.form.fieldOrder = web.register.form.fieldOrder;
      }
    }
  }
 
  callback(null, config);
};
 
module.exports = ExtendConfigStrategy;