Code coverage report for lib\streams\RouteStream.js

Statements: 85% (34 / 40)      Branches: 50% (5 / 10)      Functions: 100% (10 / 10)      Lines: 85% (34 / 40)      Ignored: none     

All files » lib\streams\ » RouteStream.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71  1   1 7 7 7 7               1 60       1   1 4 60   4     4 4     1 1 1     1 1     1 1     1 1     1 1 1     1     1 5   1     1 1         1
'use strict';
var BaseStream = require('./BaseStream.js');
 
var RouteStream = function RouteStream(from) {
    Eif (this instanceof RouteStream) {
        this.init();
        Eif (from === undefined) {
            return this;
        }
        this.from(from);
        return this;
    }
    return new RouteStream(from);
};
 
function checkMethod (method, x) {
    return x.method === method;
};
 
 
RouteStream.prototype = new BaseStream();
 
RouteStream.prototype.onMethod = function(method, fn) {
    var filter = this.filter(function methodFilter(x){
        return checkMethod(method, x);
    });
    Iif (fn === undefined) {
        return filter;
    }
    filter.onValue(fn);
    return filter;
};
 
RouteStream.prototype.constructor = RouteStream;
RouteStream.prototype.onGet = function onGet(fn) {
    return this.onMethod('GET', fn);
};
 
RouteStream.prototype.onPost = function onPost(fn) {
    return this.onMethod('POST', fn);
};
 
RouteStream.prototype.onPut = function onPut(fn) {
    return this.onMethod('PUT', fn);
};
 
RouteStream.prototype.onDelete = function onDelete(fn) {
    return this.onMethod('DELETE', fn);
};
 
RouteStream.prototype.onUrl = function onUrl(url, fn) {
    var f = null;
    Iif (url instanceof RegExp) {
        f = url;
    } else {
        f = new RegExp(url);
    }
 
    var filter = this.filter(function urlFilter(x) {
        return f.test(x.url);
    });
    Iif (fn === undefined) {
        return filter;
    }
    filter.onValue(fn);
    return filter;
};
 
 
 
module.exports = RouteStream;