modella-context
v1.2.0
Published
Context access control for Modella.
Downloads
2
Readme
modella-context
context access control for modella.
Installation
Node
Using npm:
npm install modella-context
Browser
Using component:
component install alexmingoia/modella-context
Example
var access = require('modella-context')
, modella = require('modella');
var User = modella('User');
User
.attr('id')
.attr('name')
.attr('password')
.use(access)
.allow([ 'id', 'name' ], { role: 'guest' });
var user = new User({ name: 'alex', password: 'secret' });
user.context({ role: 'guest' });
user.toJSON();
// => { id: 1, name: 'alex' }
API
Model.allow(attrs, context)
Allow attrs
for the given context
.
Model#context(context)
Set the model instance's context
. Model#toJSON()
will only return
attributes allowed for the context, if it has been set.
Model#toJSON()
Returns only the attributes allowed by the model instance's current context, if it has been set.