diff --git a/bower.json b/bower.json index 4749e08..3fc0b43 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularjs-rails-resource", - "version": "2.3.0", + "version": "2.3.1", "main": "dist/angularjs-rails-resource.js", "description": "A resource factory inspired by $resource from AngularJS", "repository": { diff --git a/dist/angularjs-rails-resource.js b/dist/angularjs-rails-resource.js index bdc252f..611adb7 100644 --- a/dist/angularjs-rails-resource.js +++ b/dist/angularjs-rails-resource.js @@ -1,6 +1,6 @@ /** * A resource factory inspired by $resource from AngularJS - * @version v2.3.0 - 2016-09-07 + * @version v2.3.1 - 2016-09-21 * @link https://github.com/FineLinePrototyping/angularjs-rails-resource.git * @author */ @@ -1498,7 +1498,7 @@ angular.forEach(angular.copy(this), function(value, key) { if (attributesList.indexOf(key) === -1) { that[key] = undefined; } }); - return that.$patch(this.$url(), queryParams); + return that.$patch(this.$url(), this, queryParams); }; RailsResource.prototype.get = function () { diff --git a/dist/angularjs-rails-resource.min.js b/dist/angularjs-rails-resource.min.js index 3f04cc3..c10cb15 100644 --- a/dist/angularjs-rails-resource.min.js +++ b/dist/angularjs-rails-resource.min.js @@ -1,7 +1,7 @@ /** * A resource factory inspired by $resource from AngularJS - * @version v2.3.0 - 2016-09-07 + * @version v2.3.1 - 2016-09-21 * @link https://github.com/FineLinePrototyping/angularjs-rails-resource.git * @author */ -!function(a){angular.module("rails",["ng"])}(),function(a){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}function e(b){return angular.isObject(b)?b:b?d(b):a}return{createService:d,getService:e,getDependency:c}}])}(),function(a){angular.module("rails").factory("railsUrlBuilder",["$interpolate",function(a){return function(b){var c,d=b.url,e=b.idAttribute;return angular.isFunction(d)||angular.isUndefined(d)?d:(b.singular||-1!==d.indexOf(a.startSymbol())||(d=d+"/"+a.startSymbol()+e+a.endSymbol()),c=a(d),function(a){return d=c(a),"/"===d.charAt(d.length-1)&&(d=d.substr(0,d.length-1)),d})}}])}(),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.castedResources={},this.customDeserializeFn=a,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.cast=function(a,b){return this.castedResources[a]=b,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(a){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.config.serializer:a},f.prototype.serializeData=function(a){var b=a,c=this;if(angular.isArray(a))b=[],angular.forEach(a,function(a){b.push(c.serializeData(a))});else if(angular.isObject(a)){if(angular.isDate(a))return a;b={},this.serializeObject(b,a)}return b},f.prototype.serializeObject=function(a,b){var c=this;return angular.forEach(b,function(b,d){angular.isFunction(b)||c.serializeAttribute(a,d,b)}),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.serializeData(d))},f.prototype.serialize=function(a){var b=angular.copy(a),c=this;return angular.isObject(b)&&angular.forEach(this.customSerializedAttributes,function(d,e){angular.isArray(b)?angular.forEach(b,function(a,b){var f=d;angular.isFunction(d)&&(f=f.call(a,a)),c.serializeAttribute(a,e,f)}):(angular.isFunction(d)&&(d=d.call(a,a)),c.serializeAttribute(b,e,d))}),b=this.serializeData(b)},f.prototype.deserializeData=function(a,b){var c,d=a,f=this;if(angular.isArray(a))d=[],angular.forEach(a,function(a){d.push(f.deserializeData(a,b))});else if(angular.isObject(a)){if(angular.isDate(a))return a;if(d={},c=f.castedResources[a.type]){var g=e.getDependency(c);d=new g}else b&&(d=new b.config.resourceConstructor);this.deserializeObject(d,a)}return d},f.prototype.customDeserialize=function(a){this.customDeserializeFn=a},f.prototype.deserializeObject=function(a,b){var c=this;return"function"==typeof this.customDeserializeFn&&(b=this.customDeserializeFn.call(null,b)),angular.forEach(b,function(b,d){c.deserializeAttribute(a,d,b)}),b},f.prototype.deserializeAttribute=function(b,c,d){var e,f,g=this.getDeserializedAttributeName(c);g!==a&&(e=this.getAttributeSerializer(g),f=this.getNestedResource(g),this.preservedAttributes[g]?b[g]=d:b[g]=e?e.deserialize(d,f):this.deserializeData(d,f))},f.prototype.deserialize=function(a,b){return this.deserializeData(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("railsRootWrapper",function(){return{wrap:function(a,b){var c={};return c[angular.isArray(a)?b.config.pluralName:b.config.name]=a,c},unwrap:function(a,b,c){return a.data&&a.data.hasOwnProperty(b.config.name)?a.data=a.data[b.config.name]:a.data&&a.data.hasOwnProperty(b.config.pluralName)&&!c&&(a.data=a.data[b.config.pluralName]),a}}}),angular.module("rails").provider("RailsResource",function(){var b={rootWrapping:!0,updateMethod:"put",httpConfig:{},defaultParams:a,underscoreParams:!0,fullResponse:!1,singular:!1,extensions:[]};this.rootWrapping=function(a){return b.rootWrapping=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.underscoreParams=function(a){return b.underscoreParams=a,this},this.fullResponse=function(a){return b.fullResponse=a,this},this.extensions=function(){return b.extensions=[],angular.forEach(arguments,function(a){b.extensions=b.extensions.concat(a)}),this},this.$get=["$http","$q","railsUrlBuilder","railsSerializer","railsRootWrapper","RailsResourceInjector",function(c,d,e,f,g,h){function i(a){if(a){var b=this.constructor.deserialize({data:a});this.constructor.config.rootWrapping&&(b=g.unwrap(b,this.constructor,!0)),angular.extend(this,b.data)}}function j(a,b){return b&&("/"!==b[0]&&(a+="/"),a+=b),a}function k(a,b){for(var c,d=0,e=a.length;e>d;d++)c=a[d],angular.isString(c)&&(c=a[d]=h.getDependency(c)),b(c)}function l(a,b,c,d){var e=["included","extended,","configure"];a.$mixins||(a.$mixins=[]),angular.isString(c)&&(c=h.getDependency(c)),c&&-1===a.$mixins.indexOf(c)&&(angular.forEach(c,function(a,c){-1===e.indexOf(c)&&(b[c]=a)}),a.$mixins.push(c),angular.isFunction(d)&&d(a,c))}function m(a){var b=[];return angular.forEach(a,function(a){a="RailsResource"+a.charAt(0).toUpperCase()+a.slice(1)+"Mixin",b.push(h.getDependency(a))}),b}function n(a,b){return angular.isUndefined(a)?b:a}function o(a,b,c){return function(d){return(a||angular.identity)(d,b,c)}}function p(a,b,c){return function(e){return a?a(e,b,c):d.reject(e)}}return i.extendTo=function(a){function b(){this.constructor=a}return angular.forEach(this,function(b,c){a[c]=b}),angular.isArray(this.$modules)&&(a.$modules=this.$modules.slice(0)),b.prototype=this.prototype,a.prototype=new b,a.__super__=this.prototype,a},i.extend=function(){return angular.forEach(arguments,function(a){l(this,this,a,function(a,b){angular.isFunction(b.extended)&&b.extended(a)})},this),this},i.include=function(){return angular.forEach(arguments,function(a){l(this,this.prototype,a,function(a,b){angular.isFunction(b.included)&&b.included(a)})},this),this},i.configure=function(a){return a=a||{},this.config&&(a=angular.extend({},this.config,a)),this.config={},this.config.idAttribute=a.idAttribute||"id",this.config.url=a.url,this.config.rootWrapping=n(a.rootWrapping,b.rootWrapping),this.config.httpConfig=a.httpConfig||b.httpConfig,this.config.httpConfig.headers=angular.extend({Accept:"application/json","Content-Type":"application/json"},this.config.httpConfig.headers||{}),this.config.defaultParams=a.defaultParams||b.defaultParams,this.config.underscoreParams=n(a.underscoreParams,b.underscoreParams),this.config.updateMethod=(a.updateMethod||b.updateMethod).toLowerCase(),this.config.fullResponse=n(a.fullResponse,b.fullResponse),this.config.requestTransformers=a.requestTransformers?a.requestTransformers.slice(0):[],this.config.responseInterceptors=a.responseInterceptors?a.responseInterceptors.slice(0):[],this.config.afterResponseInterceptors=a.afterResponseInterceptors?a.afterResponseInterceptors.slice(0):[],this.config.interceptors=a.interceptors?a.interceptors.slice(0):[],this.config.serializer=h.getService(a.serializer||f()),this.config.name=this.config.serializer.underscore(a.name),this.config.name&&(this.config.pluralName=this.config.serializer.underscore(a.pluralName||this.config.serializer.pluralize(this.config.name))),this.config.urlBuilder=e(this.config),this.config.resourceConstructor=this,this.extend.apply(this,m((a.extensions||[]).concat(b.extensions))),angular.forEach(this.$mixins,function(b){angular.isFunction(b.configure)&&b.configure(this.config,a)},this),this.config},i.setUrl=function(a){this.configure({url:a})},i.buildUrl=function(a){return this.config.urlBuilder(a)},i.addInterceptor=function(a){this.config.interceptors.push(a)},i.intercept=function(a,b){var c={};b=h.getDependency(b),c[a]=function(a,c,d){return b(a,c,d)||a},this.addInterceptor(c)},i.interceptBeforeRequest=function(a){this.intercept("beforeRequest",a)},i.interceptBeforeRequestWrapping=function(a){this.intercept("beforeRequestWrapping",a)},i.interceptRequest=function(a){this.intercept("request",a)},i.interceptBeforeResponse=function(a){this.intercept("beforeResponse",a)},i.interceptBeforeResponseDeserialize=function(a){this.intercept("beforeResponseDeserialize",a)},i.interceptResponse=function(a){this.intercept("response",a)},i.interceptAfterResponse=function(a){this.intercept("afterResponse",a)},i.beforeResponse=function(a){a=h.getDependency(a),this.interceptResponse(function(b,c,d){return a(b.data,c.config.resourceConstructor,d),b})},i.afterResponse=function(a){a=h.getDependency(a),this.interceptAfterResponse(function(b,c,d){return a(b,c.config.resourceConstructor,d),b})},i.beforeRequest=function(a){a=h.getDependency(a),this.interceptBeforeRequestWrapping(function(b,c){return b.data=a(b.data,c.config.resourceConstructor)||b.data,b})},i.serialize=function(a){return a.data&&(a.data=this.config.serializer.serialize(a.data)),a},i.deserialize=function(a){return a.data=this.config.serializer.deserialize(a.data,this.config.resourceConstructor),a},i.callResponseInterceptors=function(a,b){var c=this.config;return k(c.responseInterceptors,function(d){a.resource=c.resourceConstructor,a.context=b,a=d(a)}),a},i.callAfterResponseInterceptors=function(a){var b=this.config;return k(b.afterResponseInterceptors,function(c){a.resource=b.resourceConstructor,a=c(a)}),a},i.runInterceptorPhase=function(a,b,c){var d=this.config,e=[];for(k(d.interceptors,function(b){(b[a]||b[a+"Error"])&&e.push(b[a],b[a+"Error"])});e.length;){var f=e.shift(),g=e.shift();c=c.then(o(f,d.resourceConstructor,b),p(g,d.resourceConstructor,b))}return c},i.$http=function(a,b,e){var f=angular.extend(angular.copy(this.config),e||{}),h=f.resourceConstructor,i=d.when(a);return f.skipRequestProcessing?i=c(a):(i=this.runInterceptorPhase("beforeRequest",b,i).then(function(a){return a=h.serialize(a),k(f.requestTransformers,function(b){a.data=b(a.data,f.resourceConstructor)}),a}),i=this.runInterceptorPhase("beforeRequestWrapping",b,i),f.rootWrapping&&(i=i.then(function(a){return a.data=g.wrap(a.data,f.resourceConstructor),a})),i=this.runInterceptorPhase("request",b,i).then(function(a){return c(a)})),i=this.runInterceptorPhase("beforeResponse",b,i).then(function(a){return a.originalData=a.data,a}),f.rootWrapping&&(i=i.then(function(a){return g.unwrap(a,f.resourceConstructor,!1)})),i=this.runInterceptorPhase("beforeResponseDeserialize",b,i).then(function(a){return h.deserialize(a)}),i=this.callResponseInterceptors(i,b),i=this.runInterceptorPhase("response",b,i).then(function(a){return b&&a.hasOwnProperty("data")&&angular.isObject(a.data)&&angular.extend(b,a.data),f.fullResponse?a:b||a.data}),i=this.callAfterResponseInterceptors(i,b),i=this.runInterceptorPhase("afterResponse",b,i),i.resource=f.resourceConstructor,i.context=b,i},i.processParameters=function(a){var b={};return angular.isObject(a)&&this.config.underscoreParams?(angular.forEach(a,function(a,c){b[this.config.serializer.underscore(c)]=a},this),b):a},i.getParameters=function(a){var b;return this.config.defaultParams&&(b=angular.copy(this.config.defaultParams)),angular.isObject(a)&&(b=angular.extend(b||{},a)),this.processParameters(b)},i.getHttpConfig=function(a){var b=this.getParameters(a);return b?angular.extend({params:b},this.config.httpConfig):angular.copy(this.config.httpConfig)},i.$url=i.resourceUrl=function(a,b){return angular.isObject(a)||(a={id:a}),j(this.buildUrl(a||{}),b)},i.$get=function(a,b){return this.$http(angular.extend({method:"get",url:a},this.getHttpConfig(b)))},i.query=function(a,b){return this.$get(this.resourceUrl(b),a)},i.get=function(a,b){return this.$get(this.resourceUrl(a),b)},i.prototype.$url=function(a){return j(this.constructor.resourceUrl(this),a)},i.prototype.$http=function(a,b){return this.constructor.$http(a,this,b)},angular.forEach(["post","put","patch"],function(a){i["$"+a]=function(b,c,d,e){return c=angular.copy(c),this.$http(angular.extend({method:a,url:b,data:c},this.getHttpConfig(e)),null,d)},i.prototype["$"+a]=function(b,c,d){var e=angular.copy(this,{});return this.constructor.$http(angular.extend({method:a,url:b,data:e},this.constructor.getHttpConfig(d)),this)}}),i.prototype.create=function(){return this.$post(this.$url(),this)},i.prototype.update=function(){return this["$"+this.constructor.config.updateMethod](this.$url(),this)},i.prototype.patch=function(b,c){var d=angular.copy(this);return angular.forEach(angular.copy(this),function(c,e){-1===b.indexOf(e)&&(d[e]=a)}),d.$patch(this.$url(),c)},i.prototype.get=function(){return this.constructor.$http(angular.extend({method:"GET",url:this.$url()},this.constructor.getHttpConfig()),this)},i.prototype.getRelated=function(a,b,c){var d=c?h.getDependency(c):this.constructor;return d.$get(this.$url(a),b)},i.prototype.isNew=function(){var a=this.constructor.config.idAttribute;return angular.isUndefined(this[a])||null===this[a]},i.prototype.save=function(){return this.isNew()?this.create():this.update()},i.$delete=function(a,b){return this.$http(angular.extend({method:"delete",url:a},this.getHttpConfig(b)))},i.prototype.$delete=function(a,b){return this.constructor.$http(angular.extend({method:"delete",url:a},this.constructor.getHttpConfig(b)),this)},i.prototype.remove=i.prototype["delete"]=function(){return this.$delete(this.$url())},i}]}),angular.module("rails").factory("railsResourceFactory",["RailsResource",function(a){return function(b){function c(){c.__super__.constructor.apply(this,arguments)}return a.extendTo(c),c.configure(b),c}}])}(); \ No newline at end of file +!function(a){angular.module("rails",["ng"])}(),function(a){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}function e(b){return angular.isObject(b)?b:b?d(b):a}return{createService:d,getService:e,getDependency:c}}])}(),function(a){angular.module("rails").factory("railsUrlBuilder",["$interpolate",function(a){return function(b){var c,d=b.url,e=b.idAttribute;return angular.isFunction(d)||angular.isUndefined(d)?d:(b.singular||-1!==d.indexOf(a.startSymbol())||(d=d+"/"+a.startSymbol()+e+a.endSymbol()),c=a(d),function(a){return d=c(a),"/"===d.charAt(d.length-1)&&(d=d.substr(0,d.length-1)),d})}}])}(),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.castedResources={},this.customDeserializeFn=a,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.cast=function(a,b){return this.castedResources[a]=b,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(a){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.config.serializer:a},f.prototype.serializeData=function(a){var b=a,c=this;if(angular.isArray(a))b=[],angular.forEach(a,function(a){b.push(c.serializeData(a))});else if(angular.isObject(a)){if(angular.isDate(a))return a;b={},this.serializeObject(b,a)}return b},f.prototype.serializeObject=function(a,b){var c=this;return angular.forEach(b,function(b,d){angular.isFunction(b)||c.serializeAttribute(a,d,b)}),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.serializeData(d))},f.prototype.serialize=function(a){var b=angular.copy(a),c=this;return angular.isObject(b)&&angular.forEach(this.customSerializedAttributes,function(d,e){angular.isArray(b)?angular.forEach(b,function(a,b){var f=d;angular.isFunction(d)&&(f=f.call(a,a)),c.serializeAttribute(a,e,f)}):(angular.isFunction(d)&&(d=d.call(a,a)),c.serializeAttribute(b,e,d))}),b=this.serializeData(b)},f.prototype.deserializeData=function(a,b){var c,d=a,f=this;if(angular.isArray(a))d=[],angular.forEach(a,function(a){d.push(f.deserializeData(a,b))});else if(angular.isObject(a)){if(angular.isDate(a))return a;if(d={},c=f.castedResources[a.type]){var g=e.getDependency(c);d=new g}else b&&(d=new b.config.resourceConstructor);this.deserializeObject(d,a)}return d},f.prototype.customDeserialize=function(a){this.customDeserializeFn=a},f.prototype.deserializeObject=function(a,b){var c=this;return"function"==typeof this.customDeserializeFn&&(b=this.customDeserializeFn.call(null,b)),angular.forEach(b,function(b,d){c.deserializeAttribute(a,d,b)}),b},f.prototype.deserializeAttribute=function(b,c,d){var e,f,g=this.getDeserializedAttributeName(c);g!==a&&(e=this.getAttributeSerializer(g),f=this.getNestedResource(g),this.preservedAttributes[g]?b[g]=d:b[g]=e?e.deserialize(d,f):this.deserializeData(d,f))},f.prototype.deserialize=function(a,b){return this.deserializeData(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("railsRootWrapper",function(){return{wrap:function(a,b){var c={};return c[angular.isArray(a)?b.config.pluralName:b.config.name]=a,c},unwrap:function(a,b,c){return a.data&&a.data.hasOwnProperty(b.config.name)?a.data=a.data[b.config.name]:a.data&&a.data.hasOwnProperty(b.config.pluralName)&&!c&&(a.data=a.data[b.config.pluralName]),a}}}),angular.module("rails").provider("RailsResource",function(){var b={rootWrapping:!0,updateMethod:"put",httpConfig:{},defaultParams:a,underscoreParams:!0,fullResponse:!1,singular:!1,extensions:[]};this.rootWrapping=function(a){return b.rootWrapping=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.underscoreParams=function(a){return b.underscoreParams=a,this},this.fullResponse=function(a){return b.fullResponse=a,this},this.extensions=function(){return b.extensions=[],angular.forEach(arguments,function(a){b.extensions=b.extensions.concat(a)}),this},this.$get=["$http","$q","railsUrlBuilder","railsSerializer","railsRootWrapper","RailsResourceInjector",function(c,d,e,f,g,h){function i(a){if(a){var b=this.constructor.deserialize({data:a});this.constructor.config.rootWrapping&&(b=g.unwrap(b,this.constructor,!0)),angular.extend(this,b.data)}}function j(a,b){return b&&("/"!==b[0]&&(a+="/"),a+=b),a}function k(a,b){for(var c,d=0,e=a.length;e>d;d++)c=a[d],angular.isString(c)&&(c=a[d]=h.getDependency(c)),b(c)}function l(a,b,c,d){var e=["included","extended,","configure"];a.$mixins||(a.$mixins=[]),angular.isString(c)&&(c=h.getDependency(c)),c&&-1===a.$mixins.indexOf(c)&&(angular.forEach(c,function(a,c){-1===e.indexOf(c)&&(b[c]=a)}),a.$mixins.push(c),angular.isFunction(d)&&d(a,c))}function m(a){var b=[];return angular.forEach(a,function(a){a="RailsResource"+a.charAt(0).toUpperCase()+a.slice(1)+"Mixin",b.push(h.getDependency(a))}),b}function n(a,b){return angular.isUndefined(a)?b:a}function o(a,b,c){return function(d){return(a||angular.identity)(d,b,c)}}function p(a,b,c){return function(e){return a?a(e,b,c):d.reject(e)}}return i.extendTo=function(a){function b(){this.constructor=a}return angular.forEach(this,function(b,c){a[c]=b}),angular.isArray(this.$modules)&&(a.$modules=this.$modules.slice(0)),b.prototype=this.prototype,a.prototype=new b,a.__super__=this.prototype,a},i.extend=function(){return angular.forEach(arguments,function(a){l(this,this,a,function(a,b){angular.isFunction(b.extended)&&b.extended(a)})},this),this},i.include=function(){return angular.forEach(arguments,function(a){l(this,this.prototype,a,function(a,b){angular.isFunction(b.included)&&b.included(a)})},this),this},i.configure=function(a){return a=a||{},this.config&&(a=angular.extend({},this.config,a)),this.config={},this.config.idAttribute=a.idAttribute||"id",this.config.url=a.url,this.config.rootWrapping=n(a.rootWrapping,b.rootWrapping),this.config.httpConfig=a.httpConfig||b.httpConfig,this.config.httpConfig.headers=angular.extend({Accept:"application/json","Content-Type":"application/json"},this.config.httpConfig.headers||{}),this.config.defaultParams=a.defaultParams||b.defaultParams,this.config.underscoreParams=n(a.underscoreParams,b.underscoreParams),this.config.updateMethod=(a.updateMethod||b.updateMethod).toLowerCase(),this.config.fullResponse=n(a.fullResponse,b.fullResponse),this.config.requestTransformers=a.requestTransformers?a.requestTransformers.slice(0):[],this.config.responseInterceptors=a.responseInterceptors?a.responseInterceptors.slice(0):[],this.config.afterResponseInterceptors=a.afterResponseInterceptors?a.afterResponseInterceptors.slice(0):[],this.config.interceptors=a.interceptors?a.interceptors.slice(0):[],this.config.serializer=h.getService(a.serializer||f()),this.config.name=this.config.serializer.underscore(a.name),this.config.name&&(this.config.pluralName=this.config.serializer.underscore(a.pluralName||this.config.serializer.pluralize(this.config.name))),this.config.urlBuilder=e(this.config),this.config.resourceConstructor=this,this.extend.apply(this,m((a.extensions||[]).concat(b.extensions))),angular.forEach(this.$mixins,function(b){angular.isFunction(b.configure)&&b.configure(this.config,a)},this),this.config},i.setUrl=function(a){this.configure({url:a})},i.buildUrl=function(a){return this.config.urlBuilder(a)},i.addInterceptor=function(a){this.config.interceptors.push(a)},i.intercept=function(a,b){var c={};b=h.getDependency(b),c[a]=function(a,c,d){return b(a,c,d)||a},this.addInterceptor(c)},i.interceptBeforeRequest=function(a){this.intercept("beforeRequest",a)},i.interceptBeforeRequestWrapping=function(a){this.intercept("beforeRequestWrapping",a)},i.interceptRequest=function(a){this.intercept("request",a)},i.interceptBeforeResponse=function(a){this.intercept("beforeResponse",a)},i.interceptBeforeResponseDeserialize=function(a){this.intercept("beforeResponseDeserialize",a)},i.interceptResponse=function(a){this.intercept("response",a)},i.interceptAfterResponse=function(a){this.intercept("afterResponse",a)},i.beforeResponse=function(a){a=h.getDependency(a),this.interceptResponse(function(b,c,d){return a(b.data,c.config.resourceConstructor,d),b})},i.afterResponse=function(a){a=h.getDependency(a),this.interceptAfterResponse(function(b,c,d){return a(b,c.config.resourceConstructor,d),b})},i.beforeRequest=function(a){a=h.getDependency(a),this.interceptBeforeRequestWrapping(function(b,c){return b.data=a(b.data,c.config.resourceConstructor)||b.data,b})},i.serialize=function(a){return a.data&&(a.data=this.config.serializer.serialize(a.data)),a},i.deserialize=function(a){return a.data=this.config.serializer.deserialize(a.data,this.config.resourceConstructor),a},i.callResponseInterceptors=function(a,b){var c=this.config;return k(c.responseInterceptors,function(d){a.resource=c.resourceConstructor,a.context=b,a=d(a)}),a},i.callAfterResponseInterceptors=function(a){var b=this.config;return k(b.afterResponseInterceptors,function(c){a.resource=b.resourceConstructor,a=c(a)}),a},i.runInterceptorPhase=function(a,b,c){var d=this.config,e=[];for(k(d.interceptors,function(b){(b[a]||b[a+"Error"])&&e.push(b[a],b[a+"Error"])});e.length;){var f=e.shift(),g=e.shift();c=c.then(o(f,d.resourceConstructor,b),p(g,d.resourceConstructor,b))}return c},i.$http=function(a,b,e){var f=angular.extend(angular.copy(this.config),e||{}),h=f.resourceConstructor,i=d.when(a);return f.skipRequestProcessing?i=c(a):(i=this.runInterceptorPhase("beforeRequest",b,i).then(function(a){return a=h.serialize(a),k(f.requestTransformers,function(b){a.data=b(a.data,f.resourceConstructor)}),a}),i=this.runInterceptorPhase("beforeRequestWrapping",b,i),f.rootWrapping&&(i=i.then(function(a){return a.data=g.wrap(a.data,f.resourceConstructor),a})),i=this.runInterceptorPhase("request",b,i).then(function(a){return c(a)})),i=this.runInterceptorPhase("beforeResponse",b,i).then(function(a){return a.originalData=a.data,a}),f.rootWrapping&&(i=i.then(function(a){return g.unwrap(a,f.resourceConstructor,!1)})),i=this.runInterceptorPhase("beforeResponseDeserialize",b,i).then(function(a){return h.deserialize(a)}),i=this.callResponseInterceptors(i,b),i=this.runInterceptorPhase("response",b,i).then(function(a){return b&&a.hasOwnProperty("data")&&angular.isObject(a.data)&&angular.extend(b,a.data),f.fullResponse?a:b||a.data}),i=this.callAfterResponseInterceptors(i,b),i=this.runInterceptorPhase("afterResponse",b,i),i.resource=f.resourceConstructor,i.context=b,i},i.processParameters=function(a){var b={};return angular.isObject(a)&&this.config.underscoreParams?(angular.forEach(a,function(a,c){b[this.config.serializer.underscore(c)]=a},this),b):a},i.getParameters=function(a){var b;return this.config.defaultParams&&(b=angular.copy(this.config.defaultParams)),angular.isObject(a)&&(b=angular.extend(b||{},a)),this.processParameters(b)},i.getHttpConfig=function(a){var b=this.getParameters(a);return b?angular.extend({params:b},this.config.httpConfig):angular.copy(this.config.httpConfig)},i.$url=i.resourceUrl=function(a,b){return angular.isObject(a)||(a={id:a}),j(this.buildUrl(a||{}),b)},i.$get=function(a,b){return this.$http(angular.extend({method:"get",url:a},this.getHttpConfig(b)))},i.query=function(a,b){return this.$get(this.resourceUrl(b),a)},i.get=function(a,b){return this.$get(this.resourceUrl(a),b)},i.prototype.$url=function(a){return j(this.constructor.resourceUrl(this),a)},i.prototype.$http=function(a,b){return this.constructor.$http(a,this,b)},angular.forEach(["post","put","patch"],function(a){i["$"+a]=function(b,c,d,e){return c=angular.copy(c),this.$http(angular.extend({method:a,url:b,data:c},this.getHttpConfig(e)),null,d)},i.prototype["$"+a]=function(b,c,d){var e=angular.copy(this,{});return this.constructor.$http(angular.extend({method:a,url:b,data:e},this.constructor.getHttpConfig(d)),this)}}),i.prototype.create=function(){return this.$post(this.$url(),this)},i.prototype.update=function(){return this["$"+this.constructor.config.updateMethod](this.$url(),this)},i.prototype.patch=function(b,c){var d=angular.copy(this);return angular.forEach(angular.copy(this),function(c,e){-1===b.indexOf(e)&&(d[e]=a)}),d.$patch(this.$url(),this,c)},i.prototype.get=function(){return this.constructor.$http(angular.extend({method:"GET",url:this.$url()},this.constructor.getHttpConfig()),this)},i.prototype.getRelated=function(a,b,c){var d=c?h.getDependency(c):this.constructor;return d.$get(this.$url(a),b)},i.prototype.isNew=function(){var a=this.constructor.config.idAttribute;return angular.isUndefined(this[a])||null===this[a]},i.prototype.save=function(){return this.isNew()?this.create():this.update()},i.$delete=function(a,b){return this.$http(angular.extend({method:"delete",url:a},this.getHttpConfig(b)))},i.prototype.$delete=function(a,b){return this.constructor.$http(angular.extend({method:"delete",url:a},this.constructor.getHttpConfig(b)),this)},i.prototype.remove=i.prototype["delete"]=function(){return this.$delete(this.$url())},i}]}),angular.module("rails").factory("railsResourceFactory",["RailsResource",function(a){return function(b){function c(){c.__super__.constructor.apply(this,arguments)}return a.extendTo(c),c.configure(b),c}}])}(); \ No newline at end of file diff --git a/dist/angularjs-rails-resource.zip b/dist/angularjs-rails-resource.zip index 01c8a36..46b9567 100644 Binary files a/dist/angularjs-rails-resource.zip and b/dist/angularjs-rails-resource.zip differ diff --git a/dist/extensions/snapshots.min.js b/dist/extensions/snapshots.min.js index d8422c2..32969b6 100644 --- a/dist/extensions/snapshots.min.js +++ b/dist/extensions/snapshots.min.js @@ -1,6 +1,6 @@ /** * A resource factory inspired by $resource from AngularJS - * @version v2.3.0 - 2016-09-07 + * @version v2.3.1 - 2016-09-21 * @link https://github.com/FineLinePrototyping/angularjs-rails-resource.git * @author */ diff --git a/package.json b/package.json index c653177..eed6adf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "angularjs-rails-resource", "description" : "A resource factory inspired by $resource from AngularJS", - "version": "2.3.0", + "version": "2.3.1", "main" : "dist/angularjs-rails-resource.js", "homepage" : "https://github.com/FineLinePrototyping/angularjs-rails-resource.git", "author" : "",