Sha256: b3e938cbd0956675aad29ff523bb531702abd19d1b68125cc0b20a41328b2189

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

HAL.Models.Resource = Backbone.Model.extend({
  initialize: function(representation) {
    representation = representation || {};
    this.links = representation._links;
    if(representation._embedded !== undefined) {
      this.embeddedResources = this.buildEmbeddedResources(representation._embedded);
    }
    this.set(representation);
    this.unset('_embedded', { silent: true });
    this.unset('_links', { silent: true });
  },

  buildEmbeddedResources: function(embeddedResources) {
    var result = {};
    _.each(embeddedResources, function(obj, rel) {
      if($.isArray(obj)) {
        var arr = [];
        _.each(obj, function(resource, i) {
          var newResource = new HAL.Models.Resource(resource);
          newResource.identifier = rel + '[' + i + ']';
          newResource.embed_rel = rel;
          arr.push(newResource);
        });
        result[rel] = arr;
      } else {
        var newResource = new HAL.Models.Resource(obj);
        newResource.identifier = rel;
        newResource.embed_rel = rel;
        result[rel] = newResource;
      }
    });
    return result;
  }
});

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pact_broker-1.3.2.rc1 vendor/hal-browser/js/hal/resource.js
pact_broker-1.3.1 vendor/hal-browser/js/hal/resource.js
pact_broker-1.3.0 vendor/hal-browser/js/hal/resource.js
pact_broker-1.2.0 vendor/hal-browser/js/hal/resource.js
pact_broker-1.1.0 vendor/hal-browser/js/hal/resource.js
pact_broker-1.0.0 vendor/hal-browser/js/hal/resource.js
pact_broker-1.0.0.alpha3 vendor/hal-browser/js/hal/resource.js
pact_broker-1.0.0.alpha2 vendor/hal-browser/js/hal/resource.js
pact_broker-1.0.0.alpha1 vendor/hal-browser/js/hal/resource.js