Skip to content

Commit

Permalink
Merge pull request #14 from digitalsadhu/update/documentation#13
Browse files Browse the repository at this point in the history
Update/documentation#13
  • Loading branch information
digitalsadhu committed Mar 22, 2014
2 parents 34da842 + 662c348 commit 9ef63cd
Showing 1 changed file with 96 additions and 9 deletions.
105 changes: 96 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,115 @@ example:
<a name="api"></a>
## 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 `<object>`
- assignments `<object>`

Returns:

- admittance `<function>`

Example:

```js
var admittanceModule = require('admittance')
var admittance = admittanceModule(permissionsObject, assignmentObject)
```

### admittance(userid)

Parameters:

- userid `<string|int>`

Returns:

- `<function>` - 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 `<string>`

Returns:

- `<boolean>`

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 `<string>`

`cant(permission)`
Returns:

Alias for isnt
- `<boolean>`

Example:

```js
admittance(userId).isnt('admin') //true or false
```

#### .can(permission)

Alias for `is`

Parameters:

- permission `<string>`

Returns:

- `<boolean>`

Example:

```js
admittance(userId).can('edit') //true or false
```

#### .cant(permission)

Alias for `isnt`

Parameters:

- permission `<string>`

Returns:

- `<boolean>`

Example:

```js
admittance(userId).cant('edit') //true or false
```

<a name="tests"></a>
## Tests
Expand Down

0 comments on commit 9ef63cd

Please # to comment.