Comparing version 0.6.0 to 0.7.0
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -8,4 +8,4 @@ */ | ||
var sequence = require('./processor/sequence'), | ||
cocktail, | ||
var sequence = require('./processor/sequence'); | ||
var cocktail, | ||
ANNOTATION_REG_EXP = /^@/; | ||
@@ -36,3 +36,3 @@ | ||
*/ | ||
getProcessors : function(){ | ||
getProcessors : function () { | ||
return this._processors; | ||
@@ -62,8 +62,8 @@ }, | ||
*/ | ||
registerProcessors: function(processorsConfig){ | ||
registerProcessors: function (processorsConfig) { | ||
var processors = this.getProcessors(), | ||
key; | ||
for(key in processorsConfig){ | ||
if(processorsConfig.hasOwnProperty(key)){ | ||
processors[key] = processorsConfig[key]; | ||
for (key in processorsConfig){ | ||
if (processorsConfig.hasOwnProperty(key)) { | ||
processors[key] = processorsConfig[key]; | ||
} | ||
@@ -76,7 +76,7 @@ } | ||
*/ | ||
use: function(annotation){ | ||
use: function (annotation) { | ||
var name = annotation.name || (annotation.prototype && annotation.prototype.name), | ||
processor = {}; | ||
if(name && annotation.prototype){ | ||
if (name && annotation.prototype) { | ||
processor[name] = annotation; | ||
@@ -91,3 +91,3 @@ this.registerProcessors(processor); | ||
*/ | ||
_getProcessorFor: function(key){ | ||
_getProcessorFor: function (key) { | ||
var processors = this.getProcessors(), | ||
@@ -104,5 +104,5 @@ P; | ||
*/ | ||
_applyDefaultsOptions: function(options){ | ||
if(options && !('@merge' in options) ){ | ||
options['@merge'] = "single"; | ||
_applyDefaultsOptions: function (options) { | ||
if (options && !('@merge' in options)) { | ||
options['@merge'] = 'single'; | ||
} | ||
@@ -115,3 +115,3 @@ }, | ||
*/ | ||
_configureProcessorsWith: function(options){ | ||
_configureProcessorsWith: function (options) { | ||
var key, value, processor; | ||
@@ -121,5 +121,5 @@ | ||
if(options){ | ||
for(key in options){ | ||
if(options.hasOwnProperty(key) && ANNOTATION_REG_EXP.test(key)){ | ||
if (options) { | ||
for (key in options) { | ||
if (options.hasOwnProperty(key) && ANNOTATION_REG_EXP.test(key)) { | ||
value = options[key]; | ||
@@ -131,3 +131,3 @@ //get the processor instance for this annotation | ||
//check if the annotation should be removed | ||
if(!processor.retain){ | ||
if (!processor.retain) { | ||
delete options[key]; | ||
@@ -146,3 +146,3 @@ } | ||
*/ | ||
_pushQueue: function() { | ||
_pushQueue: function () { | ||
this._qStack.push(this._queue); | ||
@@ -156,3 +156,3 @@ this._queue = []; | ||
*/ | ||
_popQueue: function() { | ||
_popQueue: function () { | ||
this._queue = this._qStack.pop(); | ||
@@ -166,3 +166,3 @@ }, | ||
*/ | ||
_cleanQueue: function(){ | ||
_cleanQueue: function () { | ||
this._queue.length = 0; | ||
@@ -175,4 +175,4 @@ }, | ||
*/ | ||
_addProcessorToQueue: function(processor){ | ||
if(processor && processor.priority !== -1){ | ||
_addProcessorToQueue: function (processor) { | ||
if (processor && processor.priority !== -1) { | ||
this._queue.push(processor); | ||
@@ -186,3 +186,3 @@ } | ||
*/ | ||
_sortQueueByPriority: function(){ | ||
_sortQueueByPriority: function () { | ||
this._queue.sort(function(a, b){ | ||
@@ -197,3 +197,3 @@ return a.priority - b.priority; | ||
*/ | ||
_executeProcessorsOn: function(subject, options){ | ||
_executeProcessorsOn: function (subject, options) { | ||
var processors = this._queue, | ||
@@ -205,3 +205,3 @@ l = processors.length, | ||
for(i = 0; i < l; i++){ | ||
for (i = 0; i < l; i++) { | ||
processors[i].process(subject, options); | ||
@@ -231,3 +231,3 @@ } | ||
for (key in subject) { | ||
if(definitionProps.indexOf(key) > -1){ | ||
if (definitionProps.indexOf(key) > -1) { | ||
isClassDef = true; | ||
@@ -281,3 +281,3 @@ break; | ||
for (k in obj) { | ||
if(property === k) { | ||
if (property === k) { | ||
return true; | ||
@@ -294,7 +294,7 @@ } | ||
*/ | ||
_processClassDefition: function(subject) { | ||
_processClassDefition: function (subject) { | ||
var defaultConstructor, options; | ||
defaultConstructor = this._getDefaultClassConstructor(subject); | ||
if(this._isPropertyDefinedIn('constructor', subject)) { | ||
if (this._isPropertyDefinedIn('constructor', subject)) { | ||
delete subject.constructor; | ||
@@ -319,4 +319,4 @@ } | ||
*/ | ||
mix: function(subject, options){ | ||
if(!options){ | ||
mix: function (subject, options) { | ||
if (!options) { | ||
if (this._isClassDefition(subject)) { | ||
@@ -330,3 +330,3 @@ return this._processClassDefition(subject); | ||
if(subject){ | ||
if (subject) { | ||
this._pushQueue(); | ||
@@ -362,3 +362,3 @@ this._applyDefaultsOptions(options); | ||
'@exports' : require('./processor/annotation/Exports'), | ||
'@static' : require('./processor/annotation/Static'), | ||
'@static' : require('./processor/annotation/Static') | ||
}; | ||
@@ -365,0 +365,0 @@ |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -9,4 +9,4 @@ */ | ||
var sequence = require('../sequence'), | ||
Annotation = function(){}; | ||
var sequence = require('../sequence'); | ||
var Annotation = function () {}; | ||
@@ -20,12 +20,12 @@ Annotation.prototype = { | ||
setParameter: function(value){ | ||
setParameter: function (value) { | ||
this._value = value; | ||
}, | ||
getParameter: function() { | ||
getParameter: function () { | ||
return this._value; | ||
}, | ||
process: function(subject){ | ||
var name = '@'+this.getParameter(); | ||
process: function (subject) { | ||
var name = '@' + this.getParameter(); | ||
@@ -37,2 +37,2 @@ subject.prototype.name = name; | ||
module.exports = Annotation; | ||
module.exports = Annotation; |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -9,4 +9,4 @@ */ | ||
var sequence = require('../sequence'), | ||
Exports = function(){}; | ||
var sequence = require('../sequence'); | ||
var Exports = function () {}; | ||
@@ -21,15 +21,15 @@ Exports.prototype = { | ||
setParameter: function(value) { | ||
setParameter: function (value) { | ||
this._parameter = value; | ||
}, | ||
getParameter: function() { | ||
getParameter: function () { | ||
return this._parameter; | ||
}, | ||
process: function(subject /*, proto*/){ | ||
process: function (subject /*, proto*/) { | ||
var value = this.getParameter(); | ||
if(value && typeof value === 'object'){ | ||
value['exports'] = subject; | ||
if (value && typeof value === 'object') { | ||
value.exports = subject; | ||
} | ||
@@ -39,2 +39,2 @@ } | ||
module.exports = Exports; | ||
module.exports = Exports; |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -9,4 +9,4 @@ */ | ||
var sequence = require('../sequence'), | ||
Extends = function(){}; | ||
var sequence = require('../sequence'); | ||
var Extends = function (){}; | ||
@@ -20,5 +20,5 @@ Extends.prototype = { | ||
setParameter: function(value){ | ||
if(typeof value !== 'function'){ | ||
throw new Error("Object cannot be extended"); | ||
setParameter: function (value) { | ||
if (!(value && value.prototype)) { | ||
throw new Error('@extends parameter should have a prototype'); | ||
} | ||
@@ -28,7 +28,7 @@ this._parameter = value; | ||
getParameter: function() { | ||
getParameter: function () { | ||
return this._parameter; | ||
}, | ||
process: function(subject){ | ||
process: function (subject) { | ||
var parent = this.getParameter(), | ||
@@ -44,4 +44,4 @@ sp; | ||
mthdArgs = Array.prototype.slice.call(arguments, 1); | ||
if(!mthd){ | ||
throw new Error("There is no method named " + mthd + " in parent class."); | ||
if (!mthd) { | ||
throw new Error('callSuper: There is no method named ' + mthd + ' in parent class.'); | ||
} | ||
@@ -54,2 +54,2 @@ return mthd.apply(this, mthdArgs); | ||
module.exports = Extends; | ||
module.exports = Extends; |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -8,12 +8,11 @@ */ | ||
var sequence = require('../sequence'), | ||
Merge; | ||
var sequence = require('../sequence'); | ||
var Merge; | ||
/** | ||
* @constructor | ||
*/ | ||
Merge = function(options) { | ||
Merge = function (options) { | ||
var useProto; | ||
if(options) { | ||
if (options) { | ||
useProto = options.usePrototypeWhenSubjectIsClass; | ||
@@ -42,33 +41,37 @@ this._usePrototypeWhenSubjectIsClass = (useProto === false) ? useProto : true; | ||
setParameter: function(value){ | ||
setParameter: function (value) { | ||
this._parameter = value; | ||
}, | ||
getParameter: function() { | ||
getParameter: function () { | ||
return this._parameter; | ||
}, | ||
/** | ||
* mine merge strategy: mine params over their. If params is already defined it gets overriden. | ||
*/ | ||
_mergeMine : function(mine, their){ | ||
_doMerge : function (mine, their, method) { | ||
var key; | ||
for(key in their){ | ||
if(their.hasOwnProperty(key)){ | ||
mine[key] = their[key]; | ||
for (key in their) { | ||
if (their.hasOwnProperty(key)) { | ||
method.call(this, key); | ||
} | ||
} | ||
}, | ||
/** | ||
* mine merge strategy: mine params over their. If params is already defined it gets overriden. | ||
*/ | ||
_mergeMine : function (mine, their) { | ||
this._doMerge(mine, their, function(k){ | ||
mine[k] = their[k]; | ||
}); | ||
return mine; | ||
}, | ||
_mergeOnlyProperties : function (mine, their){ | ||
var key; | ||
for(key in their){ | ||
if(their.hasOwnProperty(key) && typeof their[key] !== "function"){ | ||
mine[key] = their[key]; | ||
_mergeOnlyProperties : function (mine, their) { | ||
this._doMerge(mine, their, function(k){ | ||
if (typeof their[k] !== 'function'){ | ||
mine[k] = their[k]; | ||
} | ||
} | ||
}); | ||
@@ -79,3 +82,3 @@ return mine; | ||
/** | ||
* deepMine merge strategy: mine params over their. | ||
* deepMine merge strategy: mine params over their. | ||
* If params is already defined and it is an object it is merged with strategy mine, | ||
@@ -85,4 +88,4 @@ * if params is already defined and it is an array it is concatenated, | ||
*/ | ||
_mergeDeepMine : function(mine, their){ | ||
return this._mergeDeep(mine, their, this._mergeMine); | ||
_mergeDeepMine : function (mine, their) { | ||
return this._mergeDeep(mine, their, '_mergeMine'); | ||
}, | ||
@@ -93,12 +96,10 @@ | ||
*/ | ||
_mergeTheir : function(mine, their){ | ||
var key; | ||
for(key in their){ | ||
if(their.hasOwnProperty(key) && mine[key] === undefined ){ | ||
mine[key] = their[key]; | ||
_mergeTheir : function (mine, their) { | ||
this._doMerge(mine, their, function(k){ | ||
if (mine[k] === undefined) { | ||
mine[k] = their[k]; | ||
} | ||
} | ||
}); | ||
return mine; | ||
return mine; | ||
}, | ||
@@ -108,3 +109,3 @@ | ||
/** | ||
* deepMine merge strategy: their params over mine. | ||
* deepMine merge strategy: their params over mine. | ||
* If params is already defined and it is an object it is merged with strategy their, | ||
@@ -114,5 +115,5 @@ * if params is already defined and it is an array it is concatenated, | ||
*/ | ||
_mergeDeepTheir : function(mine, their){ | ||
return this._mergeDeep(mine, their, this._mergeTheir); | ||
}, | ||
_mergeDeepTheir : function (mine, their) { | ||
return this._mergeDeep(mine, their, '_mergeTheir'); | ||
}, | ||
@@ -122,26 +123,23 @@ /** | ||
*/ | ||
_mergeDeep: function(mine, their, strategy){ | ||
var key; | ||
for(key in their){ | ||
if(their.hasOwnProperty(key)){ | ||
if(typeof their[key] === "object"){ | ||
if(their[key] instanceof Array){ | ||
mine[key] = [].concat(mine[key], their[key]); | ||
}else{ | ||
mine[key] = strategy(mine[key], their[key]); | ||
} | ||
}else if(mine[key] === undefined ){ | ||
mine[key] = their[key]; | ||
_mergeDeep: function (mine, their, strategy) { | ||
this._doMerge(mine, their, function(key){ | ||
if (typeof their[key] === 'object') { | ||
if (their[key] instanceof Array) { | ||
mine[key] = [].concat(mine[key], their[key]); | ||
} else { | ||
mine[key] = this[strategy](mine[key], their[key]); | ||
} | ||
}else if (mine[key] === undefined ) { | ||
mine[key] = their[key]; | ||
} | ||
} | ||
}); | ||
return mine; | ||
}, | ||
_shouldUsePrototypeWhenSubjectIsClass: function() { | ||
_shouldUsePrototypeWhenSubjectIsClass: function () { | ||
return this._usePrototypeWhenSubjectIsClass; | ||
}, | ||
process: function(subject, options){ | ||
process: function (subject, options) { | ||
var their = options, | ||
@@ -148,0 +146,0 @@ useProto = this._shouldUsePrototypeWhenSubjectIsClass(), |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -9,4 +9,4 @@ */ | ||
var sequence = require('../sequence'), | ||
Properties = function(){}; | ||
var sequence = require('../sequence'); | ||
var Properties = function (){}; | ||
@@ -20,4 +20,4 @@ Properties.prototype = { | ||
setParameter: function(value){ | ||
if(Object.prototype.toString.call(value) !== '[object Object]'){ | ||
setParameter: function (value) { | ||
if (Object.prototype.toString.call(value) !== '[object Object]') { | ||
throw new Error('@properties parameter should be an Object'); | ||
@@ -28,19 +28,19 @@ } | ||
getParameter: function() { | ||
getParameter: function () { | ||
return this._parameter; | ||
}, | ||
_capitalizeName: function(name){ | ||
_capitalizeName: function (name) { | ||
return (name.charAt(0).toUpperCase() + name.slice(1)); | ||
}, | ||
_getterName: function(property, value){ | ||
_getterName: function (property, value) { | ||
return (value !== false && value !== true ? 'get' : 'is') + this._capitalizeName(property); | ||
}, | ||
_setterName: function(property){ | ||
_setterName: function (property) { | ||
return 'set' + this._capitalizeName(property); | ||
}, | ||
_createPropertyFor: function(subject, name, value, doNotOverride){ | ||
_createPropertyFor: function (subject, name, value, doNotOverride) { | ||
@@ -53,8 +53,8 @@ if (typeof subject[name] === 'undefined' || doNotOverride !== true) { | ||
}; | ||
subject[this._setterName(name)] = function(value){ | ||
this[name] = value; | ||
subject[this._setterName(name)] = function(set){ | ||
this[name] = set; | ||
}; | ||
}, | ||
process: function(subject){ | ||
process: function (subject) { | ||
var properties = this.getParameter(), | ||
@@ -64,4 +64,4 @@ isObject = !(subject.prototype), | ||
for(key in properties){ | ||
if(properties.hasOwnProperty(key)){ | ||
for (key in properties) { | ||
if (properties.hasOwnProperty(key)) { | ||
this._createPropertyFor(subject.prototype || subject, key, properties[key], isObject); | ||
@@ -68,0 +68,0 @@ } |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -9,7 +9,11 @@ */ | ||
var sequence = require('../sequence'), | ||
Requires = function(){}; | ||
var sequence = require('../sequence'); | ||
var Requires = function (){}; | ||
Requires.requiredMethod = function $$required$$(){ throw new Error('method is marked as required but it has not been defined');}; | ||
function $$required$$ () { | ||
throw new Error('method is marked as required but it has not been defined'); | ||
} | ||
Requires.requiredMethod = $$required$$; | ||
Requires.prototype = { | ||
@@ -22,3 +26,3 @@ retain : false, | ||
setParameter: function(value){ | ||
setParameter: function (value) { | ||
//TODO: validate parameter | ||
@@ -28,7 +32,7 @@ this._parameter = [].concat(value); | ||
getParameter: function() { | ||
getParameter: function () { | ||
return this._parameter; | ||
}, | ||
process: function(subject){ | ||
process: function (subject) { | ||
var reqs = this.getParameter(), // always an [] | ||
@@ -38,3 +42,3 @@ l = reqs.length, | ||
for(i = 0; i < l; i++){ | ||
for (i = 0; i < l; i++) { | ||
this._createRequiredMethod(subject, reqs[i]); | ||
@@ -46,7 +50,7 @@ } | ||
var subject = (sub.prototype || sub); | ||
if(!subject[methodName]){ | ||
if (!subject[methodName]) { | ||
subject[methodName] = Requires.requiredMethod; | ||
} | ||
} | ||
@@ -53,0 +57,0 @@ |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -9,5 +9,5 @@ */ | ||
var sequence = require('../sequence'), | ||
Merge = require('./Merge'), | ||
Static = function(){}; | ||
var sequence = require('../sequence'); | ||
var Merge = require('./Merge'); | ||
var Static = function () {}; | ||
@@ -21,5 +21,5 @@ Static.prototype = { | ||
setParameter: function(value){ | ||
if(Object.prototype.toString.call(value) !== '[object Object]'){ | ||
throw new Error('@static parameter should be an Object'); | ||
setParameter: function (value) { | ||
if (Object.prototype.toString.call(value) !== '[object Object]') { | ||
throw new Error('@static parameter should be an Object'); | ||
} | ||
@@ -29,7 +29,7 @@ this._parameter = value; | ||
getParameter: function() { | ||
getParameter: function () { | ||
return this._parameter; | ||
}, | ||
process: function(subject){ | ||
process: function (subject) { | ||
var statics = this.getParameter(), | ||
@@ -36,0 +36,0 @@ merger = new Merge({usePrototypeWhenSubjectIsClass: false}); |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -9,6 +9,6 @@ */ | ||
var Traits = require('./Traits'), | ||
Talents; | ||
var Traits = require('./Traits'); | ||
var Talents; | ||
Talents = function(){ | ||
Talents = function () { | ||
Traits.call(this); | ||
@@ -19,14 +19,14 @@ }; | ||
Talents.prototype._applyTalentTo = Traits.prototype._applyTraitTo; | ||
Talents.prototype._configName = 'talent'; | ||
Talents.prototype.process = function(subject){ | ||
var traits = this.getParameter(), // always an [] | ||
l = traits.length, | ||
i; | ||
Talents.prototype.process = function (subject) { | ||
var traits = this.getParameter(), // always an [] | ||
l = traits.length, | ||
i; | ||
for(i = 0; i < l; i++){ | ||
this._applyTalentTo(subject, traits[i]); | ||
} | ||
for (i = 0; i < l; i++) { | ||
this._applyTo(subject, traits[i]); | ||
} | ||
}; | ||
module.exports = Talents; |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -9,5 +9,5 @@ */ | ||
var sequence = require('../sequence'), | ||
Requires = require('./Requires'), | ||
Traits = function(){}; | ||
var sequence = require('../sequence'); | ||
var Requires = require('./Requires'); | ||
var Traits = function () {}; | ||
@@ -19,5 +19,7 @@ Traits.prototype = { | ||
_configName: 'trait', | ||
_parameter: [], | ||
setParameter: function(value){ | ||
setParameter: function (value) { | ||
//TODO: validate parameter | ||
@@ -27,7 +29,7 @@ this._parameter = [].concat(value); | ||
getParameter: function() { | ||
getParameter: function () { | ||
return this._parameter; | ||
}, | ||
process: function(subject){ | ||
process: function (subject) { | ||
var traits = this.getParameter(), // always an [] | ||
@@ -37,12 +39,20 @@ l = traits.length, | ||
for(i = 0; i < l; i++){ | ||
this._applyTraitTo(subject.prototype || subject, traits[i]); | ||
for (i = 0; i < l; i++) { | ||
this._applyTo(subject.prototype || subject, traits[i]); | ||
} | ||
}, | ||
_applyTraitTo: function(subject, options){ | ||
var key, tp, excluded, aliases, alias,t; | ||
_isApplicable: function (option) { | ||
var type = this._configName; | ||
return (typeof option === 'function') || (option && !option[type]); | ||
}, | ||
if(typeof options === 'function'){ | ||
return this._applyTraitTo(subject, {trait: options}); | ||
_applyTo: function (subject, options) { | ||
var type = this._configName, | ||
o = {}, | ||
key, tp, excluded, aliases, t; | ||
if (this._isApplicable(options)) { | ||
o[type] = options; | ||
return this._applyTo(subject, o); | ||
} | ||
@@ -52,17 +62,20 @@ | ||
aliases = options.alias || {}; | ||
t = options.trait || options.talent; | ||
tp = t.prototype; | ||
t = options[type]; | ||
tp = t.prototype || t; | ||
for(key in tp){ | ||
for (key in tp) { | ||
this._raiseErrorIfItIsState(key, tp); | ||
if(excluded.indexOf(key) === -1){ | ||
alias = aliases[key] || key; | ||
this._applyIfNotExcluded(key, excluded, aliases, subject, tp); | ||
} | ||
}, | ||
this._raiseErrorIfConflict(alias, subject, tp); | ||
if(!subject[alias] || subject[alias] === Requires.requiredMethod){ | ||
subject[alias] = tp[key]; | ||
} | ||
_applyIfNotExcluded: function (key, excluded, aliases, subject, tp) { | ||
var alias; | ||
if (excluded.indexOf(key) === -1) { | ||
alias = aliases[key] || key; | ||
this._raiseErrorIfConflict(alias, subject, tp); | ||
if (!subject[alias] || subject[alias] === Requires.requiredMethod) { | ||
subject[alias] = tp[key]; | ||
} | ||
@@ -72,4 +85,4 @@ } | ||
_raiseErrorIfItIsState: function(key, traitProto){ | ||
if(typeof traitProto[key] !== 'function'){ | ||
_raiseErrorIfItIsState: function (key, traitProto) { | ||
if (typeof traitProto[key] !== 'function') { | ||
throw new Error('Trait MUST NOT contain any state. Found: ' + key + ' as state while processing trait'); | ||
@@ -79,3 +92,3 @@ } | ||
_raiseErrorIfConflict: function(methodName, subjectProto, traitProto){ | ||
_raiseErrorIfConflict: function (methodName, subjectProto, traitProto) { | ||
var requiredMethodName = Requires.requiredMethod.name, | ||
@@ -90,3 +103,3 @@ subjectMethod = subjectProto[methodName], | ||
if(sameMethodName && methodsAreNotTheSame && traitMethodIsNotARequired && subjecMethodIsNotARequired){ | ||
if (sameMethodName && methodsAreNotTheSame && traitMethodIsNotARequired && subjecMethodIsNotARequired) { | ||
throw new Error('Same method named: ' + methodName + ' is defined in trait and Class.' ); | ||
@@ -97,2 +110,2 @@ } | ||
module.exports = Traits; | ||
module.exports = Traits; |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
@@ -8,5 +8,6 @@ */ | ||
var sequence = require('./sequence'), | ||
NoOp = function(){}; | ||
var sequence = require('./sequence'); | ||
var NoOp = function () {}; | ||
NoOp.prototype = { | ||
@@ -21,2 +22,2 @@ retain : false, | ||
module.exports = NoOp; | ||
module.exports = NoOp; |
/* | ||
* | ||
* Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
* Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
* Licensed under the MIT license. | ||
*/ | ||
"use strict"; | ||
'use strict'; | ||
/** | ||
* sequence list | ||
The processors will use one of the defined priorities in this list | ||
The priorities are organized in groups: | ||
[-1] No Op. | ||
[-1] No Op. | ||
[1..99) Object/Class creation. | ||
[99..999) Merge - Traits and talents are considered merge stage since we copy the structure into the subject. | ||
[999..) Miscelaneous - Annotation definition makes no changes over the Subject itself. | ||
*/ | ||
@@ -34,3 +33,3 @@ | ||
REQUIRES : 30, | ||
POST_REQUIRES : 31, | ||
POST_REQUIRES : 31, | ||
@@ -54,2 +53,1 @@ PRE_MERGE : 99, | ||
}; | ||
{ | ||
"name": "cocktail", | ||
"description": "CocktailJS is a small library to explore traits, talents, inheritance and annotations concepts in nodejs - Shake your objects and classes with Cocktail!", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"homepage": "http://cocktailjs.github.io", | ||
@@ -28,15 +28,15 @@ "author": { | ||
"scripts": { | ||
"test": "grunt test" | ||
"test": "npm run lint && npm run unit && npm run integration", | ||
"unit": "mocha --recursive test/unit/", | ||
"integration": "mocha --recursive test/integration/", | ||
"lint": "eslint --quiet lib/ test/", | ||
"coverage": "istanbul cover _mocha -- -u exports --recursive test" | ||
}, | ||
"devDependencies": { | ||
"grunt-simple-mocha": "~0.4", | ||
"chai": "~1.9", | ||
"mocha": "~1.19", | ||
"grunt-contrib-jshint": "~0.10", | ||
"grunt-contrib-watch": "~0.6", | ||
"grunt": "~0.4", | ||
"sinon-chai": "~2.5", | ||
"sinon": "~1.10", | ||
"grunt-cli": "~0.1.13", | ||
"grunt-mocha-test": "~0.10.2" | ||
"chai": "~2.1", | ||
"eslint": "^0.15", | ||
"istanbul": "^0.3.6", | ||
"mocha": "~2.1", | ||
"sinon": "~1.12", | ||
"sinon-chai": "~2.7" | ||
}, | ||
@@ -43,0 +43,0 @@ "keywords": [ |
# Cocktail JS | ||
[![Build Status](https://travis-ci.org/CocktailJS/cocktail.png?branch=master)](https://travis-ci.org/CocktailJS/cocktail) | ||
[![NPM version](https://badge.fury.io/js/cocktail.png)](http://badge.fury.io/js/cocktail) | ||
[![Code Climate](https://codeclimate.com/github/CocktailJS/cocktail.png)](https://codeclimate.com/github/CocktailJS/cocktail) | ||
[![Build Status](https://travis-ci.org/CocktailJS/cocktail.svg?branch=master)](https://travis-ci.org/CocktailJS/cocktail) | ||
[![npm version](https://badge.fury.io/js/cocktail.svg)](http://badge.fury.io/js/cocktail) | ||
<!-- Removed until bitHound understands eslint | ||
[![bitHound Score](https://www.bithound.io/CocktailJS/cocktail/badges/score.svg)](https://www.bithound.io/CocktailJS/cocktail) | ||
--> | ||
[![Code Climate](https://codeclimate.com/github/CocktailJS/cocktail/badges/gpa.svg)](https://codeclimate.com/github/CocktailJS/cocktail) | ||
@@ -42,3 +45,3 @@ Cocktail is a small but yet powerful library with very simple principles: | ||
## Defining a Class / Module | ||
Using cocktail to define a class is easy an elegant. | ||
Using cocktail to define a class is easy and elegant. | ||
@@ -236,12 +239,29 @@ ```js | ||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
### Running Tests | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. | ||
### Running Lint & Tests | ||
Add your unit and/or integration tests and execute | ||
$ grunt test | ||
$ npm test | ||
### Run unit tests | ||
$npm run unit | ||
### Run integration tests | ||
$npm run integration | ||
### Lint your code | ||
$ npm run lint | ||
### Before Commiting | ||
Run grunt to check lint and execute tests | ||
Run `npm test` to check lint and execute tests | ||
$ grunt | ||
$ npm test | ||
@@ -251,10 +271,5 @@ | ||
Install instanbul from npm globally if you don't have it already installed | ||
$ npm run coverage | ||
$ npm install -g istanbul | ||
Run | ||
$ istanbul cover _mocha -- -u exports --recursive test | ||
## Release History | ||
@@ -265,3 +280,3 @@ | ||
## License | ||
Copyright (c) 2013 - 2014 Maximiliano Fierro | ||
Copyright (c) 2013 - 2015 Maximiliano Fierro | ||
Licensed under the MIT license. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37366
6
797
279