Skip to content

Commit

Permalink
Updated to new Admit One interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
wbyoung committed Jun 29, 2014
1 parent c996bd4 commit eead084
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

[Admit One][admit-one] adapter for MongoDB.

## Install

```
npm install admit-one admit-one-mongo
```

## Usage

```javascript
var admit = require('admit-one-mongo')({
var admit = require('admit-one')('mongo', {
mongo: {
db: 'mongodb://localhost/dbname'
}
Expand Down
20 changes: 9 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

var _ = require('lodash');
var monk = require('monk');
var admit = require('admit-one');
var bluebird = require('bluebird'), Promise = bluebird;

module.exports = function(options) {
var opts = admit.helpers.defaults({}, options, {
mongo: { collection: 'users' }
var opts = _.defaults({}, options.mongo, {
collection: 'users'
});
var db = monk(opts.mongo.db);
var users = db.get(opts.mongo.collection);
var db = monk(opts.db);
var users = db.get(opts.collection);

var create = function(attributes) {
return users.insert(attributes);
Expand All @@ -34,19 +32,19 @@ module.exports = function(options) {
{ $pull: { sessionDigests: token }});
};

opts._users = {
var adapter = {};

adapter.users = {
create: create,
find: find,
findByToken: findByToken,
addToken: addToken,
removeToken: removeToken
};

opts._attrs = {
adapter.attrs = {
all: function(user) { return user; }
};

return _.extend(admit(opts), { _options: opts });
return adapter;
};

module.exports.__admit = admit;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"author": "Whitney Young",
"license": "MIT",
"dependencies": {
"admit-one": "^0.2.0",
"bluebird": "^2.1.3",
"lodash": "^2.4.1",
"monk": "^0.9.0"
},
"devDependencies": {
"admit-one": "^0.3.0",
"bluebird": "^2.1.3",
"chai": "^1.9.1",
"coveralls": "^2.10.1",
"istanbul": "^0.2.11",
Expand Down

0 comments on commit eead084

Please sign in to comment.