app/bin/router.js
function getActiveRoutes(params) {
        var activeRoutes = {},
            availableRoutes =
            {
                'index': 'GET     /',
                'create': 'POST    /',
                'new': 'GET     /new',
                'edit': 'GET     /:id/edit',
                'destroy': 'DELETE  /:id',
                'update': 'PUT     /:id',
                'show': 'GET     /:id',
                'destroyall': 'DELETE  /'
            },
            availableRoutesSingleton =
            {
                'show': 'GET     /show',
                'create': 'POST    /',
                'new': 'GET     /new',
                'edit': 'GET     /edit',
                'destroy': 'DELETE  /',
                'update': 'PUT     /',
                'destroyall': 'DELETE  /'
            };

        if (params.singleton) {
            availableRoutes = availableRoutesSingleton;
        }

        // 1. only
        if (params.only) {
            if (typeof params.only === 'string') {
                params.only = [params.only];
            }
            params.only.forEach(function (action) {
                if (action in availableRoutes) {
                    activeRoutes[action] = availableRoutes[action];
                }
            });
        }
        // 2. except
        else if (params.except) {
            if (typeof params.except === 'string') {
                params.except = [params.except];
            }
            for (var action1 in availableRoutes) {
                if (params.except.indexOf(action1) === -1) {
                    activeRoutes[action1] = availableRoutes[action1];
                }
            }
        }
        // 3. all
        else {
            for (var action2 in availableRoutes) {
                activeRoutes[action2] = availableRoutes[action2];
            }
        }

        return activeRoutes;
    }
function getActiveRoutes(params) {
        var activeRoutes = {},
            availableRoutes =
            {
                'index': 'GET     /',
                'create': 'POST    /',
                'new': 'GET     /new',
                'edit': 'GET     /:id/edit',
                'destroy': 'DELETE  /:id',
                'update': 'PUT     /:id',
                'show': 'GET     /:id',
                'destroyall': 'DELETE  /'
            },
            availableRoutesSingleton =
            {
                'show': 'GET     /show',
                'create': 'POST    /',
                'new': 'GET     /new',
                'edit': 'GET     /edit',
                'destroy': 'DELETE  /',
                'update': 'PUT     /',
                'destroyall': 'DELETE  /'
            };

        if (params.singleton) {
            availableRoutes = availableRoutesSingleton;
        }

        // 1. only
        if (params.only) {
            if (typeof params.only === 'string') {
                params.only = [params.only];
            }
            params.only.forEach(function (action) {
                if (action in availableRoutes) {
                    activeRoutes[action] = availableRoutes[action];
                }
            });
        }
        // 2. except
        else if (params.except) {
            if (typeof params.except === 'string') {
                params.except = [params.except];
            }
            for (var action1 in availableRoutes) {
                if (params.except.indexOf(action1) === -1) {
                    activeRoutes[action1] = availableRoutes[action1];
                }
            }
        }
        // 3. all
        else {
            for (var action2 in availableRoutes) {
                activeRoutes[action2] = availableRoutes[action2];
            }
        }

        return activeRoutes;
    }
function getActiveRoutes ( params ) { var activeRoutes = { } , availableRoutes = { 'index' : 'GET     /' , 'create' : 'POST    /' , 'new' : 'GET     /new' , 'edit' : 'GET     /:id/edit' , 'destroy' : 'DELETE  /:id' , 'update' : 'PUT     /:id' , 'show' : 'GET     /:id' , 'destroyall' : 'DELETE  /' } , availableRoutesSingleton = { 'show' : 'GET     /show' , 'create' : 'POST    /' , 'new' : 'GET     /new' , 'edit' : 'GET     /edit' , 'destroy' : 'DELETE  /' , 'update' : 'PUT     /' , 'destroyall' : 'DELETE  /' } ; if ( params . singleton ) { availableRoutes = availableRoutesSingleton ; } // 1. only if ( params . only ) { if ( typeof params . only === 'string' ) { params . only = [ params . only ] ; } params . only . forEach ( function ( action ) { if ( action in availableRoutes ) { activeRoutes [ action ] = availableRoutes [ action ] ; } } ) ; } // 2. except else if ( params . except ) { if ( typeof params . except === 'string' ) { params . except = [ params . except ] ; } for ( var action1 in availableRoutes ) { if ( params . except . indexOf ( action1 ) === - 1 ) { activeRoutes [ action1 ] = availableRoutes [ action1 ] ; } } } // 3. all else { for ( var action2 in availableRoutes ) { activeRoutes [ action2 ] = availableRoutes [ action2 ] ; } } return activeRoutes ; }
calculate set of routes based on params.only and params.except
calculate set of routes based on params . only and params . except