<commit_before>/*****************************************************************************/
/* IronRouter */
/*****************************************************************************/
IronRouter = function (options) {
  var self = this;
  
  this.configure(options);

  /**
   * The routes array which doubles as a named route index by adding
   * properties to the array.
   *
   * @api public
   */
  this.routes = [];
  
  this._globalHooks = {};
  _.each(IronRouter.HOOK_TYPES, function(type) { self._globalHooks[type] = []; });
};

IronRouter.HOOK_TYPES = ['load', 'before', 'after', 'unload'];

IronRouter.prototype = {
  constructor: IronRouter,

  /**
   * Configure instance with options. This can be called at any time. If the
   * instance options object hasn't been created yet it is created here.
   *
   * @param {Object} options
   * @return {IronRouter}
   * @api public
   */
  
  configure: function (options) {
    var self = this;
    
    this.options = this.options || {};
    _.extend(this.options, options);
    
    // e.g. before: fn OR before: [fn1, fn2]
    _.each(IronRouter.HOOK_TYPES, function(type) {
      if (self.options[type]) {
        _.each(Utils.toArray(self.options[type]), function(hook) {
          self.addHook(type, hook);
        });
        
        delete self.options[type];
      }
    });
    
    return this;
  },


  /**
   *
   * Add a hook to all routes. The hooks will apply to all routes,
   * unless you name routes to include or exclude via `only` and `except` options
   *
   * @param {String} [type] one of 'load', 'unload', 'before' or 'after'
   * @param {Object} [options] Options to controll the hooks [optional]
   * @param {Function} [hook] Callback to run
   * @return {IronRouter}
   * @api public
   *
   */
  
  addHook: function(type, hook, options) {
    options = options || {}

    if (options.only)
      options.only = Utils.toArray(options.only);
    if (options.except)
      options.except = Utils.toArray(options.except);
      
    this._globalHooks[type].push({options: options, hook: hook});
    
    return this;
  },
  
  load: function(hook, options) {
    return this.addHook('load', hook, options);
  },

  before: function(hook, options) {
    return this.addHook('before', hook, options);
  },
  
  after: function(hook, options) {
    return this.addHook('after', hook, options);
  },
  
  unload: function(hook, options) {
    return this.addHook('unload', hook, options);
  },
  
  /**
   *
   * Fetch the list of global hooks that apply to the given route name.
   * Hooks are defined by the .addHook() function above.
   *
   * @param {String} [type] one of 'load', 'unload', 'before' or 'after'
   * @param {String} [name] the name of the route we are interested in
   * @return {[Function]} [hooks] an array of hooks to run
   * @api public
   *
   */
    
  getHooks: function(type, name) {
    var hooks = [];
    
    _.each(this._globalHooks[type], function(hook) {
      var options = hook.options;
      
      if (options.except && _.include(options.except, name))<commit_msg>WIP - fix lib/router hook method definitions.<commit_after>/*****************************************************************************/
/* IronRouter */
/*****************************************************************************/
IronRouter = function (options) {
  var self = this;
  
  this.configure(options);

  /**
   * The routes array which doubles as a named route index by adding
   * properties to the array.
   *
   * @api public
   */
  this.routes = [];
  
  this._globalHooks = {};
  _.each(IronRouter.HOOK_TYPES, function (type) { 
    self._globalHooks[type] = []; 

    // example:
    //  self.onRun = function (hook, options) {
    //    return self.addHook('onRun', hook, options);
    //  };
    self[type] = function (hook, options) {
      return self.addHook(type, hook, options);
    };
  });
};

IronRouter.HOOK_TYPES = [
  'onRun',
  'onData',
  'onBeforeAction',
  'onAfterAction',
  'onStop'
];

IronRouter.prototype = {
  constructor: IronRouter,

  /**
   * Configure instance with options. This can be called at any time. If the
   * instance options object hasn't been created yet it is created here.
   *
   * @param {Object} options
   * @return {IronRouter}
   * @api public
   */
  
  configure: function (options) {
    var self = this;
    
    this.options = this.options || {};
    _.extend(this.options, options);
    
    // e.g. before: fn OR before: [fn1, fn2]
    _.each(IronRouter.HOOK_TYPES, function(type) {
      if (self.options[type]) {
        _.each(Utils.toArray(self.options[type]), function(hook) {
          self.addHook(type, hook);
        });
        
        delete self.options[type];
      }
    });
    
    return this;
  },


  /**
   *
   * Add a hook to all routes. The hooks will apply to all routes,
   * unless you name routes to include or exclude via `only` and `except` options
   *
   * @param {String} [type] one of 'load', 'unload', 'before' or 'after'
   * @param {Object} [options] Options to controll the hooks [optional]
   * @param {Function} [hook] Callback to run
   * @return {IronRouter}
   * @api public
   *
   */
  
  addHook: function(type, hook, options) {
    options = options || {}

    if (options.only)
      options.only = Utils.toArray(options.only);
    if (options.except)
      options.except = Utils.toArray(options.except);
      
    this._globalHooks[type].push({options: options, hook: hook});
    
    return this;
  },

  // legacy
  load: function(hook, options) {
    return this.onRun(hook, options);
  },

  // legacy
  before: function(hook, options) {
    return this.onBeforeAction(hook, options);
  },
  
  // legacy
  after: function(hook, options) {
    return this.onAfterAction(hook, options);
  },
  
  // legacy
  unload: function(hook, options) {
    return this.onStop(hook, options);
  },
  
  /**
   *
   * Fetch the list of global hooks that apply to the given route name.
   * Hooks are defined by the .addHook() function above.
   *
   * @param {String} [type] one of 'load', 'unload', 'before' or 'after'
   * @param {String} [name] the name of the route we are interested in
   * @return {[Function]} [hooks] an array of hooks to run
   * @api public
   *
   */
    
  getHooks: function(type, name) {
    var hooks = [];
    
    _.each(this._globalHooks[type], function(hook) {
      var options = hook.options;
      
      if (options.except && _.include(options.except, name))
{'fraction_non_alphanumeric': 0.18067291442617914, 'fraction_numerical': 0.0006145337225380243, 'mean_word_length': 2.789289871944121, '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': '1592530', 'n_tokens_mistral': 2047, 'n_tokens_neox': 2004, 'n_words': 565}