modella-context

1.2.0 • Public • Published

modella-context

Build Status Dependency Status

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.

MIT Licensed

Readme

Keywords

none

Package Sidebar

Install

npm i modella-context

Weekly Downloads

0

Version

1.2.0

License

MIT

Last publish

Collaborators

  • amingoia