<commit_before>Ember.ResourceController = Ember.ArrayController.extend({
  type: Ember.required(),

  content: [],

  load: function(json) {
    this.pushObject(this.get('type').create(json));
  },

  loadAll: function(jsonArray) {
    for (var i=0; i < jsonArray.length; i++)
      this.load(jsonArray[i]);
  },

  findAll: function() {
    var self = this;

    jQuery.getJSON(this._collectionUrl(), function(data) {
      self.set("content", []);
      self.loadAll(data);
    });
  },

  updateResource: function(resource) {
    return jQuery.ajax({
      url: this._resourceUrl().fmt(resource.get('id')),
      data: resource.get('data'),
      dataType: 'json',
      type: 'PUT'
    });
  },

  createResource: function(resource) {
    var self = this;

    return jQuery.ajax({
      url: this._collectionUrl(),
      data: resource.get('data'),
      dataType: 'json',
      type: 'POST',
      success: function(data) { self.load(data); }
    });
  },

  destroyResource: function(resource) {
    var self = this;

    return jQuery.ajax({
      url: this._resourceUrl().fmt(resource.get('id')),
      dataType: 'json',
      type: 'DELETE',
      success: function() { self.removeObject(resource); }
    });
  },

  _collectionUrl: function() {
    if (this.collectionUrl !== undefined)
      return this.collectionUrl;
    else
      return this.url;
  },

  _resourceUrl: function() {
    if (this.resourceUrl !== undefined)
      return this.resourceUrl;
    else
      return this._collectionUrl() + '/%@';
  }
});
<commit_msg>added comments; removed collectionUrl option - now just url and resourceUrl can be specified.<commit_after>// A controller for RESTful resources
//
// Override this controller and include the following:
//
// * `type` -- an Ember.Object class; the class must have a 'data' property that
//      returns a json representation of the object
// * `url` -- the base url of the resource (e.g. '/contacts')
// * `resourceUrl` -- (optional) overrides `url` with a url to individual resources
//      in this collection (e.g. '/contacts/%@'). Set this property if individual resources
//      can not be found at `url/id`.
Ember.ResourceController = Ember.ArrayController.extend({
  url:     Ember.required(),
  type:    Ember.required(),
  content: [],

  load: function(json) {
    this.pushObject(this.get('type').create(json));
  },

  loadAll: function(jsonArray) {
    for (var i=0; i < jsonArray.length; i++)
      this.load(jsonArray[i]);
  },

  findAll: function() {
    var self = this;

    jQuery.getJSON(this.url, function(data) {
      self.set("content", []);
      self.loadAll(data);
    });
  },

  updateResource: function(resource) {
    return jQuery.ajax({
      url: this._resourceUrl(resource.get('id')),
      data: resource.get('data'),
      dataType: 'json',
      type: 'PUT'
    });
  },

  createResource: function(resource) {
    var self = this;

    return jQuery.ajax({
      url: this._resourceUrl(''),
      data: resource.get('data'),
      dataType: 'json',
      type: 'POST',
      success: function(data) { self.load(data); }
    });
  },

  destroyResource: function(resource) {
    var self = this;

    return jQuery.ajax({
      url: this._resourceUrl(resource.get('id')),
      dataType: 'json',
      type: 'DELETE',
      success: function() { self.removeObject(resource); }
    });
  },

  _resourceUrl: function(id) {
    var resourceUrl = this.resourceUrl;
    if (resourceUrl === undefined)
      resourceUrl = this.url + '/%@';
    return resourceUrl.fmt(id);
  }
});

{'fraction_non_alphanumeric': 0.16052853528254146, 'fraction_numerical': 0.000562271577171774, 'mean_word_length': 2.871599564744287, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2362623', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1089, 'n_words': 258}