Skip to content

Commit

Permalink
Update mask prototype property to class property
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Gama committed Oct 26, 2016
1 parent 9d2a8e9 commit b79ca56
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ var mask = require('bookshelf-mask');
bookshelf.plugin(mask);
```

Define masks on your models with `masks` prototype property:
Define masks on your models with `masks` class property:

```js
var Author = bookshelf.Model.extend({
masks: {
custom: 'id,name'
},
posts: {
return this.hasMany(Post);
},
tableName: 'Author'
}, {
masks: {
custom: 'id,name'
}
});
```

Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import mask from 'json-mask';
export default Bookshelf => {
Bookshelf.Model = Bookshelf.Model.extend({
mask(scope, options) {
return mask(this.toJSON(options), this.masks && this.masks[scope] || scope);
return mask(this.toJSON(options), this.constructor.masks && this.constructor.masks[scope] || scope);
}
});

Bookshelf.Collection = Bookshelf.Collection.extend({
mask(scope, options) {
scope = this.model.prototype.masks && this.model.prototype.masks[scope] || scope;
scope = this.model.masks && this.model.masks[scope] || scope;

return this.toJSON(options).map(model => mask(model, scope));
}
Expand Down
5 changes: 3 additions & 2 deletions test/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ export function dropTables(repository) {

export function fixtures(repository) {
const Post = repository.Model.extend({
tableName: 'Post'
}, {
masks: {
private: 'foo'
},
tableName: 'Post'
}
});

const Author = repository.Model.extend({
Expand Down

0 comments on commit b79ca56

Please sign in to comment.