UNPKG

cocktail

Version:

CocktailJS is a small library to explore traits, talents, inheritance and annotations concepts in nodejs - Shake your objects and classes with Cocktail!

56 lines (40 loc) 1.14 kB
/* * * Copyright (c) 2013 - 2016 Maximiliano Fierro * Licensed under the MIT license. */ 'use strict'; var sequence = require('../sequence'); function $$required$$ () { throw new Error('method is marked as required but it has not been defined'); } function Requires () {} Requires.requiredMethod = $$required$$; Requires.prototype = { retain : false, priority : sequence.REQUIRES, name : '@requires', _parameter: [], setParameter: function (value) { //TODO: validate parameter this._parameter = [].concat(value); }, getParameter: function () { return this._parameter; }, process: function (subject) { var reqs = this.getParameter(), // always an [] l = reqs.length, i; for (i = 0; i < l; i++) { this._createRequiredMethod(subject, reqs[i]); } }, _createRequiredMethod: function(sub, methodName){ var subject = (sub.prototype || sub); if (!subject[methodName]) { subject[methodName] = Requires.requiredMethod; } } }; module.exports = Requires;