angularjs-rails-resource 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d157c5ed2c1ddd214a91ddfe19c13b820dfc5a91
4
- data.tar.gz: 928857da368dcfbff87e63c36e4e490f5c33dce4
3
+ metadata.gz: 3af2e27b94554d7c76725e83fbafe496f428dba6
4
+ data.tar.gz: 49b9c83300358da0e4aa970949ee48c1b0d7671f
5
5
  SHA512:
6
- metadata.gz: 710afddc7abe88b944dfe92897ebb8e6c81696314598bc07d5217556889385d20714b313bea9bca226ef30159ffa765949bd44435174ad2969ce4f567b695148
7
- data.tar.gz: 9bdd1b3d25e0103621d04d2b07e2bc711e54f69c183d070e730d8232639fffda0e92d44703cc78e3a9390ff1c07e2f38bf09117574f1e904f7e580de3ef7f8cb
6
+ metadata.gz: 138e28efba7ce29cc39fbdfbfa07435b8709237664219ea5169c2fbe390fb47f074afd45fb3d9603f2860014b1ceba3c7332b12630cba2f66368e0af610da732
7
+ data.tar.gz: abb4c0ced83000383d828540957cf2cefe769ff25dc507e5d1be7a7b9a3ac105437188b4ca1121d72a4aff2f602e4d48d4b70f732423924b31971c94ffe75187
@@ -7,74 +7,74 @@ For example, suppose we have an Author that serializes all of the books that aut
7
7
  are a nested resource that allows us to more easily perform updates against those books without having to worry about creating
8
8
  a resource instance for the book.
9
9
 
10
- angular.module('book.services', ['rails']);
11
-
12
- angular.module('book.services').factory('Book', ['railsResourceFactory', function (railsResourceFactory) {
13
- return railsResourceFactory({url: '/books', name: 'book'});
14
- }]);
15
-
16
- angular.module('book.services').factory('Author', ['railsResourceFactory', 'railsSerializer', function (railsResourceFactory, railsSerializer) {
17
- return railsResourceFactory({
18
- url: '/authors',
19
- name: 'author',
20
- serializer: railsSerializer(function () {
21
- this.resource('books', 'Book');
22
- });
23
- });
24
- }]);
25
-
26
- angular.module('book.controllers').controller('AuthorCtrl', ['$scope', 'Author', function ($scope, Author) {
27
- $scope.author = Author.get(123);
28
-
29
- // allow the view to trigger an update to a book from $scope.author.books
30
- $scope.updateBook = function (book) {
31
- book.update();
32
- }
33
- }]);
10
+ angular.module('book.services', ['rails']);
11
+
12
+ angular.module('book.services').factory('Book', ['railsResourceFactory', function (railsResourceFactory) {
13
+ return railsResourceFactory({url: '/books', name: 'book'});
14
+ }]);
15
+
16
+ angular.module('book.services').factory('Author', ['railsResourceFactory', 'railsSerializer', function (railsResourceFactory, railsSerializer) {
17
+ return railsResourceFactory({
18
+ url: '/authors',
19
+ name: 'author',
20
+ serializer: railsSerializer(function () {
21
+ this.resource('books', 'Book');
22
+ })
23
+ });
24
+ }]);
25
+
26
+ angular.module('book.controllers').controller('AuthorCtrl', ['$scope', 'Author', function ($scope, Author) {
27
+ $scope.author = Author.get(123);
28
+
29
+ // allow the view to trigger an update to a book from $scope.author.books
30
+ $scope.updateBook = function (book) {
31
+ book.update();
32
+ }
33
+ }]);
34
34
 
35
35
  # Nested attributes
36
36
  While we don't have logic for full nested attributes support, the new serializer does allow you to specify which fields
37
37
  should be passed with the <code>_attributes</code> suffix.
38
38
 
39
- angular.module('book.services').factory('Book', ['railsResourceFactory', 'railsSerializer', function (railsResourceFactory, railsSerializer) {
40
- return railsResourceFactory({
41
- url: '/books',
42
- name: 'book',
43
- serializer: railsSerializer(function () {
44
- this.nestedAttribute('author');
45
- });
46
- });
47
- }]);
39
+ angular.module('book.services').factory('Book', ['railsResourceFactory', 'railsSerializer', function (railsResourceFactory, railsSerializer) {
40
+ return railsResourceFactory({
41
+ url: '/books',
42
+ name: 'book',
43
+ serializer: railsSerializer(function () {
44
+ this.nestedAttribute('author');
45
+ })
46
+ });
47
+ }]);
48
48
 
49
49
  # Excluding attributes from serialization
50
50
  Sometimes you don't want to serialize certain fields when updating an object. Take for instance the case of the author on a book.
51
51
  We know that we don't accept nested attributes for the author on the server so we want to exclude it from the JSON to reduce
52
52
  the amount of data being sent to the server.
53
53
 
54
- angular.module('book.services').factory('Book', ['railsResourceFactory', 'railsSerializer', function (railsResourceFactory railsSerializer) {
55
- return railsResourceFactory({
56
- url: '/books',
57
- name: 'book',
58
- serializer: railsSerializer(function () {
59
- this.exclude('author');
60
- });
61
- });
62
- }]);
54
+ angular.module('book.services').factory('Book', ['railsResourceFactory', 'railsSerializer', function (railsResourceFactory railsSerializer) {
55
+ return railsResourceFactory({
56
+ url: '/books',
57
+ name: 'book',
58
+ serializer: railsSerializer(function () {
59
+ this.exclude('author');
60
+ })
61
+ });
62
+ }]);
63
63
 
64
64
 
65
65
  # Only allowing specific attributes for serialization
66
66
  You can also be very restrictive and only include specific attributes that you want to send to the server. All other attribtues
67
67
  would be excluded by default.
68
68
 
69
- angular.module('book.services').factory('Book', ['railsResourceFactory', 'railsSerializer', function (railsResourceFactory. railsSerializer) {
70
- return railsResourceFactory({
71
- url: '/books',
72
- name: 'book',
73
- serializer: railsSerializer(function () {
74
- this.only('id', 'isbn', 'publicationDate');
75
- });
76
- });
77
- }]);
69
+ angular.module('book.services').factory('Book', ['railsResourceFactory', 'railsSerializer', function (railsResourceFactory. railsSerializer) {
70
+ return railsResourceFactory({
71
+ url: '/books',
72
+ name: 'book',
73
+ serializer: railsSerializer(function () {
74
+ this.only('id', 'isbn', 'publicationDate');
75
+ })
76
+ });
77
+ }]);
78
78
 
79
79
 
80
80
  # Adding custom methods to a resource
@@ -84,61 +84,61 @@ You can add additional "class" or "instance" methods by modifying the resource r
84
84
  For instance, if you wanted to add a method that would search for Books by the title without having to construct the query params
85
85
  each time you could add a new <code>findByTitle</code> class function.
86
86
 
87
- angular.module('book.services', ['rails']);
88
- angular.module('book.services').factory('Book', ['railsResourceFactory', function (railsResourceFactory) {
89
- var resource = railsResourceFactory({url: '/books', name: 'book'});
90
- resource.findByTitle = function (title) {
91
- return resource.query({title: title});
92
- };
93
- return resource;
94
- }]);
95
-
96
- angular.module('book.controllers').controller('BookShelfCtrl', ['$scope', 'Book', function ($scope, Book) {
97
- $scope.searching = true;
98
- // Find all books matching the title
99
- $scope.books = Book.findByTitle({title: title});
100
- $scope.books.then(function(results) {
101
- $scope.searching = false;
102
- }, function (error) {
103
- $scope.searching = false;
104
- });
105
- }]);
87
+ angular.module('book.services', ['rails']);
88
+ angular.module('book.services').factory('Book', ['railsResourceFactory', function (railsResourceFactory) {
89
+ var resource = railsResourceFactory({url: '/books', name: 'book'});
90
+ resource.findByTitle = function (title) {
91
+ return resource.query({title: title});
92
+ };
93
+ return resource;
94
+ }]);
95
+
96
+ angular.module('book.controllers').controller('BookShelfCtrl', ['$scope', 'Book', function ($scope, Book) {
97
+ $scope.searching = true;
98
+ // Find all books matching the title
99
+ $scope.books = Book.findByTitle({title: title});
100
+ $scope.books.then(function(results) {
101
+ $scope.searching = false;
102
+ }, function (error) {
103
+ $scope.searching = false;
104
+ });
105
+ }]);
106
106
 
107
107
  ## Get related object
108
108
  You can also add additional methods on the object prototype chain so all instances of the resource have that function available.
109
109
  The following example exposes a <code>getAuthor</code> instance method that would be accessible on all Book instances.
110
110
 
111
- angular.module('book.services', ['rails']);
112
- angular.module('book.services').factory('Author', ['railsResourceFactory', function (railsResourceFactory) {
113
- return railsResourceFactory({url: '/authors', name: 'author'});
114
- }]);
115
- angular.module('book.services').factory('Book', ['railsResourceFactory', 'Author', function (railsResourceFactory, Author) {
116
- var resource = railsResourceFactory({url: '/books', name: 'book'});
117
- resource.prototype.getAuthor = function () {
118
- return Author.get(this.authorId);
119
- };
120
- }]);
121
- angular.module('book.controllers').controller('BookShelfCtrl', ['$scope', 'Book', function ($scope, Book) {
122
- $scope.getAuthorDetails = function (book) {
123
- $scope.author = book.getAuthor();
124
- };
125
- }]);
111
+ angular.module('book.services', ['rails']);
112
+ angular.module('book.services').factory('Author', ['railsResourceFactory', function (railsResourceFactory) {
113
+ return railsResourceFactory({url: '/authors', name: 'author'});
114
+ }]);
115
+ angular.module('book.services').factory('Book', ['railsResourceFactory', 'Author', function (railsResourceFactory, Author) {
116
+ var resource = railsResourceFactory({url: '/books', name: 'book'});
117
+ resource.prototype.getAuthor = function () {
118
+ return Author.get(this.authorId);
119
+ };
120
+ }]);
121
+ angular.module('book.controllers').controller('BookShelfCtrl', ['$scope', 'Book', function ($scope, Book) {
122
+ $scope.getAuthorDetails = function (book) {
123
+ $scope.author = book.getAuthor();
124
+ };
125
+ }]);
126
126
 
127
127
  ## Nested URL
128
128
  Or say you instead had a nested "references" service call that returned a list of referenced books for a given book instance. In that case you can add your own addition method that calls $http.get and then
129
129
  passes the resulting promise to the processResponse method which will perform the same transformations and handling that the get or query would use.
130
130
 
131
- angular.module('book.services', ['rails']);
132
- angular.module('book.services').factory('Book', ['railsResourceFactory', '$http', function (railsResourceFactory, $http) {
133
- var resource = railsResourceFactory({url: '/books', name: 'book'});
134
- resource.prototype.getReferences = function () {
135
- var self = this;
136
- return resource.$get(self.$url('references'))).then(function (references) {
137
- self.references = references;
138
- return self.references;
139
- });
140
- };
141
- }]);
131
+ angular.module('book.services', ['rails']);
132
+ angular.module('book.services').factory('Book', ['railsResourceFactory', '$http', function (railsResourceFactory, $http) {
133
+ var resource = railsResourceFactory({url: '/books', name: 'book'});
134
+ resource.prototype.getReferences = function () {
135
+ var self = this;
136
+ return resource.$get(self.$url('references'))).then(function (references) {
137
+ self.references = references;
138
+ return self.references;
139
+ });
140
+ };
141
+ }]);
142
142
 
143
143
  # Specifying Transformer
144
144
  Transformers can be specified by an array of transformers in the configuration options passed to railsResourceFactory.
@@ -147,25 +147,25 @@ a function returned by a factory if you want to share a transformer across multi
147
147
 
148
148
  Both of these examples can be accomplished using the serializers now.
149
149
 
150
- angular.module('test').factory('excludePrivateKeysTransformer', function () {
151
- return function (data) {
152
- angular.forEach(data, function (value, key) {
153
- if (key[0] === '_') {
154
- delete data[key];
155
- }
156
- });
157
- });
158
- });
159
-
160
- angular.module('test').factory('Book', function (railsResourceFactory, excludePrivateKeysTransformer) {
161
- var Book = railsResourceFactory({url: '/books', name: 'book'});
162
- Book.beforeRequest(excludePrivateKeysTransformer);
163
- Book.beforeRequest(function (data) {
164
- data['release_date'] = data['publicationDate'];
165
- delete data['publicationDate'];
166
- });
167
-
168
- return Book;
169
- });
150
+ angular.module('test').factory('excludePrivateKeysTransformer', function () {
151
+ return function (data) {
152
+ angular.forEach(data, function (value, key) {
153
+ if (key[0] === '_') {
154
+ delete data[key];
155
+ }
156
+ });
157
+ });
158
+ });
159
+
160
+ angular.module('test').factory('Book', function (railsResourceFactory, excludePrivateKeysTransformer) {
161
+ var Book = railsResourceFactory({url: '/books', name: 'book'});
162
+ Book.beforeRequest(excludePrivateKeysTransformer);
163
+ Book.beforeRequest(function (data) {
164
+ data['release_date'] = data['publicationDate'];
165
+ delete data['publicationDate'];
166
+ });
167
+
168
+ return Book;
169
+ });
170
170
 
171
171
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * A resource factory inspired by $resource from AngularJS
3
- * @version v0.2.4 - 2013-10-27
3
+ * @version v0.2.5 - 2013-11-24
4
4
  * @link https://github.com/FineLinePrototyping/angularjs-rails-resource.git
5
5
  * @author
6
6
  */
@@ -1004,7 +1004,7 @@
1004
1004
  RailsResource['$' + method] = function (url, data) {
1005
1005
  var config;
1006
1006
  // clone so we can manipulate w/o modifying the actual instance
1007
- data = RailsResource.transformData(angular.copy(data, {}));
1007
+ data = RailsResource.transformData(angular.copy(data));
1008
1008
  config = angular.extend({method: method, url: url, data: data}, RailsResource.getHttpConfig());
1009
1009
  return RailsResource.processResponse($http(config));
1010
1010
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A resource factory inspired by $resource from AngularJS
3
- * @version v0.2.4 - 2013-10-27
3
+ * @version v0.2.5 - 2013-11-24
4
4
  * @link https://github.com/FineLinePrototyping/angularjs-rails-resource.git
5
5
  * @author
6
6
  */
7
- !function(){angular.module("rails",["ng"])}(),function(){angular.module("rails").factory("RailsInflector",function(){function a(a){return angular.isString(a)?a.replace(/_[\w\d]/g,function(a,b,c){return 0===b?a:c.charAt(b+1).toUpperCase()}):a}function b(a){return angular.isString(a)?a.replace(/[A-Z]/g,function(a,b){return 0===b?a:"_"+a.toLowerCase()}):a}function c(a){return a+"s"}return{camelize:a,underscore:b,pluralize:c}})}(),function(a){angular.module("rails").factory("RailsResourceInjector",["$injector",function(b){function c(c){return c?angular.isString(c)?b.get(c):c:a}function d(d){return d?b.instantiate(c(d)):a}return{createService:d,getDependency:c}}])}(),function(){angular.module("rails").factory("railsUrlBuilder",["$interpolate",function(a){return function(b){var c;return angular.isFunction(b)?b:(-1===b.indexOf(a.startSymbol())&&(b=b+"/"+a.startSymbol()+"id"+a.endSymbol()),c=a(b),function(a){return b=c(a),"/"===b.charAt(b.length-1)&&(b=b.substr(0,b.length-1)),b})}}])}(),function(a){angular.module("rails").provider("railsSerializer",function(){var b={underscore:a,camelize:a,pluralize:a,exclusionMatchers:[]};this.underscore=function(a){return b.underscore=a,this},this.camelize=function(a){return b.camelize=a,this},this.pluralize=function(a){return b.pluralize=a,this},this.exclusionMatchers=function(a){return b.exclusionMatchers=a,this},this.$get=["$injector","RailsInflector","RailsResourceInjector",function(c,d,e){function f(c,d){function f(){angular.isFunction(c)&&(d=c,c={}),this.exclusions={},this.inclusions={},this.serializeMappings={},this.deserializeMappings={},this.customSerializedAttributes={},this.preservedAttributes={},this.customSerializers={},this.nestedResources={},this.options=angular.extend({excludeByDefault:!1},b,c||{}),d&&d.call(this,this)}return f.prototype.exclude=function(){var a=this.exclusions;return angular.forEach(arguments,function(b){a[b]=!1}),this},f.prototype.only=function(){var a=this.inclusions;return this.options.excludeByDefault=!0,angular.forEach(arguments,function(b){a[b]=!0}),this},f.prototype.nestedAttribute=function(){var a=this;return angular.forEach(arguments,function(b){a.rename(b,b+"_attributes")}),this},f.prototype.resource=function(a,b,c){return this.nestedResources[a]=b,c&&this.serializeWith(a,c),this},f.prototype.rename=function(b,c,d){return this.serializeMappings[b]=c,(d||d===a)&&(this.deserializeMappings[c]=b),this},f.prototype.add=function(a,b){return this.customSerializedAttributes[a]=b,this},f.prototype.preserve=function(a){return this.preservedAttributes[a]=!0,this},f.prototype.serializeWith=function(a,b){return this.customSerializers[a]=b,this},f.prototype.isExcludedFromSerialization=function(b){if(this.options.excludeByDefault&&!this.inclusions.hasOwnProperty(b)||this.exclusions.hasOwnProperty(b))return!0;if(this.options.exclusionMatchers){var c=!1;return angular.forEach(this.options.exclusionMatchers,function(d){angular.isString(d)?c=c||0===b.indexOf(d):angular.isFunction(d)?c=c||d.call(a,b):d instanceof RegExp&&(c=c||d.test(b))}),c}return!1},f.prototype.getSerializedAttributeName=function(b){var c=this.serializeMappings[b]||b,d=this.isExcludedFromSerialization(c),e=this.isExcludedFromSerialization(b);if(this.options.excludeByDefault){if(d&&e)return a}else if(d||e)return a;return this.underscore(c)},f.prototype.isExcludedFromDeserialization=function(){return!1},f.prototype.getDeserializedAttributeName=function(b){var c=this.camelize(b);return c=this.deserializeMappings[b]||this.deserializeMappings[c]||c,this.isExcludedFromDeserialization(b)||this.isExcludedFromDeserialization(c)?a:c},f.prototype.getNestedResource=function(a){return e.getDependency(this.nestedResources[a])},f.prototype.getAttributeSerializer=function(b){var c=this.getNestedResource(b),d=this.customSerializers[b];return d?e.createService(d):c?c.serializer:a},f.prototype.serializeValue=function(a){var b=a,c=this;if(angular.isArray(a))b=[],angular.forEach(a,function(a){b.push(c.serializeValue(a))});else if(angular.isObject(a)){if(angular.isDate(a))return a;b={},angular.forEach(a,function(a,d){angular.isFunction(a)||c.serializeAttribute(b,d,a)})}return b},f.prototype.serializeAttribute=function(b,c,d){var e=this.getAttributeSerializer(c),f=this.getSerializedAttributeName(c);f!==a&&(b[f]=e?e.serialize(d):this.serializeValue(d))},f.prototype.serialize=function(a){var b=this.serializeValue(a),c=this;return angular.isObject(b)&&angular.forEach(this.customSerializedAttributes,function(d,e){angular.isFunction(d)&&(d=d.call(a,a)),c.serializeAttribute(b,e,d)}),b},f.prototype.deserializeValue=function(a,b){var c=a,d=this;if(angular.isArray(a))c=[],angular.forEach(a,function(a){c.push(d.deserializeValue(a,b))});else if(angular.isObject(a)){if(angular.isDate(a))return a;c={},b&&(c=new b),angular.forEach(a,function(a,b){d.deserializeAttribute(c,b,a)})}return c},f.prototype.deserializeAttribute=function(b,c,d){var e,f,g=this.getDeserializedAttributeName(c);g!==a&&(e=this.getAttributeSerializer(g),f=this.getNestedResource(g),b[g]=this.preservedAttributes[g]?d:e?e.deserialize(d,f):this.deserializeValue(d,f))},f.prototype.deserialize=function(a,b){return this.deserializeValue(a,b)},f.prototype.pluralize=function(a){return this.options.pluralize?this.options.pluralize(a):a},f.prototype.underscore=function(a){return this.options.underscore?this.options.underscore(a):a},f.prototype.camelize=function(a){return this.options.camelize?this.options.camelize(a):a},f}return b.underscore=b.underscore||d.underscore,b.camelize=b.camelize||d.camelize,b.pluralize=b.pluralize||d.pluralize,f.defaultOptions=b,f}]})}(),function(a){angular.module("rails").factory("railsRootWrappingTransformer",function(){return function(a,b){var c={};return c[angular.isArray(a)?b.rootPluralName:b.rootName]=a,c}}),angular.module("rails").factory("railsRootWrappingInterceptor",function(){return function(a){var b=a.resource;return b?a.then(function(a){return a.data&&a.data.hasOwnProperty(b.rootName)?a.data=a.data[b.rootName]:a.data&&a.data.hasOwnProperty(b.rootPluralName)&&(a.data=a.data[b.rootPluralName]),a}):a}}),angular.module("rails").provider("railsResourceFactory",function(){var b={enableRootWrapping:!0,updateMethod:"put",httpConfig:{},defaultParams:a};this.enableRootWrapping=function(a){return b.enableRootWrapping=a,this},this.updateMethod=function(a){return b.updateMethod=a,this},this.httpConfig=function(a){return b.httpConfig=a,this},this.defaultParams=function(a){return b.defaultParams=a,this},this.$get=["$http","$q","railsUrlBuilder","railsSerializer","railsRootWrappingTransformer","railsRootWrappingInterceptor","RailsResourceInjector",function(c,d,e,f,g,h,i){function j(d){function j(a,b){return b&&("/"!==b[0]&&(a+="/"),a+=b),a}function k(a){var b=this;if(a){var c=function(a){return{resource:k,context:b,response:a,then:function(a){return this.response=a(this.response,this.resource,this.context),c(this.response)}}},d=k.callInterceptors(c({data:a}),this).response.data;angular.extend(this,d)}}var l=d.requestTransformers,m=d.responseInterceptors,n=d.afterResponseInterceptors;return k.setUrl=function(a){k.url=e(a)},k.setUrl(d.url),k.enableRootWrapping=d.wrapData===a?b.enableRootWrapping:d.wrapData,k.httpConfig=d.httpConfig||b.httpConfig,k.httpConfig.headers=angular.extend({Accept:"application/json","Content-Type":"application/json"},k.httpConfig.headers||{}),k.defaultParams=d.defaultParams||b.defaultParams,k.updateMethod=(d.updateMethod||b.updateMethod).toLowerCase(),k.requestTransformers=[],k.responseInterceptors=[],k.afterResponseInterceptors=[],k.serializer=i.createService(d.serializer||f()),k.rootName=k.serializer.underscore(d.name),k.rootPluralName=k.serializer.underscore(d.pluralName||k.serializer.pluralize(d.name)),k.beforeResponse=function(a){a=i.getDependency(a),k.responseInterceptors.push(function(b){return b.then(function(c){return a(c.data,b.resource,b.context),c})})},k.afterResponse=function(a){a=i.getDependency(a),k.afterResponseInterceptors.push(function(b){return b.then(function(c){return a(c,b.resource),c})})},k.beforeRequest=function(a){a=i.getDependency(a),k.requestTransformers.push(function(b,c){return a(b,c)||b})},angular.forEach(m,function(a){k.responseInterceptors.push(i.getDependency(a))}),angular.forEach(n,function(a){k.afterResponseInterceptors.push(i.getDependency(a))}),angular.forEach(l,function(a){k.requestTransformers.push(i.getDependency(a))}),k.transformData=function(a){return a=k.serializer.serialize(a),angular.forEach(k.requestTransformers,function(b){a=b(a,k)}),k.enableRootWrapping&&(a=g(a,k)),a},k.callInterceptors=function(a,b){return a=a.then(function(a){return a.originalData=a.data,a}),k.enableRootWrapping&&(a.resource=k,a=h(a)),a.then(function(a){return a.data=k.serializer.deserialize(a.data,k),a}),angular.forEach(k.responseInterceptors,function(c){a.resource=k,a.context=b,a=c(a)}),a},k.callAfterInterceptors=function(a){return angular.forEach(k.afterResponseInterceptors,function(b){a.resource=k,a=b(a)}),a},k.processResponse=function(a){return a=k.callInterceptors(a).then(function(a){return a.data}),k.callAfterInterceptors(a)},k.getParameters=function(a){var b;return k.defaultParams&&(b=k.defaultParams),angular.isObject(a)&&(b=angular.extend(b||{},a)),b},k.getHttpConfig=function(a){var b=k.getParameters(a);return b?angular.extend({params:b},k.httpConfig):angular.copy(k.httpConfig)},k.$url=k.resourceUrl=function(a,b){return angular.isObject(a)||(a={id:a}),j(k.url(a||{}),b)},k.$get=function(a,b){return k.processResponse(c.get(a,k.getHttpConfig(b)))},k.query=function(a,b){return k.$get(k.resourceUrl(b),a)},k.get=function(a,b){return k.$get(k.resourceUrl(a),b)},k.prototype.$url=function(a){return j(k.resourceUrl(this),a)},k.prototype.processResponse=function(a){return a=k.callInterceptors(a,this),a=a.then(angular.bind(this,function(a){return a.hasOwnProperty("data")&&angular.isObject(a.data)&&angular.extend(this,a.data),this})),k.callAfterInterceptors(a)},angular.forEach(["post","put","patch"],function(a){k["$"+a]=function(b,d){var e;return d=k.transformData(angular.copy(d,{})),e=angular.extend({method:a,url:b,data:d},k.getHttpConfig()),k.processResponse(c(e))},k.prototype["$"+a]=function(b){var d,e;return d=k.transformData(angular.copy(this,{})),e=angular.extend({method:a,url:b,data:d},k.getHttpConfig()),this.processResponse(c(e))}}),k.prototype.create=function(){return this.$post(this.$url(),this)},k.prototype.update=function(){return this["$"+k.updateMethod](this.$url(),this)},k.prototype.isNew=function(){return null==this.id},k.prototype.save=function(){return this.isNew()?this.create():this.update()},k.$delete=function(a){return k.processResponse(c["delete"](a,k.getHttpConfig()))},k.prototype.$delete=function(a){return this.processResponse(c["delete"](a,k.getHttpConfig()))},k.prototype.remove=k.prototype["delete"]=function(){return this.$delete(this.$url())},k}return j}]})}();
7
+ !function(){angular.module("rails",["ng"])}(),function(){angular.module("rails").factory("RailsInflector",function(){function a(a){return angular.isString(a)?a.replace(/_[\w\d]/g,function(a,b,c){return 0===b?a:c.charAt(b+1).toUpperCase()}):a}function b(a){return angular.isString(a)?a.replace(/[A-Z]/g,function(a,b){return 0===b?a:"_"+a.toLowerCase()}):a}function c(a){return a+"s"}return{camelize:a,underscore:b,pluralize:c}})}(),function(a){angular.module("rails").factory("RailsResourceInjector",["$injector",function(b){function c(c){return c?angular.isString(c)?b.get(c):c:a}function d(d){return d?b.instantiate(c(d)):a}return{createService:d,getDependency:c}}])}(),function(){angular.module("rails").factory("railsUrlBuilder",["$interpolate",function(a){return function(b){var c;return angular.isFunction(b)?b:(-1===b.indexOf(a.startSymbol())&&(b=b+"/"+a.startSymbol()+"id"+a.endSymbol()),c=a(b),function(a){return b=c(a),"/"===b.charAt(b.length-1)&&(b=b.substr(0,b.length-1)),b})}}])}(),function(a){angular.module("rails").provider("railsSerializer",function(){var b={underscore:a,camelize:a,pluralize:a,exclusionMatchers:[]};this.underscore=function(a){return b.underscore=a,this},this.camelize=function(a){return b.camelize=a,this},this.pluralize=function(a){return b.pluralize=a,this},this.exclusionMatchers=function(a){return b.exclusionMatchers=a,this},this.$get=["$injector","RailsInflector","RailsResourceInjector",function(c,d,e){function f(c,d){function f(){angular.isFunction(c)&&(d=c,c={}),this.exclusions={},this.inclusions={},this.serializeMappings={},this.deserializeMappings={},this.customSerializedAttributes={},this.preservedAttributes={},this.customSerializers={},this.nestedResources={},this.options=angular.extend({excludeByDefault:!1},b,c||{}),d&&d.call(this,this)}return f.prototype.exclude=function(){var a=this.exclusions;return angular.forEach(arguments,function(b){a[b]=!1}),this},f.prototype.only=function(){var a=this.inclusions;return this.options.excludeByDefault=!0,angular.forEach(arguments,function(b){a[b]=!0}),this},f.prototype.nestedAttribute=function(){var a=this;return angular.forEach(arguments,function(b){a.rename(b,b+"_attributes")}),this},f.prototype.resource=function(a,b,c){return this.nestedResources[a]=b,c&&this.serializeWith(a,c),this},f.prototype.rename=function(b,c,d){return this.serializeMappings[b]=c,(d||d===a)&&(this.deserializeMappings[c]=b),this},f.prototype.add=function(a,b){return this.customSerializedAttributes[a]=b,this},f.prototype.preserve=function(a){return this.preservedAttributes[a]=!0,this},f.prototype.serializeWith=function(a,b){return this.customSerializers[a]=b,this},f.prototype.isExcludedFromSerialization=function(b){if(this.options.excludeByDefault&&!this.inclusions.hasOwnProperty(b)||this.exclusions.hasOwnProperty(b))return!0;if(this.options.exclusionMatchers){var c=!1;return angular.forEach(this.options.exclusionMatchers,function(d){angular.isString(d)?c=c||0===b.indexOf(d):angular.isFunction(d)?c=c||d.call(a,b):d instanceof RegExp&&(c=c||d.test(b))}),c}return!1},f.prototype.getSerializedAttributeName=function(b){var c=this.serializeMappings[b]||b,d=this.isExcludedFromSerialization(c),e=this.isExcludedFromSerialization(b);if(this.options.excludeByDefault){if(d&&e)return a}else if(d||e)return a;return this.underscore(c)},f.prototype.isExcludedFromDeserialization=function(){return!1},f.prototype.getDeserializedAttributeName=function(b){var c=this.camelize(b);return c=this.deserializeMappings[b]||this.deserializeMappings[c]||c,this.isExcludedFromDeserialization(b)||this.isExcludedFromDeserialization(c)?a:c},f.prototype.getNestedResource=function(a){return e.getDependency(this.nestedResources[a])},f.prototype.getAttributeSerializer=function(b){var c=this.getNestedResource(b),d=this.customSerializers[b];return d?e.createService(d):c?c.serializer:a},f.prototype.serializeValue=function(a){var b=a,c=this;if(angular.isArray(a))b=[],angular.forEach(a,function(a){b.push(c.serializeValue(a))});else if(angular.isObject(a)){if(angular.isDate(a))return a;b={},angular.forEach(a,function(a,d){angular.isFunction(a)||c.serializeAttribute(b,d,a)})}return b},f.prototype.serializeAttribute=function(b,c,d){var e=this.getAttributeSerializer(c),f=this.getSerializedAttributeName(c);f!==a&&(b[f]=e?e.serialize(d):this.serializeValue(d))},f.prototype.serialize=function(a){var b=this.serializeValue(a),c=this;return angular.isObject(b)&&angular.forEach(this.customSerializedAttributes,function(d,e){angular.isFunction(d)&&(d=d.call(a,a)),c.serializeAttribute(b,e,d)}),b},f.prototype.deserializeValue=function(a,b){var c=a,d=this;if(angular.isArray(a))c=[],angular.forEach(a,function(a){c.push(d.deserializeValue(a,b))});else if(angular.isObject(a)){if(angular.isDate(a))return a;c={},b&&(c=new b),angular.forEach(a,function(a,b){d.deserializeAttribute(c,b,a)})}return c},f.prototype.deserializeAttribute=function(b,c,d){var e,f,g=this.getDeserializedAttributeName(c);g!==a&&(e=this.getAttributeSerializer(g),f=this.getNestedResource(g),b[g]=this.preservedAttributes[g]?d:e?e.deserialize(d,f):this.deserializeValue(d,f))},f.prototype.deserialize=function(a,b){return this.deserializeValue(a,b)},f.prototype.pluralize=function(a){return this.options.pluralize?this.options.pluralize(a):a},f.prototype.underscore=function(a){return this.options.underscore?this.options.underscore(a):a},f.prototype.camelize=function(a){return this.options.camelize?this.options.camelize(a):a},f}return b.underscore=b.underscore||d.underscore,b.camelize=b.camelize||d.camelize,b.pluralize=b.pluralize||d.pluralize,f.defaultOptions=b,f}]})}(),function(a){angular.module("rails").factory("railsRootWrappingTransformer",function(){return function(a,b){var c={};return c[angular.isArray(a)?b.rootPluralName:b.rootName]=a,c}}),angular.module("rails").factory("railsRootWrappingInterceptor",function(){return function(a){var b=a.resource;return b?a.then(function(a){return a.data&&a.data.hasOwnProperty(b.rootName)?a.data=a.data[b.rootName]:a.data&&a.data.hasOwnProperty(b.rootPluralName)&&(a.data=a.data[b.rootPluralName]),a}):a}}),angular.module("rails").provider("railsResourceFactory",function(){var b={enableRootWrapping:!0,updateMethod:"put",httpConfig:{},defaultParams:a};this.enableRootWrapping=function(a){return b.enableRootWrapping=a,this},this.updateMethod=function(a){return b.updateMethod=a,this},this.httpConfig=function(a){return b.httpConfig=a,this},this.defaultParams=function(a){return b.defaultParams=a,this},this.$get=["$http","$q","railsUrlBuilder","railsSerializer","railsRootWrappingTransformer","railsRootWrappingInterceptor","RailsResourceInjector",function(c,d,e,f,g,h,i){function j(d){function j(a,b){return b&&("/"!==b[0]&&(a+="/"),a+=b),a}function k(a){var b=this;if(a){var c=function(a){return{resource:k,context:b,response:a,then:function(a){return this.response=a(this.response,this.resource,this.context),c(this.response)}}},d=k.callInterceptors(c({data:a}),this).response.data;angular.extend(this,d)}}var l=d.requestTransformers,m=d.responseInterceptors,n=d.afterResponseInterceptors;return k.setUrl=function(a){k.url=e(a)},k.setUrl(d.url),k.enableRootWrapping=d.wrapData===a?b.enableRootWrapping:d.wrapData,k.httpConfig=d.httpConfig||b.httpConfig,k.httpConfig.headers=angular.extend({Accept:"application/json","Content-Type":"application/json"},k.httpConfig.headers||{}),k.defaultParams=d.defaultParams||b.defaultParams,k.updateMethod=(d.updateMethod||b.updateMethod).toLowerCase(),k.requestTransformers=[],k.responseInterceptors=[],k.afterResponseInterceptors=[],k.serializer=i.createService(d.serializer||f()),k.rootName=k.serializer.underscore(d.name),k.rootPluralName=k.serializer.underscore(d.pluralName||k.serializer.pluralize(d.name)),k.beforeResponse=function(a){a=i.getDependency(a),k.responseInterceptors.push(function(b){return b.then(function(c){return a(c.data,b.resource,b.context),c})})},k.afterResponse=function(a){a=i.getDependency(a),k.afterResponseInterceptors.push(function(b){return b.then(function(c){return a(c,b.resource),c})})},k.beforeRequest=function(a){a=i.getDependency(a),k.requestTransformers.push(function(b,c){return a(b,c)||b})},angular.forEach(m,function(a){k.responseInterceptors.push(i.getDependency(a))}),angular.forEach(n,function(a){k.afterResponseInterceptors.push(i.getDependency(a))}),angular.forEach(l,function(a){k.requestTransformers.push(i.getDependency(a))}),k.transformData=function(a){return a=k.serializer.serialize(a),angular.forEach(k.requestTransformers,function(b){a=b(a,k)}),k.enableRootWrapping&&(a=g(a,k)),a},k.callInterceptors=function(a,b){return a=a.then(function(a){return a.originalData=a.data,a}),k.enableRootWrapping&&(a.resource=k,a=h(a)),a.then(function(a){return a.data=k.serializer.deserialize(a.data,k),a}),angular.forEach(k.responseInterceptors,function(c){a.resource=k,a.context=b,a=c(a)}),a},k.callAfterInterceptors=function(a){return angular.forEach(k.afterResponseInterceptors,function(b){a.resource=k,a=b(a)}),a},k.processResponse=function(a){return a=k.callInterceptors(a).then(function(a){return a.data}),k.callAfterInterceptors(a)},k.getParameters=function(a){var b;return k.defaultParams&&(b=k.defaultParams),angular.isObject(a)&&(b=angular.extend(b||{},a)),b},k.getHttpConfig=function(a){var b=k.getParameters(a);return b?angular.extend({params:b},k.httpConfig):angular.copy(k.httpConfig)},k.$url=k.resourceUrl=function(a,b){return angular.isObject(a)||(a={id:a}),j(k.url(a||{}),b)},k.$get=function(a,b){return k.processResponse(c.get(a,k.getHttpConfig(b)))},k.query=function(a,b){return k.$get(k.resourceUrl(b),a)},k.get=function(a,b){return k.$get(k.resourceUrl(a),b)},k.prototype.$url=function(a){return j(k.resourceUrl(this),a)},k.prototype.processResponse=function(a){return a=k.callInterceptors(a,this),a=a.then(angular.bind(this,function(a){return a.hasOwnProperty("data")&&angular.isObject(a.data)&&angular.extend(this,a.data),this})),k.callAfterInterceptors(a)},angular.forEach(["post","put","patch"],function(a){k["$"+a]=function(b,d){var e;return d=k.transformData(angular.copy(d)),e=angular.extend({method:a,url:b,data:d},k.getHttpConfig()),k.processResponse(c(e))},k.prototype["$"+a]=function(b){var d,e;return d=k.transformData(angular.copy(this,{})),e=angular.extend({method:a,url:b,data:d},k.getHttpConfig()),this.processResponse(c(e))}}),k.prototype.create=function(){return this.$post(this.$url(),this)},k.prototype.update=function(){return this["$"+k.updateMethod](this.$url(),this)},k.prototype.isNew=function(){return null==this.id},k.prototype.save=function(){return this.isNew()?this.create():this.update()},k.$delete=function(a){return k.processResponse(c["delete"](a,k.getHttpConfig()))},k.prototype.$delete=function(a){return this.processResponse(c["delete"](a,k.getHttpConfig()))},k.prototype.remove=k.prototype["delete"]=function(){return this.$delete(this.$url())},k}return j}]})}();
Binary file
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "angularjs-rails-resource",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "main": "angularjs-rails-resource.js",
5
5
  "description": "A resource factory inspired by $resource from AngularJS",
6
6
  "repository": {
@@ -1,7 +1,7 @@
1
1
  module Angularjs
2
2
  module Rails
3
3
  module Resource
4
- VERSION = '0.2.4'
4
+ VERSION = '0.2.5'
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "angularjs-rails-resource",
3
3
  "description": "A resource factory inspired by $resource from AngularJS",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "main": "dist/angularjs-rails-resource.min.js",
6
6
  "homepage": "https://github.com/FineLinePrototyping/angularjs-rails-resource.git",
7
7
  "author": "",
@@ -416,6 +416,13 @@ describe('railsResourceFactory', function () {
416
416
  }));
417
417
  });
418
418
 
419
+ it('should be able to $post an array of resources', function () {
420
+ var data = [{id: 123, abc: 'xyz'}, {id: 124, abc: 'xyz'}];
421
+ $httpBackend['expectPOST']('/xyz', {tests: data} ).respond(200, {tests: data});
422
+ Test.$post('/xyz', data);
423
+ $httpBackend.flush();
424
+ });
425
+
419
426
  });
420
427
 
421
428
  describe('plural', function() {
@@ -319,7 +319,7 @@
319
319
  RailsResource['$' + method] = function (url, data) {
320
320
  var config;
321
321
  // clone so we can manipulate w/o modifying the actual instance
322
- data = RailsResource.transformData(angular.copy(data, {}));
322
+ data = RailsResource.transformData(angular.copy(data));
323
323
  config = angular.extend({method: method, url: url, data: data}, RailsResource.getHttpConfig());
324
324
  return RailsResource.processResponse($http(config));
325
325
  };
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angularjs-rails-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy Odom
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-27 00:00:00.000000000 Z
12
+ date: 2013-11-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A small AngularJS add-on for integrating with Rails via JSON more easily.
15
15
  email:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.1.9
88
+ rubygems_version: 2.0.6
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: AngularJS add-on resource add-on for integrating with Rails