-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
41 lines (31 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// index.js - Main interface file
module.exports = (function() {
var EventEmitter = require('events').EventEmitter
, acl = new EventEmitter();
acl.MemoryStore = require('./memory-store');
acl.RedisStore = require('./redis-store');
acl.MockStore = require('./mock-store');
// function shim
var shim = function(obj, action) {
var func = obj[action];
return function(grantee, resource, callback) {
acl.emit(action, grantee, resource);
func.call(obj, grantee, resource, callback);
};
};
// store management.
acl.store = null;
acl.use = function(store) {
acl.store = store;
acl.grant = shim(store, 'grant');
acl.assert = shim(store, 'assert');
acl.revoke = shim(store, 'revoke');
};
// dud function (replaced by .use)
acl.grant = function(grantee, resource, callback) { };
acl.assert = function(grantee, resource, callback) { };
acl.revoke = function(grantee, resource, callback) { };
// defaults to MemoryStore on first use
acl.use(new acl.MemoryStore());
return acl;
})();