angularjs-rails-resource 0.2.5 → 1.0.0.pre.1

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: 3af2e27b94554d7c76725e83fbafe496f428dba6
4
- data.tar.gz: 49b9c83300358da0e4aa970949ee48c1b0d7671f
3
+ metadata.gz: 6949c58b7d5354dcb4b311248088c8f831c958c6
4
+ data.tar.gz: da054ff28d6285541d7f0e5a1deb23b3b83fb91c
5
5
  SHA512:
6
- metadata.gz: 138e28efba7ce29cc39fbdfbfa07435b8709237664219ea5169c2fbe390fb47f074afd45fb3d9603f2860014b1ceba3c7332b12630cba2f66368e0af610da732
7
- data.tar.gz: abb4c0ced83000383d828540957cf2cefe769ff25dc507e5d1be7a7b9a3ac105437188b4ca1121d72a4aff2f602e4d48d4b70f732423924b31971c94ffe75187
6
+ metadata.gz: 8e2c661c2fcd2df398eeeb071c607f39e258f53e28bd5e9c9670616182a7a984ecb786ba91b2a680fc71299479f6e3a97e6449a6a8bd759743c59e36452bdee3
7
+ data.tar.gz: f63c1513e65a2254390bc3205eaeb0541b2f35f6c24669f8d52b140f2a4ff9f5fc8ea9b6bd641781d5f66fdc9ba1e09497adc73148163b7f056766136c32f69b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ <a name="1.0.0"></a>
2
+ # 1.0.0
3
+ ## Bug Fixes
4
+
5
+ ## Features
6
+ - Added <code>configure</code> to allow changing configuration options after the resource has been initially configured.
7
+
8
+ ## Breaking Changes
9
+ - <code>railsResourceFactoryProvider</code> settings have been moved to <code>RailsResourceProvider</code>
10
+ - <code>wrapData</code> config option has been renamed <code>rootWrapping</code>
11
+ - All resource settings are now stored under the <code>config</code> property on the resource and should be modified using the <code>configure</code> function.
12
+ - The following resource settings have been renamed:
13
+ - <code>enableRootWrapping</code> was renamed <code>rootWrapping</code>
14
+ - <code>rootName</code> was renamed <code>name</code>
15
+ - <code>rootPluralName</code> was renamed <code>pluralName</code>
16
+
1
17
  <a name="0.2.3"></a>
2
18
  # 0.2.3
3
19
  ## Bug Fixes
@@ -25,14 +41,14 @@
25
41
  - Removed default transformers and interceptors
26
42
  - railsFieldRenamingTransformer and railsFieldRenamingInterceptor have been removed completely and replaced by the serializers
27
43
  - railsRootWrappingTransformer/Interceptor are no longer configured by the transformers/interceptors configuration option and is instead
28
- configured by the <code>enableRootWrapping</code> option.
44
+ configured by the <code>wrapData</code> option.
29
45
  - Interceptors added using <code>beforeRequest</code> are run before any deserialization so the fields names have not been camelized.
30
46
 
31
47
  ## Bug Fixes
32
48
 
33
49
  ## Features
34
50
  - Added serializers to replace old field renaming logic and to give users a lot more flexibility in customizing the (de)serialization process
35
- - Added <code>enableRootWrapping</code> configuration option to be able to turn off root wrapping instead
51
+ - Added <code>rootWrapping</code> configuration option to be able to turn off root wrapping instead
36
52
  - Added path option to <code>$url</code> methods to make it easier to construct a nested url.
37
53
 
38
54
  <a name="0.1.7"></a>
data/EXAMPLES.md CHANGED
@@ -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
 
data/README.md CHANGED
@@ -3,35 +3,59 @@
3
3
 
4
4
  A resource factory inspired by $resource from AngularJS and [Misko's recommendation](http://stackoverflow.com/questions/11850025/recommended-way-of-getting-data-from-the-server).
5
5
 
6
- When starting out with AngularJS and Rails we initially were using $resource but there were three things we didn't like that this gem sets out to provide:
6
+ ## Differences from $resource
7
+ This library is not a drop in replacement for $resource. There are significant differences that you should be aware of and
7
8
 
8
- 1. $resource didn't return promises
9
- 2. Rails prefers JSON be root wrapped
10
- 3. Our JSON contained snake case (underscored) keys coming from our database but we didn't want to mix snake case and camel case in our UI
9
+ 1. <code>get</code> and <code>query</code> return [$q promises](http://docs.angularjs.org/api/ng.$q), not an instance or array that will be populated. To gain access to the results you
10
+ should use the promise <code>then</code> function.
11
+ 2. By default we perform root wrapping and unwrapping (if wrapped) when communicating with the server.
12
+ 3. By default we convert attribute names between underscore and camel case.
11
13
 
12
- In case you are unfamiliar, the intent of the resource is to behave a bit like a remote model object. One of the nice things about AngularJS
13
- is that it does not require you to create specific models for all of your data which gives you a lot of freedom for treating model data as basic
14
- javascript objects. However, on the Rails side when exposing models to a javascript application you are likely going to follow the same pattern for multiple
15
- models where you will have a controller that has your basic index (query), get, create, update, delete functionality.
14
+ ## FAQs
15
+ ### How come I can't iterate the array returned from query?
16
+ We don't return an array. We return promises not arrays or objects that get filled in later.
16
17
 
17
- The resource object created by this factory simplifies access to those models by exposing a mix of "class" methods (query, get) and
18
- "instance" methods (create, update, delete/remove).
19
-
20
- This module is being used for applications we are writing and we expect that over time that we will be adding additional functionality but we welcome contributions and suggestions.
18
+ If you need access to the array in your JS code you can use the promise <code>then</code> function:
19
+ ````javascript
20
+ Book.query({title: 'Moby Dick'}).then(function (books) {
21
+ $scope.books = books;
22
+ });
23
+ ````
21
24
 
22
- ## Changes
23
- Make sure to check the [CHANGELOG](CHANGELOG.md) for any breaking changes between releases.
25
+ ### I like underscores, how can I turn off the name conversion?
26
+ You can inject the <code>railsSerializerProvider</code> into your application config function and override the <code>underscore</code>
27
+ and <code>camelize</code> functions:
28
+ ````javascript
29
+ angular.module('app').config(function (railsSerializerFactory) {
30
+ railsSerializerProvider.
31
+ underscore(function (name) {
32
+ return name;
33
+ }).
34
+ camelize(function (name) {
35
+ return name;
36
+ });
37
+ });
38
+ ````
24
39
 
25
40
  ## Installation
26
-
27
- Add this line to your application's Gemfile:
41
+ Add this line to your application's Gemfile to use the latest stable version:
28
42
  ```ruby
29
- gem 'angularjs-rails-resource', '~> 0.2.0'
43
+ gem 'angularjs-rails-resource', '~> 0.2.3'
30
44
  ```
45
+
31
46
  Include the javascript somewhere in your asset pipeline:
32
47
  ```javascript
33
48
  //= require angularjs/rails/resource
34
49
  ```
50
+ ## Branching and Versioning
51
+ As much as possible we will try to adhere to the [SemVer](http://semver.org/) guidelines on release numbering.
52
+
53
+ The master branch may contain work in progress and should not be considered stable.
54
+
55
+ Release branches should remain stable but it is always best to rely on the ruby gem release versions as the most stable versions.
56
+
57
+ ## Changes
58
+ Make sure to check the [CHANGELOG](CHANGELOG.md) for any breaking changes between releases.
35
59
 
36
60
  ## Dependencies
37
61
  Since this is an [AngularJS](http://angularjs.org) module it of course depends on that but more specifically the it depends on the following AngularJS services:
@@ -44,8 +68,7 @@ Since this is an [AngularJS](http://angularjs.org) module it of course depends o
44
68
  ## Usage
45
69
  There are a lot of different ways that you can use the resources and we try not to force you into any specific pattern
46
70
 
47
- There are more examples available in [EXAMPLES.md](EXAMPLES.md). We also published a complete working example (including the rails side)
48
- at [Employee Training Tracker](https://github.com/FineLinePrototyping/employee-training-tracker) application.
71
+ There are more examples available in [EXAMPLES.md](EXAMPLES.md).
49
72
 
50
73
 
51
74
  ### Basic Example
@@ -78,6 +101,7 @@ angular.module('book.controllers').controller('BookShelfCtrl', ['$scope', 'Book'
78
101
  new Book({title: 'Gardens of the Moon', author: 'Steven Erikson', isbn: '0-553-81957-7'}).create();
79
102
  }]);
80
103
  ```
104
+
81
105
  ### Serializer
82
106
  When defining a resource, you can pass a custom [serializer](#serializers) using the <code>serializer</code> configuration option.
83
107
  ```javascript
@@ -113,17 +137,47 @@ Book = railsResourceFactory({
113
137
 
114
138
  ```
115
139
  ## Resource Creation
116
- Creating a resource using this factory is similar to using $resource, you just call <code>railsResourceFactory</code> with the config options and it returns a new resource function.
117
- The resource function serves two purposes. First is that you can use (or define new) "class" methods directly accessible such as query and get to retrieve
118
- instances from the backend rails service. The second is that it allows you to use it as a constructor to create new instances of that resource giving you access
119
- to create, update, and delete instance methods (or any others you add).
140
+ There are multiple ways that you can set up new resources in your application.
141
+
142
+ ### railsResourceFactory
143
+ Similar to $resource, we provide a <code>railsResourceFactory(config)</code> function that takes a config object with the configuration
144
+ settings for the new resource. The factory function returns a new class that is extended from RailsResource.
145
+
146
+ ### RailsResource extension
147
+ We also expose the RailsResource as base class that you can extend to create your own resource classes. Extending the RailsResource class
148
+ directly gives you a bit more flexibility to add custom constructor code. There are probably ten different ways to extend the class but
149
+ the two that we intend to be used are through CoffeeScript or through the same logic that the factory function uses.
120
150
 
151
+ #### CoffeeScript
152
+ ````coffeescript
153
+ class Book extends RailsResource
154
+ @configure url: '/books', name: 'book'
155
+
156
+ class Encyclopedia extends Book
157
+ @configure url: '/encyclopedias', name: 'encyclopedia'
158
+ ````
159
+
160
+ #### JavaScript
161
+ Since the purpose of exposing the RailsResource was to allow for CoffeeScript users to create classes from it the JavaScript way
162
+ is basically just the same as the generated CoffeeScript code. The <code>RailsResource.extend</code> function is a modification
163
+ of the <code>__extends</code> function that CoffeeScript generates.
164
+
165
+ ````javascript
166
+ function Resource() {
167
+ Resource.__super__.constructor.apply(this, arguments);
168
+ }
169
+
170
+ RailsResource.extend(Resource);
171
+ Resource.configure(config);
172
+ ````
121
173
 
122
174
  ### Config Options
123
- The following options are available for the config object passed to the factory function.
175
+
176
+ The following configuration options are available for customizing resources. Each of the configuration options can be passed as part of an object
177
+ to the <code>railsResourceFactory</code> function or to the resource's <code>configure</code> function.
124
178
 
125
179
  * **url** - This is the url of the service. See [Resource URLs](#resource-urls) below for more information.
126
- * **enableRootWrapping** - (Default: true) Turns on/off root wrapping on JSON (de)serialization.
180
+ * **rootWrapping** - (Default: true) Turns on/off root wrapping on JSON (de)serialization.
127
181
  * **name** - This is the name used for root wrapping when dealing with singular instances.
128
182
  * **pluralName** *(optional)* - If specified this name will be used for unwrapping array results. If not specified then the serializer's [pluralize](#serializers) method is used to calculate
129
183
  the plural name from the singular name.
@@ -133,6 +187,7 @@ The following options are available for the config object passed to the factory
133
187
  * **Content-Type** - application/json
134
188
  * **defaultParams** *(optional)* - If the resource expects a default set of query params on every call you can specify them here.
135
189
  * **updateMethod** *(optional)* - Allows overriding the default HTTP method (PUT) used for update. Valid values are "post", "put", or "patch".
190
+ * **serializer** *(optional)* - Allows specifying a custom [serializer](#serializers) allow configuring custom serialization options.
136
191
  * **requestTransformers** *(optional) - See [Transformers / Interceptors](#transformers--interceptors)
137
192
  * **responseInterceptors** *(optional)* - See [Transformers / Interceptors](#transformers--interceptors)
138
193
  * **afterResponseInterceptors** *(optional)* - See [Transformers / Interceptors](#transformers--interceptors)
@@ -141,11 +196,11 @@ The following options are available for the config object passed to the factory
141
196
  For example, you should specify "publishingCompany" and "publishingCompanies" instead of "publishing_company" and "publishing_companies".
142
197
 
143
198
  ### Provider Configuration
144
- <code>railsResourceFactory</code> can be injected as <code>railsResourceFactoryProvider</code> into your app's config method to configure defaults for all the resources application-wide.
199
+ <code>RailsResource</code> can be injected as <code>RailsResourceProvider</code> into your app's config method to configure defaults for all the resources application-wide.
145
200
  The individual resource configuration takes precedence over application-wide default configuration values.
146
201
  Each configuration option listed is exposed as a method on the provider that takes the configuration value as the parameter and returns the provider to allow method chaining.
147
202
 
148
- * enableRootWrapping - {function(boolean):railsSerializerProvider}
203
+ * rootWrapping - {function(boolean):railsSerializerProvider}
149
204
  * httpConfig - {function(object):railsSerializerProvider}
150
205
  * defaultParams - {function(object):railsSerializerProvider}
151
206
  * updateMethod - {function(boolean):railsSerializerProvider}
@@ -153,8 +208,8 @@ Each configuration option listed is exposed as a method on the provider that tak
153
208
  For example, to turn off the root wrapping application-wide and set the update method to PATCH:
154
209
 
155
210
  ````javascript
156
- app.config(function (railsResourceFactoryProvider) {
157
- railsResourceFactoryProvider.enableRootWrapping(false).updateMethod('patch');
211
+ app.config(function (RailsResourceProvider) {
212
+ RailsResourceProvider.rootWrapping(false).updateMethod('patch');
158
213
  );
159
214
  ````
160
215
 
@@ -184,12 +239,16 @@ that if response.data is reassigned that there's still a pointer to the original
184
239
 
185
240
 
186
241
  ## Resource Methods
187
- Resources created using <code>railsResourceFactory</code> have the following class and instance methods available.
242
+ RailsResources have the following class methods available.
188
243
 
189
244
  ### Class Methods
190
245
  * Constructor(data) - The Resource object can act as a constructor function for use with the JavaScript <code>new</code> keyword.
191
246
  * **data** {object} (optional) - Optional data to set on the new instance
192
247
 
248
+ * configure(options) - Change one or more configuration option for a resource.
249
+
250
+ * setUrl(url) - Updates the url for the resource, same as calling <code>configure({url: url})</code>
251
+
193
252
  * $url(context, path) - Returns the resource URL using the given context with the optional path appended if provided.
194
253
  * **context** {*} - The context to use when building the url. See [Resource URLs](#resource-urls) above for more information.
195
254
  * **path** {string} (optional) - A path to append to the resource's URL.
@@ -314,14 +373,6 @@ Each configuration option listed is exposed as a method on the provider that tak
314
373
  * pluralize - {function(fn):railsSerializerProvider}
315
374
  * exclusionMatchers - {function(matchers):railsSerializerProvider}
316
375
 
317
- For example, to turn off the key renaming from underscore to camel case and vice versa you would do:
318
-
319
- ````javascript
320
- app.config(function (railsSerializerProvider) {
321
- railsSerializerProvider.underscore(function (value) { return value; })
322
- .camelize(function (value) { return value; });
323
- );
324
- ````
325
376
 
326
377
  #### Customization API
327
378
  The customizer function passed to the railsSerializer has available to it the following methods for altering the serialization of an object. None of these methods support nested attribute names (e.g. <code>'books.publicationDate'</code>), in order to customize the serialization of the <code>books</code> objects you would need to specify a custom serializer for the <code>books</code> attribute.