Permalink
Browse files

add subject requests ("who?")

  • Loading branch information...
1 parent e2d571e commit 76a5fa06bdc5984c6f754609a3f8ff5c8974c5a0 Carlos Rodriguez committed Oct 16, 2012
Showing with 399 additions and 9 deletions.
  1. +52 −0 README.md
  2. +218 −5 parser.js
  3. +21 −1 parser.pegjs
  4. +20 −0 stores/memory.js
  5. +24 −3 stores/mysql.js
  6. +48 −0 stores/redis.js
  7. +16 −0 test/common.js
View
@@ -162,6 +162,40 @@ The syntax for a **role request** consists of:
( What | what ) is <subject> [ a / an / the ] <role> [ of / to / from / in ] [?]
```
+Verb subject request
+--------------------
+
+To request an array of subjects who can perform an action on an object:
+
+```js
+relations.repos('Who can pull from %s?', 'buffet', function (err, users) {
+ // users = ['Carlos']
+});
+```
+
+### Syntax
+
+```
+( Who | who ) can <verb> [ of / to / from / in ] <object> [?]
+```
+
+Role subject request
+--------------------
+
+To request an array of subjects who have a role for an object:
+
+```js
+relations.repos('Who is the owner of %s?', 'buffet', function (err, users) {
+ // users = ['Carlos']
+});
+```
+
+### Syntax
+
+```
+( Who | who ) can <verb> [ of / to / from / in ] <object> [?]
+```
+
Revocation
----------
@@ -276,6 +310,24 @@ Respond to a role request and call `cb(err, /* array */ objects)` with the resul
- subject
- role
+### `verb-subject-request` (cmd, cb)
+
+Respond to a verb subject request and call `cb(err, /* array */ subjects)` with
+the result. `cmd` will be an object containing the properties:
+
+- ctx - context object
+- verb
+- object
+
+### `role-subject-request` (cmd, cb)
+
+Respond to a role subject request and call `cb(err, /* array */ subjects)` with
+the result. `cmd` will be an object containing the properties:
+
+- ctx - context object
+- role
+- object
+
### `reset` (cb)
Reset the store, dumping all storage and structure, calling `cb(err)` when done.
View
Oops, something went wrong.
View
@@ -4,7 +4,9 @@
start
= ret:(
- RoleQuestion
+ RoleSubjectRequest
+ / VerbSubjectRequest
+ / RoleQuestion
/ RoleRequest
/ Declaration
/ VerbRequest
@@ -72,6 +74,24 @@ RoleRequest "role request"
}
}
+VerbSubjectRequest "verb subject request"
+ = "who can "i verb:Token Preposition? " " object:Token "?"? {
+ return {
+ type: "verb-subject-request",
+ object: object,
+ verb: verb
+ }
+ }
+
+RoleSubjectRequest "role subject request"
+ = "who "i Positive Quantifier? " " role:Token Preposition? " " object:Token "?"? {
+ return {
+ type: "role-subject-request",
+ object: object,
+ role: role
+ }
+ }
+
Token "token"
= NamedToken / UnnamedToken / Literal
View
@@ -74,4 +74,24 @@ store.on('role-request', function (cmd, cb) {
cb(null, Object.keys(subject.objects).filter(function (k) {
return subject.objects[k][cmd.role];
}));
+});
+
+store.on('verb-subject-request', function (cmd, cb) {
+ contexts[cmd.ctx.name] || (contexts[cmd.ctx.name] = {});
+ cb(null, Object.keys(contexts[cmd.ctx.name]).filter(function (subject) {
+ subject = contexts[cmd.ctx.name][subject];
+ if (!subject.objects[cmd.object]) return false;
+ return Object.keys(subject.objects[cmd.object]).some(function (role) {
+ return ~cmd.ctx.verbs[cmd.verb].indexOf(role);
+ });
+ }));
+});
+
+store.on('role-subject-request', function (cmd, cb) {
+ contexts[cmd.ctx.name] || (contexts[cmd.ctx.name] = {});
+ cb(null, Object.keys(contexts[cmd.ctx.name]).filter(function (subject) {
+ subject = contexts[cmd.ctx.name][subject];
+ if (!subject.objects[cmd.object]) return false;
+ return subject.objects[cmd.object][cmd.role];
+ }));
});
Oops, something went wrong.

0 comments on commit 76a5fa0

Please sign in to comment.