<commit_before>/**
 * Created by jeff.flater on 4/23/2014.
 */
var dummyJson = require('dummy-json'),
    jsonStore = require('json-store'),
    validator = require('validator');

var configOptions = [
  'jsonStore',
  'mockRoutes'
];

var routes,
    store;

function Mock(config) {
    // Validate JSON object
    //todo: replace with validator
    if (!_tryParseJSON(JSON.stringify(config))) {
        throw 'Invalid json config object!';
    }

    // Validate config options
    for (var i=0; i < configOptions.length; i++) {
        if (!config.hasOwnProperty(configOptions[i])) {
            throw 'Missing required config options';
        }
    }

    store = jsonStore(config.jsonStore);
    routes = config.mockRoutes;
}

Mock.prototype.registerRoutes = function (req, res) {

    var found = false;
    var matchingMethod;

    for (var i = 0; i < routes.length; i++) {
        
        if (!(typeof routes[i].method === 'string' || routes[i].method instanceof String)) {
            routes[i].method = 'get';
        }

        matchingMethod = (routes[i].method.toLowerCase() === req.method.toLowerCase());

        if (req.path.match(routes[i].mockRoute) !== null && matchingMethod) {

            found = true;

            var route = routes[i];

            //If scope & scenario is passed via the url; then, overwrite the testScope & testScenario properties
            if (typeof req.query !== 'undefined') {
<commit_msg>Update mock.js<commit_after>/**
 * Created by jeff.flater on 4/23/2014.
 */
var dummyJson = require('dummy-json'),
    jsonStore = require('json-store'),
    validator = require('validator');

var configOptions = [
  'jsonStore',
  'mockRoutes'
];

var routes,
    store;

function Mock(config) {
    // Validate JSON object
    //todo: replace with validator
    if (!_tryParseJSON(JSON.stringify(config))) {
        throw 'Invalid json config object!';
    }

    // Validate config options
    for (var i=0; i < configOptions.length; i++) {
        if (!config.hasOwnProperty(configOptions[i])) {
            throw 'Missing required config options';
        }
    }

    store = jsonStore(config.jsonStore);
    routes = config.mockRoutes;
}

Mock.prototype.registerRoutes = function (req, res) {

    var found = false;
    var matchingMethod;

    for (var i = 0; i < routes.length; i++) {
        
        if (!(typeof routes[i].method === 'string' || routes[i].method instanceof String)) {
            routes[i].method = 'get';
        }

        matchingMethod = (routes[i].method.toLowerCase() === req.method.toLowerCase());

        if (req.path.match(routes[i].mockRoute.toLowerCase()) !== null && matchingMethod) {

            found = true;

            var route = routes[i];

            //If scope & scenario is passed via the url; then, overwrite the testScope & testScenario properties
            if (typeof req.query !== 'undefined') {

{'fraction_non_alphanumeric': 0.1401449775629962, 'fraction_numerical': 0.006213324128408699, 'mean_word_length': 2.56019656019656, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2569377', 'n_tokens_mistral': 852, 'n_tokens_neox': 845, 'n_words': 223}