all files / lib/resolver/ assignment.js

100% Statements 8/8
100% Branches 0/0
100% Functions 4/4
100% Lines 8/8
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                                                       
"use strict";
 
/**
 * Invoke the specified method as part of resolving the instance on which the method is called, optionally configuring
 * dependencies to be passed as method parameters.
 *
 * @name assignment
 * @param {string|object} dependencyKeyOrObject A dependency key of the object with which to
 *        assign to the instance being resolved, or the object itself.
 * @function
 * @memberOf Resolver:assignment#
 */
 
/**
 * An assignment resolver takes dependencies and copies their properties
 * into the resolution instance using <code>Object.assign</code>.
 *
 * @function
 * @exports Resolver:assignment
 */
module.exports = function assignment(ctx, res, next) {
  var instance = res.instance(true);
 
  ctx.resolve(this.args())
    .then(function(deps) {
      deps.list.forEach(function(dep) {
        Object.assign(instance, dep);
      });
      next();
    })
    .catch(function(err) {
      res.fail(err);
      next();
    });
};