<commit_before>(function(Paloma){

  var Engine = function(config){
    this.factory = config.factory;
    this._clearRequest();
  };

  Engine.prototype.start = function(){
    if ( !this._request ) return;
    if ( this._request.id == this.lastRequest().id ) return;

    this._lastRequest = this._request;

    var resource = this._request.controller,
        action = this._request.action,
        params = this._request.params;

    var Controller = this.factory.get(resource),
        controller = null;

    Paloma.log('Paloma: ' + resource + '#' + action + ' with params:');
    Paloma.log(params);

    if ( !Controller ) return true;
    controller = new Controller(params);

    if ( !controller[action] ) return true;
    controller[action]();

    this._lastRequest.executed = true;
    this._clearRequest();
  };


  //
  // options:
  //  resource
  //  action
  //  params
  //  id
  //
  Engine.prototype.setRequest = function(options){
    this._request = {
      id: options.id,
      controller: options.resource,
      action: options.action,
      params: options.params,
      executed: false
    };
  };


  Engine.prototype.getRequest = function(key){
    return (!key ? this._request : this._request[key]);
  };

  Engine.prototype.lastRequest = function(){
    return this._lastRequest || {executed: false};
  };

  Engine.prototype.hasRequest = function(){
    return this._request != null;
  };

  Engine.prototype._clearRequest = function(){
    this._request = null;
  };

  Engine.prototype._stopWithWarning = function(warning){
    Paloma.warn(warning);
    this._clearRequest();
  };

  Paloma.Engine = Engine;

})(window.Paloma);<commit_msg>Refactor Paloma.Engine<commit_after>Paloma.Engine = function(config){
  this.factory = config.factory;
  this._clearRequest();
};

Paloma.Engine.prototype = {

  setRequest: function(options){
    this._request = {
      id: options.id,
      controller: options.resource,
      action: options.action,
      params: options.params,
      executed: false
    };
  },

  hasRequest: function(){
    return this._request != null;
  },

  lastRequest: function(){
    return this._lastRequest = this._lastRequest || {executed: false};
  },

  start: function(){
    if ( this._shouldStop() ) return;

    this._logRequest();
    this._lastRequest = this._request;

    var controllerClass = this.factory.get( this._request.controller );

    if (controllerClass){
      var controller = new controllerClass( this._request.params );
      this._executeActionOf(controller);
    }

    this._clearRequest();
  },

  _executeActionOf: function(controller){
    var callback = controller[ this._request.action ];

    if (callback){
      callback.call(controller);
      this._lastRequest.executed = true;
    }
  },

  _shouldStop: function(){
    if ( !this.hasRequest() ) return true;
    if ( this._request.id == this.lastRequest().id ) return true;

    return false;
  },

  _logRequest: function(){
    Paloma.log(
      'Paloma: ' + this._request.controller + '#' +
      this._request.action + ' with params:'
    );

    Paloma.log( this._request.params );
  },

  _clearRequest: function(){
    this._request = null;
  }
};
{'fraction_non_alphanumeric': 0.14013732833957554, 'fraction_numerical': 0.0, 'mean_word_length': 2.9037758830694274, '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': '3943091', 'n_tokens_mistral': 968, 'n_tokens_neox': 935, 'n_words': 187}