Docs in code and export the format
This commit is contained in:
parent
17b582d682
commit
ad3902efaf
|
|
@ -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 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){
|
||||
this.spec = (_spec) ? new _spec(Cloudevent) : new Spec_0_1(Cloudevent);
|
||||
this.formatter = (_formatter) ? _formatter : new JSONFormatter_0_1();
|
||||
}
|
||||
|
||||
/*
|
||||
* To format the payload using the formatter
|
||||
*/
|
||||
Cloudevent.prototype.format = function(){
|
||||
return this.formatter.format(this.spec.payload);
|
||||
}
|
||||
|
|
@ -25,10 +33,21 @@ Cloudevent.prototype.source = function(_source){
|
|||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Export the specs
|
||||
*/
|
||||
Cloudevent.specs = {
|
||||
'0.1': Spec_0_1,
|
||||
'0.2': Spec_0_2
|
||||
};
|
||||
|
||||
/*
|
||||
* Export the formats
|
||||
*/
|
||||
Cloudevent.formats = {
|
||||
'json' : JSONFormatter_0_1,
|
||||
'json0.1': JSONFormatter_0_1
|
||||
};
|
||||
|
||||
module.exports = Cloudevent;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue