Docs in code and export the format
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
104b74acf5
commit
2ba9916153
|
|
@ -2,11 +2,19 @@ var Spec_0_1 = require('./specs/spec_0_1.js');
|
||||||
var Spec_0_2 = require('./specs/spec_0_2.js');
|
var Spec_0_2 = require('./specs/spec_0_2.js');
|
||||||
var JSONFormatter_0_1 = require('./formats/json_0_1.js');
|
var JSONFormatter_0_1 = require('./formats/json_0_1.js');
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class created using the Builder Design Pattern.
|
||||||
|
*
|
||||||
|
* https://en.wikipedia.org/wiki/Builder_pattern
|
||||||
|
*/
|
||||||
function Cloudevent(_spec, _formatter){
|
function Cloudevent(_spec, _formatter){
|
||||||
this.spec = (_spec) ? new _spec(Cloudevent) : new Spec_0_1(Cloudevent);
|
this.spec = (_spec) ? new _spec(Cloudevent) : new Spec_0_1(Cloudevent);
|
||||||
this.formatter = (_formatter) ? _formatter : new JSONFormatter_0_1();
|
this.formatter = (_formatter) ? _formatter : new JSONFormatter_0_1();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To format the payload using the formatter
|
||||||
|
*/
|
||||||
Cloudevent.prototype.format = function(){
|
Cloudevent.prototype.format = function(){
|
||||||
return this.formatter.format(this.spec.payload);
|
return this.formatter.format(this.spec.payload);
|
||||||
}
|
}
|
||||||
|
|
@ -25,10 +33,21 @@ Cloudevent.prototype.source = function(_source){
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Export the specs
|
||||||
|
*/
|
||||||
Cloudevent.specs = {
|
Cloudevent.specs = {
|
||||||
'0.1': Spec_0_1,
|
'0.1': Spec_0_1,
|
||||||
'0.2': Spec_0_2
|
'0.2': Spec_0_2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Export the formats
|
||||||
|
*/
|
||||||
|
Cloudevent.formats = {
|
||||||
|
'json' : JSONFormatter_0_1,
|
||||||
|
'json0.1': JSONFormatter_0_1
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = Cloudevent;
|
module.exports = Cloudevent;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue