angularjs-rails-resource 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTFlYThkZWUwZGQzZmYwMmI3ODA0MmFhMTJjODQxNzg0MzEwMWZiYQ==
5
- data.tar.gz: !binary |-
6
- M2I1ZTlkNGE4MzlhYTQ1YzdiYTUwODZlMzFlMGVkNzRiYTU0ZTMzYg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZTNhNjViNjAzNDNkY2JkNzgwYWE5MjBmMGViZDkzNjBmOWM2YTY0YjFiNmJj
10
- NzkxYTE5Y2U5NTgwMjJhOTY1NTE3Yjk5ZjMxMDY4MzU2MzE3NmUxNDE4YWZj
11
- OTlhZGYxZDU3MWZlZTUwZjNlMGVkMjg5OTE4MjRkOWE1YWZjYTM=
12
- data.tar.gz: !binary |-
13
- ZjNlY2FkMDA4MDhlMTJhMzEyYzkxNWEyMmFhODE1Y2ExMTIzODFmNGU5ODY5
14
- M2NmZTJmMGQ1ZDc0ZTE5ZjA1OTE2NWFhY2VhODY4YjgyY2I5ZGZkNGVhMmUy
15
- Y2NiYmJkNjEzMGQ4YzZkMzUyZTgwMTFmNDMyMzgyNWUxZDJkNDk=
2
+ SHA1:
3
+ metadata.gz: d157c5ed2c1ddd214a91ddfe19c13b820dfc5a91
4
+ data.tar.gz: 928857da368dcfbff87e63c36e4e490f5c33dce4
5
+ SHA512:
6
+ metadata.gz: 710afddc7abe88b944dfe92897ebb8e6c81696314598bc07d5217556889385d20714b313bea9bca226ef30159ffa765949bd44435174ad2969ce4f567b695148
7
+ data.tar.gz: 9bdd1b3d25e0103621d04d2b07e2bc711e54f69c183d070e730d8232639fffda0e92d44703cc78e3a9390ff1c07e2f38bf09117574f1e904f7e580de3ef7f8cb
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * A resource factory inspired by $resource from AngularJS
3
- * @version v0.2.3 - 2013-09-28
3
+ * @version v0.2.4 - 2013-10-27
4
4
  * @link https://github.com/FineLinePrototyping/angularjs-rails-resource.git
5
5
  * @author
6
6
  */
@@ -408,8 +408,17 @@
408
408
  Serializer.prototype.getSerializedAttributeName = function (attributeName) {
409
409
  var mappedName = this.serializeMappings[attributeName] || attributeName;
410
410
 
411
- if (this.isExcludedFromSerialization(attributeName) || this.isExcludedFromSerialization(mappedName)) {
412
- return undefined;
411
+ var mappedNameExcluded = this.isExcludedFromSerialization(mappedName),
412
+ attributeNameExcluded = this.isExcludedFromSerialization(attributeName);
413
+
414
+ if(this.options.excludeByDefault) {
415
+ if(mappedNameExcluded && attributeNameExcluded) {
416
+ return undefined;
417
+ }
418
+ } else {
419
+ if (mappedNameExcluded || attributeNameExcluded) {
420
+ return undefined;
421
+ }
413
422
  }
414
423
 
415
424
  return this.underscore(mappedName);
@@ -474,7 +483,7 @@
474
483
 
475
484
  // custom serializer takes precedence over resource serializer
476
485
  if (serializer) {
477
- return RailsResourceInjector.createService(serializer)
486
+ return RailsResourceInjector.createService(serializer);
478
487
  } else if (resource) {
479
488
  return resource.serializer;
480
489
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A resource factory inspired by $resource from AngularJS
3
- * @version v0.2.3 - 2013-09-28
3
+ * @version v0.2.4 - 2013-10-27
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;return this.isExcludedFromSerialization(b)||this.isExcludedFromSerialization(c)?a: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.3",
3
+ "version": "0.2.4",
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.3'
4
+ VERSION = '0.2.4'
5
5
  end
6
6
  end
7
7
  end
data/package.json CHANGED
@@ -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.3",
4
+ "version": "0.2.4",
5
5
  "main": "dist/angularjs-rails-resource.min.js",
6
6
  "homepage": "https://github.com/FineLinePrototyping/angularjs-rails-resource.git",
7
7
  "author": "",
@@ -390,6 +390,22 @@ describe('railsSerializer', function () {
390
390
  result = serializer.deserialize({id: 1, first: 'George', middle: 'R. R.', last: 'Martin'});
391
391
  expect(result).toEqualData({id: 1, first: 'George', middle: 'R. R.', last: 'Martin'});
392
392
  });
393
+
394
+ it('should only serialize id and books', function() {
395
+ var result,
396
+ serializer = createSerializer(function(config) {
397
+ this.only('id', 'books');
398
+ this.nestedAttribute('books');
399
+ this.serializeWith('books', factory(function() { }));
400
+ });
401
+ var book = { id: 1, title: 'A Game of Thrones', publicationDate: '1996-08-06' };
402
+ result = serializer.serialize({
403
+ id: 1, first: 'George', last: 'Martin', books: [book]
404
+ });
405
+ expect(result).toEqualData({ id: 1, books_attributes: [{ id: 1, title: 'A Game of Thrones', publication_date: '1996-08-06' }] });
406
+ result = serializer.deserialize(result);
407
+ expect(result).toEqual({ id: 1, books: [book]});
408
+ });
393
409
  });
394
410
  });
395
411
  });
@@ -263,8 +263,17 @@
263
263
  Serializer.prototype.getSerializedAttributeName = function (attributeName) {
264
264
  var mappedName = this.serializeMappings[attributeName] || attributeName;
265
265
 
266
- if (this.isExcludedFromSerialization(attributeName) || this.isExcludedFromSerialization(mappedName)) {
267
- return undefined;
266
+ var mappedNameExcluded = this.isExcludedFromSerialization(mappedName),
267
+ attributeNameExcluded = this.isExcludedFromSerialization(attributeName);
268
+
269
+ if(this.options.excludeByDefault) {
270
+ if(mappedNameExcluded && attributeNameExcluded) {
271
+ return undefined;
272
+ }
273
+ } else {
274
+ if (mappedNameExcluded || attributeNameExcluded) {
275
+ return undefined;
276
+ }
268
277
  }
269
278
 
270
279
  return this.underscore(mappedName);
@@ -329,7 +338,7 @@
329
338
 
330
339
  // custom serializer takes precedence over resource serializer
331
340
  if (serializer) {
332
- return RailsResourceInjector.createService(serializer)
341
+ return RailsResourceInjector.createService(serializer);
333
342
  } else if (resource) {
334
343
  return resource.serializer;
335
344
  }
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.3
4
+ version: 0.2.4
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-09-29 00:00:00.000000000 Z
12
+ date: 2013-10-27 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:
@@ -75,17 +75,17 @@ require_paths:
75
75
  - lib
76
76
  required_ruby_version: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - ! '>='
78
+ - - '>='
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - ! '>='
83
+ - - '>='
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.0.6
88
+ rubygems_version: 2.1.9
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: AngularJS add-on resource add-on for integrating with Rails