Class: MemoryStore

MemoryStore

Represents a Memory rule store.

new MemoryStore()

Constructor for Memory rule store.

This store keeps rules in memory only. Rules are not persisted across application reloads and therefore they have to be loaded early in the application start (initialization) phase.

This is the default store for authority and it doesn’t have to be explicitly configured unless it is used in conjunction with other stores.

Source:
Example
 var authority = require("authority");

 authority.setRules([{
         name: "allow_managers_only",
            description: "Only managers can pass.",
            condition: { title: "Manager" }
     }, {
         name: "allow_teenagers_only",
            description: "Only users between 13 and 19 years old can pass.",
            condition: { age: { $gte: 13, $lte: 19 } }
     }
 ]);

Members

name

The name of this store. The default value is "memory". NOTE: every store is required to have a unique name within a manager.

Source:

rules

The object that holds the references to all stored rules. NOTE: this member is not part of the Authority API and it is specific to this store only.

Source:

Methods

deleteRules(names, done) → {null}

Removes the specified rules from the store.

Parameters:
Name Type Argument Description
names string | Array.<string>

The name or an array of names to remove.

done function <optional>

Optional callback function that will be called after the rule(s) have been deleted. If the method is unsuccessful an error object will be passed as a single parameter to the callback. If the callback is omitted and the method is unsuccessful an error will be thrown.

Source:
Returns:
Type
null

getRule(name, done) → {null}

Retrieves the specified rule from the store.

Parameters:
Name Type Description
name string

The name of the rule.

done function

The callback that handles the result. The first parameter will always be null for this store while the second parameter will contain the requested rule or null if not found.

Source:
Returns:
Type
null

getRuleCount(done)

Gets the total count of rules present in the store.

Parameters:
Name Type Description
done function

The callback that handles the result. The first parameter will always be null for this store while the second parameter will contain a number representing the total count of rules.

Source:

getRuleNames(start, count, match, done)

Retrieves the names and descriptions of the rules present in the store and matching the specified criteria.

All parameters are required.

Parameters:
Name Type Description
start number

The index at wich to begin retrieving names. The index of the first element is 0.

count number

The number of names to retrieve. 0 denotes all remaining.

match string

Wildcard expression to match names. null denotes any name. Example: allow_*

done function

The callback that handles the result. The first parameter will always be null for this store while the second parameter will contain an array of matched objects { name: "string", description: "string" }.

Source:

setRules(rules, override, done) → {null}

Adds one or more rules to the store.

Parameters:
Name Type Argument Description
rules object | Array.<object>

The rule or an array of rules to be added to the store.

override boolean <optional>

Specifies whether existing rules should be replaced by the ones provided to this method. Rules are matched by their name. If this parameter is not specified or is false and there is a name conflict an error will be returned or thrown depending on the usage of the method.

done function <optional>

Optional callback function that will be called after the rule(s) have been added. If the method is unsuccessful an error object will be passed as a single parameter to the callback. If the callback is omitted and the method is unsuccessful an error will be thrown.

Source:
Returns:
Type
null
Authority Copyright © 2013-2014 The contributors to the Authority projects.
Documentation generated by JSDoc 3.2.2 on Sat Jan 18 2014 02:44:25 GMT+0200 (EET) using the DocStrap template.