Skip to content

Commit

Permalink
first pass at metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jesuscript committed May 11, 2014
1 parent 78abee2 commit eaa5661
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion lib/fortune.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Fortune.prototype._defaults = {
* @param {Object} options
*/
Fortune.prototype._init = function (options) {
var router;
var _this = this,
router;

// Initialize options.
options = typeof options === 'object' ? options : {};
Expand All @@ -101,6 +102,31 @@ Fortune.prototype._init = function (options) {

// Create a database adapter instance.
this.adapter = new Adapter(options, inflect);

router.get("/metadata", function(req,res){
res.write(JSON.stringify({metadata: _.reduce(_this.schemas, function(memo, schema, name){
_.each(schema, function(v,k){
var vIsObject = _.isObject(v),
typeFn = vIsObject ? v.type : v;

if(typeFn){
typeFn = typeFn.toString();
typeFn = typeFn.substr('function '.length);
typeFn = typeFn.substr(0, typeFn.indexOf('('));

if(vIsObject){
v.type = typeFn;
}else{
schema[k] = typeFn;
}
}
});

memo[name] = schema;
return memo;
}, {})}));
res.end();
});
};

/**
Expand Down Expand Up @@ -152,6 +178,10 @@ Fortune.prototype.resource = function(name, schema, options) {
}, function (error) {
console.trace(error);
});

this.schemas = this.schemas || {};
this.schemas[name] = schema;

return this;
};

Expand Down

0 comments on commit eaa5661

Please sign in to comment.