angularjs-rails-resource 2.0.0 → 2.1.0

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: 5dcbb9f729e55fc427ad6eaed8e5356f08315d30
4
- data.tar.gz: 19cfc254499c9fe89f5db0bf93576055d2309f89
3
+ metadata.gz: 3f99d3285acce5e56b23fb1afcb9f9441f2bbc00
4
+ data.tar.gz: d23f60d6f53df27985752e40129329d9a740d585
5
5
  SHA512:
6
- metadata.gz: 06c9d9ea3be0fbfea6a3bee07b7a85a08623a3d4d394f0ccee79597d65eb4cd9f0f723d8ac53260e4102767d6597da2d6fcf71a900af256650fe23dc0c7e8ac7
7
- data.tar.gz: 008723eb726c8aa86aa84ccc15468ef7a6ee223a05ff16fec7c75dc53bf0dbbbf3900a059d28df60ca2afa7f3fd88f6bf13f365a6f52a79b423d92496e5171df
6
+ metadata.gz: 79ae6274c9fe790e75ce17fc06b8f9d116dfee01d6a49e253fc685f4aa08736f0c4ace185250a038e5866c8fb02c539924935cb1429fe54e6f75b6a3082396aa
7
+ data.tar.gz: 9c0721c4f9be00b5cddba762a8869e1c7cfbc0ee7c1cd3c31e121551787529c99e6c9413af94c5c9f85c4337a258acd3e394f8495f7270b3f5afcb2ab94743b6
@@ -1,3 +1,9 @@
1
+ <a name="2.1.0"></a>
2
+ # 2.1.0
3
+ ## Features
4
+ - Added option for singular resources - #187 (@jnfeinstein)
5
+ - <code>configure</code> now returns the config object. - #176 (@poporul)
6
+
1
7
  <a name="2.0.0"></a>
2
8
  # 2.0.0
3
9
  ## Breaking Changes
data/README.md CHANGED
@@ -107,6 +107,9 @@ class Encyclopedia extends Book
107
107
  @configure url: '/encyclopedias', name: 'encyclopedia'
108
108
  ````
109
109
 
110
+ **NOTE:** Always call <code>@configure()</code> in subclasses, even when no configuration is required.
111
+ This is important to prevent overriding the parent's configuration with interceptors, etc (especially when using a module mixin pattern).
112
+
110
113
  ##### JavaScript
111
114
  Since the purpose of exposing the RailsResource was to allow for CoffeeScript users to create classes from it the JavaScript way
112
115
  is basically just the same as the generated CoffeeScript code. The <code>RailsResource.extendTo</code> function is a modification
@@ -126,7 +129,7 @@ Resource.configure(config);
126
129
  angular.module('book.controllers').controller('BookShelfCtrl', ['$scope', 'Book', function ($scope, Book) {
127
130
  $scope.searching = true;
128
131
  $scope.books = [];
129
-
132
+
130
133
  // Find all books matching the title
131
134
  Book.query({ title: title }).then(function (results) {
132
135
  $scope.books = results;
@@ -208,6 +211,7 @@ defined on the resource can be called multiple times to adjust properties as nee
208
211
  * **updateMethod** *(optional)* - Allows overriding the default HTTP method (PUT) used for update. Valid values are "post", "put", or "patch".
209
212
  * **serializer** *(optional)* - Allows specifying a custom [serializer](#serializers) to configure custom serialization options.
210
213
  * **fullResponse** *(optional)* - When set to true promises will return full $http responses instead of just the response data.
214
+ * **singular** - (Default: false) Treat this as a [singular resource](http://guides.rubyonrails.org/routing.html#singular-resources).
211
215
  * **interceptors** *(optional)* - See [Interceptors](#interceptors)
212
216
  * **extensions** *(optional)* - See [Extensions](#extensions)
213
217
 
@@ -442,7 +446,7 @@ The customizer function passed to the railsSerializer has available to it the fo
442
446
 
443
447
  * rename (javascriptName, jsonName) - Specifies a custom name mapping for an attribute. On serializing to JSON the <code>jsonName</code> will be used. On deserialization, if <code>jsonName</code> is seen then it will be renamed as javascriptName in the resulting resource. Right now it is still passed to underscore so you could do 'publicationDate' -> 'releaseDate' and it will still underscore as release_date. However, that may be changed to prevent underscore from breaking some custom name that it doesn't handle properly.
444
448
 
445
- * nestedAttribute (attributeName...) - This is a shortcut for rename that allows you to specify a variable number of attributes that should all be renamed to <code><name>_attributes</code> to work with the Rails nested_attributes feature. This does not perform any additional logic to accomodate specifying the <code>_destroy</code> property.
449
+ * nestedAttribute (attributeName...) - This is a shortcut for rename that allows you to specify a variable number of attributes that should all be renamed to <code><name>_attributes</code> to work with the Rails nested_attributes feature. This does not perform any additional logic to accommodate specifying the <code>_destroy</code> property.
446
450
 
447
451
  * resource (attributeName, resource, serializer) - Specifies an attribute that is a nested resource within the parent object. Nested resources do not imply nested attributes, if you want both you still have to specify call <code>nestedAttribute</code> as well. A nested resource serves two purposes. First, it defines the resource that should be used when constructing resources from the server. Second, it specifies how the nested object should be serialized. An optional third parameter <code>serializer</code> is available to override the serialization logic of the resource in case you need to serialize it differently in multiple contexts.
448
452
 
@@ -457,7 +461,7 @@ are also defined to expose underscore, camelize, and pluralize. Those functions
457
461
  ## Interceptors
458
462
  The entire request / response processing is configured as a [$q promise chain](http://docs.angularjs.org/api/ng.$q). Interceptors allow inserting additional synchronous or asynchronous processing at various phases in the request / response cycle. The flexibility of the synchronous or asynchronous promise resolution allows any number of customizations to be built. For instance, on response you could load additional data before returning that the current response is complete. Or, you could listen to multiple phases and set a flag that a save operation is in progress in <code>beforeRequest</code> and then in <code>afterResponse</code> and <code>afterResponseError</code> you could clear the flag.
459
463
 
460
- Interceptors are similar in design to the $http interceptors. You can add interceptors via the <code>RailsResource.addInterceptors</code> method or by explicitly adding them to the <code>interceptors</code> array on the on the resource <code>config</code> object. When you add the interceptor, you can add it using either the interceptor service factory name or the object reference. An interceptor should contain a set of keys representing one of the valid phases and the callback function for the phase.
464
+ Interceptors are similar in design to the $http interceptors. You can add interceptors via the <code>RailsResource.addInterceptor</code> method or by explicitly adding them to the <code>interceptors</code> array on the on the resource <code>config</code> object. When you add the interceptor, you can add it using either the interceptor service factory name or the object reference. An interceptor should contain a set of keys representing one of the valid phases and the callback function for the phase.
461
465
 
462
466
  There are several phases for both request and response to give users and mixins more flexibility for exactly where they want to insert a customization. Each phase also has a corresponding error phase which is the phase name appended with Error (e.g. beforeResponse and beforeResponseError). The error phases receive the current rejection value which in most cases would be the error returned from $http. Since these are $q promises, your interceptor can decide whether or not to propagate the error or recover from it. If you want to propagate the error, you must return a <code>$q.reject(reason)</code> result. Otherwise any value you return will be treated as a successful value to use for the rest of the chain. For instance, in the <code>beforeResponseError</code> phase you could attempt to recover by using an alternate URL for the request data and return the new promise as the result.
463
467
 
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "angularjs-rails-resource",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "main": "angularjs-rails-resource.js",
5
5
  "description": "A resource factory inspired by $resource from AngularJS",
6
6
  "repository": {
@@ -8,7 +8,7 @@
8
8
  "url": "https://github.com/FineLinePrototyping/dist-angularjs-rails-resource.git"
9
9
  },
10
10
  "dependencies": {
11
- "angular": "*"
11
+ "angular": "~1.0"
12
12
  },
13
13
  "ignore": [
14
14
  "node_modules",
@@ -1,7 +1,7 @@
1
1
  module Angularjs
2
2
  module Rails
3
3
  module Resource
4
- VERSION = '2.0.0'
4
+ VERSION = '2.1.0'
5
5
  end
6
6
  end
7
7
  end
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "angularjs-rails-resource",
3
3
  "description" : "A resource factory inspired by $resource from AngularJS",
4
- "version": "2.0.0",
5
- "main" : "dist/angularjs-rails-resource.min.js",
4
+ "version": "2.1.0",
5
+ "main" : "angularjs-rails-resource.min.js",
6
6
  "homepage" : "https://github.com/FineLinePrototyping/angularjs-rails-resource.git",
7
7
  "author" : "",
8
8
  "repository": {
@@ -13,7 +13,9 @@
13
13
  "angular",
14
14
  "resources"
15
15
  ],
16
- "dependencies": {},
16
+ "dependencies": {
17
+ "angular": "~1.0"
18
+ },
17
19
  "devDependencies": {
18
20
  "grunt": "~0.4.1",
19
21
  "grunt-contrib-jshint": "~0.6.0",
@@ -534,6 +534,11 @@ describe('railsResourceFactory', function () {
534
534
  expect(new Test({id: 1}).isNew()).toBeFalsy();
535
535
  });
536
536
 
537
+ it('configure should return config object', function() {
538
+ var Resource = factory();
539
+ expect(Resource.configure(config)).toBeInstanceOf(Object);
540
+ });
541
+
537
542
  describe('overridden idAttribute', function () {
538
543
  beforeEach(inject(function (_$httpBackend_, _$rootScope_, railsResourceFactory) {
539
544
  Test = railsResourceFactory({url: '/test', name: 'test', idAttribute: 'xyz'});
@@ -22,6 +22,13 @@ describe("railsUrlBuilder", function () {
22
22
  })({id: 1})).toEqualData('/books/1');
23
23
  }));
24
24
 
25
+ it('should not append id when singular', inject(function (railsUrlBuilder) {
26
+ expect(railsUrlBuilder({
27
+ url: '/book',
28
+ singular: true
29
+ })()).toEqualData('/book');
30
+ }));
31
+
25
32
  it('should use author id for book list', inject(function (railsUrlBuilder) {
26
33
  expect(railsUrlBuilder({
27
34
  url: '/authors/{{authorId}}/books/{{id}}',
@@ -26,6 +26,7 @@
26
26
  defaultParams: undefined,
27
27
  underscoreParams: true,
28
28
  fullResponse: false,
29
+ singular: false,
29
30
  extensions: []
30
31
  };
31
32
 
@@ -243,6 +244,8 @@
243
244
  mixin.configure(this.config, cfg);
244
245
  }
245
246
  }, this);
247
+
248
+ return this.config;
246
249
  };
247
250
 
248
251
  /**
@@ -39,7 +39,7 @@
39
39
  return url;
40
40
  }
41
41
 
42
- if (url.indexOf($interpolate.startSymbol()) === -1) {
42
+ if (!config.singular && url.indexOf($interpolate.startSymbol()) === -1) {
43
43
  url = url + '/' + $interpolate.startSymbol() + idAttribute + $interpolate.endSymbol();
44
44
  }
45
45
 
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: 2.0.0
4
+ version: 2.1.0
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: 2015-02-11 00:00:00.000000000 Z
12
+ date: 2016-03-20 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:
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  requirements: []
83
83
  rubyforge_project:
84
- rubygems_version: 2.2.2
84
+ rubygems_version: 2.4.6
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: AngularJS add-on resource add-on for integrating with Rails