From 31b588ec6b8b1d5d31746f92d2c752a1c2178ed5 Mon Sep 17 00:00:00 2001 From: Richard Walker Date: Sat, 22 Mar 2014 18:45:45 +0100 Subject: [PATCH 1/3] Improve API section of documentation Fix #13 --- README.md | 105 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 590cacb..91f003c 100644 --- a/README.md +++ b/README.md @@ -173,28 +173,115 @@ example: ## API -`admittance(permissionsobject, assignmentsobject)` +### admittanceModule(permissionsobject, assignmentsobject) Load permissions and assignments from js objects and return an admittance instance. See the "Writing permissions" and "Writing assignments" sections above for how to write a permissions and assignments object -Admittance instance methods: (returned from admittance method) +Parameters: -`is(permission)` +- permissions +- assignments + +Returns: + +- admittance + +Example: + +```js +var admittanceModule = require('admittance') +var admittance = admittanceModule(permissionsObject, assignmentObject) +``` + +### admittance(userid) + +Parameters: + +- userid + +Returns: + +- - A function with is, isnt, can and cant methods populated with userid + +Example: + +```js +var userId = 1 +admittance(userId) //returns a new function with methods is, isnt, can and cant +``` + +#### .is(permission) Test if a given 'id' can be matched with given 'permission' -`isnt(permission)` +Parameters: + +- permission + +Returns: + +- + +Example: + +```js +admittance(userId).is('admin') //true or false +``` + +#### .isnt(permission) -Opposite of is. Equivalent of writing `!admittance(id).is(permission)` +Opposite of `is`. Equivalent of writing `!admittance(id).is(permission)` -`can(permission)` +Parameters: -Alias for is +- permission -`cant(permission)` +Returns: -Alias for isnt +- + +Example: + +```js +admittance(userId).isnt('admin') //true or false +``` + +#### .can(permission) + +Alias for `is` + +Parameters: + +- permission + +Returns: + +- + +Example: + +```js +admittance(userId).can('edit') //true or false +``` + +#### .cant(permission) + +Alias for `isnt` + +Parameters: + +- permission + +Returns: + +- + +Example: + +```js +admittance(userId).cant('edit') //true or false +``` ## Tests From b62a911a7463878041a41e0540df422e828b5607 Mon Sep 17 00:00:00 2001 From: Richard Walker Date: Sat, 22 Mar 2014 18:52:10 +0100 Subject: [PATCH 2/3] Update API docs to code quote angle brackets --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 91f003c..cb4c61c 100644 --- a/README.md +++ b/README.md @@ -180,12 +180,12 @@ for how to write a permissions and assignments object Parameters: -- permissions -- assignments +- permissions `` +- assignments `` Returns: -- admittance +- admittance `` Example: @@ -198,11 +198,11 @@ var admittance = admittanceModule(permissionsObject, assignmentObject) Parameters: -- userid +- userid `` Returns: -- - A function with is, isnt, can and cant methods populated with userid +- `` - A function with is, isnt, can and cant methods populated with userid Example: @@ -217,11 +217,11 @@ Test if a given 'id' can be matched with given 'permission' Parameters: -- permission +- permission `` Returns: -- +- `` Example: @@ -235,11 +235,11 @@ Opposite of `is`. Equivalent of writing `!admittance(id).is(permission)` Parameters: -- permission +- permission `` Returns: -- +- `` Example: @@ -253,11 +253,11 @@ Alias for `is` Parameters: -- permission +- permission `` Returns: -- +- `` Example: @@ -271,11 +271,11 @@ Alias for `isnt` Parameters: -- permission +- permission `` Returns: -- +- `` Example: From 662c348c6a126147ef9a525a69a97b5ab885c0cf Mon Sep 17 00:00:00 2001 From: Richard Walker Date: Sat, 22 Mar 2014 18:53:42 +0100 Subject: [PATCH 3/3] Code quote is, isnt, cant and cant methods --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb4c61c..6bba02f 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ Parameters: Returns: -- `` - A function with is, isnt, can and cant methods populated with userid +- `` - A function with `is`, `isnt`, `can` and `cant` methods populated with userid Example: