angularjs-rails-resource 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A resource factory inspired by $resource from AngularJS
3
+ * @version v0.2.3 - 2013-09-28
4
+ * @link https://github.com/FineLinePrototyping/angularjs-rails-resource.git
5
+ * @author
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}]})}();
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "angularjs-rails-resource",
3
+ "version": "0.2.3",
4
+ "main": "angularjs-rails-resource.js",
5
+ "description": "A resource factory inspired by $resource from AngularJS",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/FineLinePrototyping/angularjs-rails-resource.git"
9
+ },
10
+ "dependencies": {
11
+ "angular": "*"
12
+ },
13
+ "ignore": [
14
+ "node_modules",
15
+ "Gemfile",
16
+ "Gruntfile.js",
17
+ "karma.conf.js",
18
+ "package.json",
19
+ "Rakefile",
20
+ "angularjs-rails-resource.gemspec",
21
+ "test",
22
+ "vendor",
23
+ "lib",
24
+ "*.zip",
25
+ ".travis.yml",
26
+ ".gitignore"
27
+ ]
28
+ }
@@ -1,7 +1,7 @@
1
1
  module Angularjs
2
2
  module Rails
3
3
  module Resource
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
6
6
  end
7
7
  end
@@ -1,16 +1,39 @@
1
1
  {
2
2
  "name": "angularjs-rails-resource",
3
- "version": "0.0.0",
4
- "dependencies": {
5
- },
6
- "scripts": {
7
- "test": "./node_modules/.bin/karma start --single-run --browsers PhantomJS"
3
+ "description": "A resource factory inspired by $resource from AngularJS",
4
+ "version": "0.2.3",
5
+ "main": "dist/angularjs-rails-resource.min.js",
6
+ "homepage": "https://github.com/FineLinePrototyping/angularjs-rails-resource.git",
7
+ "author": "",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/FineLinePrototyping/angularjs-rails-resource.git"
8
11
  },
12
+ "keywords": [
13
+ "angular",
14
+ "resources"
15
+ ],
16
+ "dependencies": {},
9
17
  "devDependencies": {
18
+ "grunt": "~0.4.1",
19
+ "grunt-contrib-jshint": "~0.6.0",
20
+ "grunt-contrib-uglify": "~0.2.2",
21
+ "grunt-contrib-concat": "~0.3.0",
22
+ "grunt-contrib-watch": "~0.5.1",
23
+ "grunt-zip": "~0.9.2",
10
24
  "karma": "~0.10",
11
25
  "karma-jasmine": "~0.1",
12
26
  "karma-chrome-launcher": "~0.1",
13
27
  "karma-phantomjs-launcher": "~0.1",
14
28
  "karma-junit-reporter": "~0.1"
15
- }
16
- }
29
+ },
30
+ "scripts": {
31
+ "test": "./node_modules/.bin/karma start --single-run --browsers PhantomJS"
32
+ },
33
+ "licenses": [
34
+ {
35
+ "type": "MIT",
36
+ "url": "https://github.com/FineLinePrototyping/angularjs-rails-resource.js/blob/master/LICENSE"
37
+ }
38
+ ]
39
+ }
@@ -381,6 +381,13 @@ describe('railsResourceFactory', function () {
381
381
  expect(test).toEqualData({id: 123, abcDef: "T"});
382
382
  });
383
383
 
384
+ it('should support constructing with date properties', function () {
385
+ var testDate = new Date(),
386
+ test = new Test({id: 123, testDate: testDate});
387
+
388
+ expect(test.testDate).toBe(testDate);
389
+ });
390
+
384
391
  angular.forEach(['post', 'put', 'patch'], function (method) {
385
392
  it('should be able to ' + method + ' to arbitrary url', inject(function($httpBackend) {
386
393
  var promise, result = {};
@@ -436,6 +436,10 @@
436
436
  result.push(self.deserializeValue(value, Resource));
437
437
  });
438
438
  } else if (angular.isObject(data)) {
439
+ if (angular.isDate(data)) {
440
+ return data;
441
+ }
442
+
439
443
  result = {};
440
444
 
441
445
  if (Resource) {
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.2
4
+ version: 0.2.3
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-08-10 00:00:00.000000000 Z
12
+ date: 2013-09-29 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:
@@ -24,10 +24,15 @@ files:
24
24
  - CHANGELOG.md
25
25
  - EXAMPLES.md
26
26
  - Gemfile
27
+ - Gruntfile.js
27
28
  - LICENSE
28
29
  - README.md
29
30
  - Rakefile
30
31
  - angularjs-rails-resource.gemspec
32
+ - angularjs-rails-resource.js
33
+ - angularjs-rails-resource.min.js
34
+ - angularjs-rails-resource.zip
35
+ - bower.json
31
36
  - karma.conf.js
32
37
  - lib/angularjs-rails-resource.rb
33
38
  - lib/angularjs-rails-resource/version.rb