Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

Commit

Permalink
ResourceController._resourceUrl() can now extract a resourceUrl from …
Browse files Browse the repository at this point in the history
…a Resource that hasn't been instantiated
  • Loading branch information
dgeb committed Apr 3, 2012
1 parent bd310d4 commit 8d45099
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
*Ember-REST 0.1.1 (April 2, 2012)*

* ResourceController._resourceUrl() can now extract a resourceUrl from a Resource that hasn't been instantiated

*Ember-REST 0.1.0 (April 2, 2012)*

* Added versioning to Ember-REST
Expand Down
25 changes: 20 additions & 5 deletions src/ember-rest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Ember-REST.js 0.1.0
Ember-REST.js 0.1.1
A simple library for RESTful resources in Ember.js
Expand Down Expand Up @@ -292,9 +292,24 @@ Ember.ResourceController = Ember.ArrayController.extend({
the `resourceUrl` specified for `resourceType`.
*/
_resourceUrl: function() {
if (this.resourceUrl === undefined)
return this.get('resourceType').prototype.resourceUrl;
else
return this.resourceUrl;
if (this.resourceUrl === undefined) {
// If `resourceUrl` is not defined for this controller, there are a couple
// ways to retrieve it from the resource. If a resource has been instantiated,
// then it can be retrieved from the resource's prototype. Otherwise, we need
// to loop through the mixins for the prototype to get the resourceUrl.
var rt = this.get('resourceType');
if (rt.prototype.resourceUrl === undefined) {
for (var i = rt.PrototypeMixin.mixins.length - 1; i >= 0; i--) {
var m = rt.PrototypeMixin.mixins[i];
if (m.properties !== undefined && m.properties.resourceUrl !== undefined) {
return m.properties.resourceUrl;
}
}
}
else {
return rt.prototype.resourceUrl;
}
}
return this.resourceUrl;
}
}, Ember.ResourceAdapter);
5 changes: 5 additions & 0 deletions tests/tests/ember-resource-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ test("should use the resourceUrl from its corresponding resource", function() {
equal(contactsController._resourceUrl(), "/contacts");
});

test("should use the resourceUrl from a corresponding resource which has not yet been instantiated", function() {
contactsController.set("resourceType", Ember.Resource.extend({resourceUrl: '/people'}));
equal(contactsController._resourceUrl(), "/people");
});

test("should be able to override resourceUrl", function() {
contactsController.set("resourceUrl", "/contacts/active");
equal(contactsController._resourceUrl(), "/contacts/active");
Expand Down

0 comments on commit 8d45099

Please sign in to comment.