Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tylerlh/rolo
Simple roles for your Mongoose models
https://github.com/tylerlh/rolo
Last synced: about 2 months ago
JSON representation
Simple roles for your Mongoose models
- Host: GitHub
- URL: https://github.com/tylerlh/rolo
- Owner: TylerLH
- Created: 2014-12-28T19:00:45.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-29T06:53:30.000Z (about 10 years ago)
- Last Synced: 2024-11-15T00:15:58.475Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 141 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rolo
A simple roles plugin for Mongoose.js models.
## Installation
1. Use npm to install by running `npm install --save rolo` in your project
2. Register rolo as a plugin in your Mongoose models:```node
// ./models/user.jsvar mongoose = require('mongoose');
var Schema = mongoose.Schema;
var rolo = require('rolo');var schema = new Schema({
name: String
});schema.plugin(rolo);
module.exports = mongoose.model('User', schema);
```3. Use Rolo's methods to manage and query your model's roles.
```node
var User = require('./models/user');User.find({name: 'Tyler'}, function (err, user) {
if (err) throw err;// Assign a role to a model
user.addRole('admin', function(err, added) {
if (err) throw err;
if (added) {
// Role was added successfully, do stuff
}
});// Query a model for a specific role
if ( user.hasRole('admin') ) {
// user is an admin
}// etc...
})
```### License Information
Copyright (c) 2014, Tyler Hughes
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.