Created
October 17, 2015 16:11
-
-
Save ErisDS/bb8bfbb5b30396f39e01 to your computer and use it in GitHub Desktop.
Bookshelf plugin for introspecting tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash'); | |
module.exports = function (Bookshelf) { | |
var model = Bookshelf.Model, | |
collection = Bookshelf.Collection, | |
modelProto = model.prototype, | |
collProto = collection.prototype, | |
Model, | |
Collection; | |
//console.log('modelProto', modelProto); | |
//console.log('collProto', collProto); | |
if (Bookshelf.registry) { | |
console.log('registry plugin initialised'); | |
} | |
Model = Bookshelf.Model.extend({ | |
constructor: function () { | |
if (_.result(this, 'tableName') === 'tags') { | |
console.log('Model constructing', arguments); | |
} | |
return modelProto.constructor.apply(this, arguments); | |
}, | |
fetch: function () { | |
if (_.result(this, 'tableName') === 'tags') { | |
console.log('Model fetching', arguments); | |
} | |
return modelProto.fetch.apply(this, arguments); | |
} | |
}, | |
{ | |
forge: function () { | |
if (_.result(this.prototype, 'tableName') === 'tags') { | |
console.log('Model forging', arguments); | |
} | |
return model.forge.apply(this, arguments); | |
} | |
}); | |
Collection = Bookshelf.Collection.extend({ | |
constructor: function () { | |
if (_.result(arguments[1].model.prototype, 'tableName') === 'tags') { | |
console.log('Collection constructing', arguments); | |
} | |
return collProto.constructor.apply(this, arguments); | |
}, | |
fetch: function () { | |
if (_.result(this.model.prototype, 'tableName') === 'tags') { | |
console.log('Collection fetching', arguments); | |
} | |
return collProto.fetch.apply(this, arguments); | |
} | |
}); | |
Bookshelf.Model = Model; | |
Bookshelf.Collection = Collection; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment