<commit_before>var utils = require(__dirname + '/utils.js');

var driverJob = function(){
  return {
    plugins: [],
    pluginOptions: [],
    perform: function(args, callback){
      var self = this;

      var started = 0;
      var matches = [];
      self.subscriptions(function(err, subscriptions, count){
        if(count == 0){
          if(started === 0 && typeof callback === 'function'){ callback(null, matches); }
        }else{    
          for(var app in subscriptions){
            for(var i in subscriptions[app]){
              started++;
              var subscription = subscriptions[app][i];
              var matched = subscriptionMatch(args, subscription);
              if(matched === true){
                matches.push(subscription['queue_name']);
                var payload = driverMetadata(args, subscription.queue_name, app, i, subscription.class, args.bus_event_type);
                self.queueObject.enqueue(subscription.queue_name, subscription.class, payload, function(err, toRun){
                  started--;
                  if(started === 0 && typeof callback === 'function'){ callback(null, matches); }
                });
              }else{
                process.nextTick(function(){
                  started--;
                  if(started === 0 && typeof callback === 'function'){ callback(null, matches); }
                });
              }
            }
          }
        }
      });
    } 
  }
}

var driverMetadata = function(args, bus_rider_queue, bus_rider_app_key, bus_rider_sub_key, bus_rider_class_name, bus_event_type){
  var payload = {}

  payload['bus_driven_at']        = utils.timestamp();
  payload['bus_rider_queue']      = bus_rider_queue;
  payload['bus_rider_app_key']    = bus_rider_app_key;
  payload['bus_rider_sub_key']    = bus_rider_sub_key;
  payload['bus_rider_class_name'] = bus_rider_class_name;
  payload['bus_event_type']       = bus_event_type;

  for(var i in args){
    payload[i] = args[i];
  }

  return payload;
} 

var subscriptionMatch = function(args, subscription){
  var specialPrepend = "bus_special_value_";
  var matched = true;
  var parts = 0;

  for(var key in subscription.matcher){
    parts++;
    var value = subscription.matcher[key];
    if(matched === true){
      if(value === specialPrepend + "key"){
        if( args[key] != null ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "blank"){
        if( args[key] != null && args[key].trim().length == 0 ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "empty"){
        if( args[key] == null ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "nil"){
        if( args[key] === undefined ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "value"){
        if( args[key] != null ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "present"){
        if( args[key] != null && args[key].trim().length > 0 ){ matched = true; }
        else{ matched = false; }
      }
      else{
        var matches = args[key].match(new RegExp(value, 'g'));
        if (matches != null ){ matched = true; }
        else{ matched = false; }
      }
    }
  }

  if(parts === 0){
    matched = false;
  }

  return matched;
}

exports.driverJob = driverJob;<commit_msg>ruby regexp<commit_after>var utils = require(__dirname + '/utils.js');

var driverJob = function(){
  return {
    plugins: [],
    pluginOptions: [],
    perform: function(args, callback){
      var self = this;

      var started = 0;
      var matches = [];
      self.subscriptions(function(err, subscriptions, count){
        if(count == 0){
          if(started === 0 && typeof callback === 'function'){ callback(null, matches); }
        }else{    
          for(var app in subscriptions){
            for(var i in subscriptions[app]){
              started++;
              var subscription = subscriptions[app][i];
              var matched = subscriptionMatch(args, subscription);
              if(matched === true){
                matches.push(subscription['queue_name']);
                var payload = driverMetadata(args, subscription.queue_name, app, i, subscription.class, args.bus_event_type);
                self.queueObject.enqueue(subscription.queue_name, subscription.class, payload, function(err, toRun){
                  started--;
                  if(started === 0 && typeof callback === 'function'){ callback(null, matches); }
                });
              }else{
                process.nextTick(function(){
                  started--;
                  if(started === 0 && typeof callback === 'function'){ callback(null, matches); }
                });
              }
            }
          }
        }
      });
    } 
  }
}

var driverMetadata = function(args, bus_rider_queue, bus_rider_app_key, bus_rider_sub_key, bus_rider_class_name, bus_event_type){
  var payload = {}

  payload['bus_driven_at']        = utils.timestamp();
  payload['bus_rider_queue']      = bus_rider_queue;
  payload['bus_rider_app_key']    = bus_rider_app_key;
  payload['bus_rider_sub_key']    = bus_rider_sub_key;
  payload['bus_rider_class_name'] = bus_rider_class_name;
  payload['bus_event_type']       = bus_event_type;

  for(var i in args){
    payload[i] = args[i];
  }

  return payload;
} 

var subscriptionMatch = function(args, subscription){
  var specialPrepend = "bus_special_value_";
  var matched = true;
  var parts = 0;

  for(var key in subscription.matcher){
    parts++;
    var value = subscription.matcher[key];

    // deal with wierd ruby prefixes
    if(value.substring(0,7) === '(?i-mx:'){
      value = value.substring(7).slice(0,-1);
    }
    if(value.substring(0,7) === '(?-mix:'){
      value = value.substring(7).slice(0,-1);
    }

    if(matched === true){
      if(value === specialPrepend + "key"){
        if( args[key] != null ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "blank"){
        if( args[key] != null && args[key].trim().length == 0 ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "empty"){
        if( args[key] == null ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "nil" || value === specialPrepend + "null"){
        if( args[key] === undefined ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "value"){
        if( args[key] != null ){ matched = true; }
        else{ matched = false; }
      }
      else if(value === specialPrepend + "present"){
        if( args[key] != null && args[key].trim().length > 0 ){ matched = true; }
        else{ matched = false; }
      }
      else{
        var matches = args[key].match(new RegExp(value, 'g'));
        if (matches != null ){ matched = true; }
        else{ matched = false; }
      }
    }
  }

  if(parts === 0){
    matched = false;
  }

  return matched;
}

exports.driverJob = driverJob;
{'fraction_non_alphanumeric': 0.1461453133666112, 'fraction_numerical': 0.003882418191902385, 'mean_word_length': 2.2549638989169676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6575287', 'n_tokens_mistral': 2183, 'n_tokens_neox': 2107, 'n_words': 484}