<commit_before>
module.exports = (function() {

  var fs = require('fs')
    , parse = require('./grammar.js').parse;

  function createRouter(filename) {
    var routes = parse(fs.readFileSync(filename, 'utf-8'))
      , handlers = null;

    routes.handlers = function(handlers_) { handlers = handlers_; };

    routes.express = function(app) {
      var count = routes.length, i = 0
        , route = null, mapping = null, group = null;

      if (!handlers) throw new Error('must register handlers() first.');

      for (; i < count; i++) {
        route = routes[i];
        mapping = route.mapping;
        if (!((group = handlers[mapping.group]) && (handler = group[mapping.action])))
            continue;

        app[route.method.toLowerCase()](route.url.pathname, handler);
      }
    };

    routes.route = function(req) {
      var count = routes.length, i = 0, route = null;

      if (typeof req === 'string') {
        for (; i < count; i++) {
          route = routes[i];
          if (route.url.path == req) return route;
        }

      } else {
        for (; i < count; i++) {
          route = routes[i]
          if (route.url.href === req.url && route.method === req.method) return route;
        }
      }

      return null;
    };

    return routes;
  }

  require.extensions['.routes'] = function(module, filename) {
    module.exports = createRouter(filename);
  };

  return createRouter;<commit_msg>Adds support for handler being an array.<commit_after>
module.exports = (function() {

  var fs = require('fs')
    , parse = require('./grammar.js').parse;

  function createRouter(filename) {
    var routes = parse(fs.readFileSync(filename, 'utf-8'))
      , handlers = null;

    routes.handlers = function(handlers_) { handlers = handlers_; };

    routes.express = function(app) {
      var count = routes.length, i = 0
        , method = null, route = null, mapping = null, group = null;

      if (!handlers) throw new Error('must register handlers() first.');

      for (; i < count; i++) {
        route = routes[i];
        mapping = route.mapping;
        if (!((group = handlers[mapping.group]) && (handler = group[mapping.action])))
            continue;

        method = app[route.method.toLowerCase()]
        if (handler instanceof Array) {
          method.apply(app, [route.url.pathname].concat(handler));
        } else {
          method.call(app, route.url.pathname, handler);
        }
      }
    };

    routes.route = function(req) {
      var count = routes.length, i = 0, route = null;

      if (typeof req === 'string') {
        for (; i < count; i++) {
          route = routes[i];
          if (route.url.path == req) return route;
        }

      } else {
        for (; i < count; i++) {
          route = routes[i]
          if (route.url.href === req.url && route.method === req.method) return route;
        }
      }

      return null;
    };

    return routes;
  }

  require.extensions['.routes'] = function(module, filename) {
    module.exports = createRouter(filename);
  };

  return createRouter;
{'fraction_non_alphanumeric': 0.15194805194805194, 'fraction_numerical': 0.001948051948051948, 'mean_word_length': 2.212721584984359, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4395777', 'n_tokens_mistral': 934, 'n_tokens_neox': 899, 'n_words': 229}