<commit_before>/**
 * Module dependencies.
 */

var _ = require('lodash');
var sailsUtil = require('sails-util');

/**
 * @param  {SailsApp} sails  [Sails app]
 * @return {Function}
 */
module.exports = function to(sails) {

  /**
   * `interpretRouteSyntax()`
   *
   * "Teach" router to understand references to controllers.
   * This is the event handler for the 'route:typeUnknown' emitted on `sails`.
   *
   * @param  {Dictionary} route
   *         @property {String} verb
   *         @property {String} path
   *         @property {Dictionary} target
   *         @property {Dictionary} options
   *
   * @api private
   */
  return function interpretRouteSyntax (route) {
    var target = route.target;
    var path = route.path;
    var verb = route.verb;
    var options = route.options;

    var actionIdentity;

    // This hook handles the following route target syntaxes:
    // (assumes controller/action files live in api/controllers)
    //
    // 'GET /foo/bar': 'some_folder/UserController.doStuff'
    //   - Bind GET /foo/bar to the "doStuff" action in api/controllers/some_folder/UserController.js
    //
    // 'GET /foo/bar': { action: 'some_folder.user.dostuff' }
    //   - Bind GET /foo/bar to the "doStuff" action in api/controllers/some_folder/UserController.js
    //     OR
    //     Bind GET /foo/bar to the action in api/controllers/some_folder/user/dostuff.js

    // Attempt to handle string target.
    if (_.isString(target) && target.match(/.+Controller\..+/)) {
      // Get the action identity by replacing slashes with dots, removing `Controller` and lower-casing.
      actionIdentity = target.replace(/\//g, '.').replace(/Controller\./,'.').toLowerCase();
    }

    // Attempt to handle `{action: 'my-action'}` target.
    else if (_.isObject(target) && target.action) {
      // Get the action identity by lowercasing the value of the `action` property.
      actionIdentity = target.action.toLowerCase();
    }

    if (actionIdentity) {
      // Attempt to find an action with that identity.
      var action = sails.hooks.controllers._actions[actionIdentity];
      // If there is one, bind the given route address to the action.
      if (action) {
        sails.router.bind(path, action, verb, options);
      }<commit_msg>Make sure req.options.action is set when appropriate.<commit_after>/**
 * Module dependencies.
 */

var _ = require('lodash');
var sailsUtil = require('sails-util');

/**
 * @param  {SailsApp} sails  [Sails app]
 * @return {Function}
 */
module.exports = function to(sails) {

  /**
   * `interpretRouteSyntax()`
   *
   * "Teach" router to understand references to controllers.
   * This is the event handler for the 'route:typeUnknown' emitted on `sails`.
   *
   * @param  {Dictionary} route
   *         @property {String} verb
   *         @property {String} path
   *         @property {Dictionary} target
   *         @property {Dictionary} options
   *
   * @api private
   */
  return function interpretRouteSyntax (route) {
    var target = route.target;
    var path = route.path;
    var verb = route.verb;
    var options = route.options;

    var actionIdentity;

    // This hook handles the following route target syntaxes:
    // (assumes controller/action files live in api/controllers)
    //
    // 'GET /foo/bar': 'some_folder/UserController.doStuff'
    //   - Bind GET /foo/bar to the "doStuff" action in api/controllers/some_folder/UserController.js
    //
    // 'GET /foo/bar': { action: 'some_folder.user.dostuff' }
    //   - Bind GET /foo/bar to the "doStuff" action in api/controllers/some_folder/UserController.js
    //     OR
    //     Bind GET /foo/bar to the action in api/controllers/some_folder/user/dostuff.js

    // Attempt to handle string target.
    if (_.isString(target) && target.match(/.+Controller\..+/)) {
      // Get the action identity by replacing slashes with dots, removing `Controller` and lower-casing.
      actionIdentity = target.replace(/\//g, '.').replace(/Controller\./,'.').toLowerCase();
    }

    // Attempt to handle `{action: 'my-action'}` target.
    else if (_.isObject(target) && target.action) {
      // Get the action identity by lowercasing the value of the `action` property.
      actionIdentity = target.action.toLowerCase();
    }

    if (actionIdentity) {
      // Attempt to find an action with that identity.
      var action = sails.hooks.controllers._actions[actionIdentity];
      // If there is one, bind the given route address to the action.
      if (action) {
        // Make sure req.options.action is set to the identity of the action we're binding,
        // for cases where the { action: 'foo.bar' } syntax wasn't used.
        options.action = actionIdentity;
        sails.router.bind(path, action, verb, options);
      }
{'fraction_non_alphanumeric': 0.1271363067944977, 'fraction_numerical': 0.0, 'mean_word_length': 2.6082706766917294, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7552152', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1407, 'n_words': 428}