src/index.js
function getRules (resource, role, create) {
        resource = typeof resource === 'undefined' ? null : resource;
        role = typeof role === 'undefined' ? null : role;
        create = typeof create === 'undefined' ? false : create;

        var visitor;

        // follow $resource
        do {
            if (resource === null) {
                visitor = _rules.allResources;
                break;
            }
            //var resourceId = resource.getResourceId();
            var resourceId = resource;
            if (_rules.byResourceId[resourceId] === undefined) {
                if (!create) {
                    return null;
                }
                _rules.byResourceId[resourceId] = {};
            }
            visitor = _rules.byResourceId[resourceId];
        } while (false);

        // follow $role
        if (role === null) {
            if (visitor.allRoles === undefined) {
                if (!create) {
                    return null;
                }
                set(visitor, 'allRoles.byPrivilegeId', {});
            }
            return visitor.allRoles;
        }
        //var roleId = role.getRoleId();
        var roleId = role;
        if (visitor.byRoleId === undefined || visitor.byRoleId[roleId] === undefined) {
            if (!create) {
                return null;
            }
            set(visitor, 'byRoleId.' + roleId + '.byPrivilegeId', {});
        }
        return visitor.byRoleId[roleId];
    }
function getRules (resource, role, create) {
        resource = typeof resource === 'undefined' ? null : resource;
        role = typeof role === 'undefined' ? null : role;
        create = typeof create === 'undefined' ? false : create;

        var visitor;

        // follow $resource
        do {
            if (resource === null) {
                visitor = _rules.allResources;
                break;
            }
            //var resourceId = resource.getResourceId();
            var resourceId = resource;
            if (_rules.byResourceId[resourceId] === undefined) {
                if (!create) {
                    return null;
                }
                _rules.byResourceId[resourceId] = {};
            }
            visitor = _rules.byResourceId[resourceId];
        } while (false);

        // follow $role
        if (role === null) {
            if (visitor.allRoles === undefined) {
                if (!create) {
                    return null;
                }
                set(visitor, 'allRoles.byPrivilegeId', {});
            }
            return visitor.allRoles;
        }
        //var roleId = role.getRoleId();
        var roleId = role;
        if (visitor.byRoleId === undefined || visitor.byRoleId[roleId] === undefined) {
            if (!create) {
                return null;
            }
            set(visitor, 'byRoleId.' + roleId + '.byPrivilegeId', {});
        }
        return visitor.byRoleId[roleId];
    }
function getRules ( resource , role , create ) { resource = typeof resource === 'undefined' ? null : resource ; role = typeof role === 'undefined' ? null : role ; create = typeof create === 'undefined' ? false : create ; var visitor ; // follow $resource do { if ( resource === null ) { visitor = _rules . allResources ; break ; } //var resourceId = resource.getResourceId(); var resourceId = resource ; if ( _rules . byResourceId [ resourceId ] === undefined ) { if ( ! create ) { return null ; } _rules . byResourceId [ resourceId ] = { } ; } visitor = _rules . byResourceId [ resourceId ] ; } while ( false ) ; // follow $role if ( role === null ) { if ( visitor . allRoles === undefined ) { if ( ! create ) { return null ; } set ( visitor , 'allRoles.byPrivilegeId' , { } ) ; } return visitor . allRoles ; } //var roleId = role.getRoleId(); var roleId = role ; if ( visitor . byRoleId === undefined || visitor . byRoleId [ roleId ] === undefined ) { if ( ! create ) { return null ; } set ( visitor , 'byRoleId.' + roleId + '.byPrivilegeId' , { } ) ; } return visitor . byRoleId [ roleId ] ; }
Returns the rules associated with a Resource and a Role, or null if no such rules exist

If either $resource or $role is null, this means that the rules returned are for all Resources or all Roles,
respectively. Both can be null to return the default rule set for all Resources and all Roles.

If the $create parameter is true, then a rule set is first created and then returned to the caller.

@param {string} [resource=null]
@param {string} [role=null]
@param {boolean} [create=false]
@return {Object|null}
Returns the rules associated with a Resource and a Role or null if no such rules exist