Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ResourceController._resourceUrl() can now extract a resourceUrl from …

…a Resource that hasn't been instantiated
  • Loading branch information...
commit 8d450992fc2817086907a671f794ea2a97542a7e 1 parent bd310d4
@dgeb dgeb authored
View
4 CHANGELOG
@@ -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
View
25 src/ember-rest.js
@@ -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
@@ -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);
View
5 tests/tests/ember-resource-controller.js
@@ -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");
Please sign in to comment.
Something went wrong with that request. Please try again.