<commit_before>var events = {
  preSave: function () {
    var options = this._definition.getBehavior('sluggable').getOptions();
    if (!options.field) {
      throw new Meteor.Error(422, 'Field to slugify has not been specified');
    }
    if (!_.has(this, options.field)) {
      throw new Meteor.Error(422, 'Field `' + options.field + '` does not exist in the saving object');
    }
    this.slug = URLify(this[options.field]);
  },

  postRemove: function () {
    delete this.slug;
  }
};

Behavior('sluggable', function (options) {
  var defaultOptions = {
    field: null
  };
  
  this.setOptions(_.extend(defaultOptions, options));

  this.setEvents(events);
});<commit_msg>Testing<commit_after>var events = {
  preSave: function () {
    var self = this,
        behavior = self._definition.behaviors.sluggable,
        options = behaviors.sluggable.options;
    if (!_.has(self, options.sluggableFieldName)) {
      throw new Meteor.Error(422, 'Object does not have `' + options.sluggableFieldName + '` field');
    }
    self.slug = URLify(self[options.sluggableFieldName]);
  },

  postRemove: function () {
    delete this.slug;
  }
};

Behavior('sluggable', {
  options: {
    sluggableFieldName: 'name',
    slugFieldName: 'slug'
  },

  events: events
});
{'fraction_non_alphanumeric': 0.14599686028257458, 'fraction_numerical': 0.00706436420722135, 'mean_word_length': 3.3515358361774745, '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': '1598972', 'n_tokens_mistral': 422, 'n_tokens_neox': 412, 'n_words': 87}