joosy 1.2.0.beta.2 → 1.2.0.beta.3

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: 9778d9024a861575e4e595d878ed2c1106c3fb0d
4
- data.tar.gz: 599dd5188839458f6d940dc57d80d5dc90644b2f
3
+ metadata.gz: 30784fe114cfea49eb5facff2e2bc3bbd130079d
4
+ data.tar.gz: 7cd597e827d64ce5867f0372f1de7e5a8a1e7448
5
5
  SHA512:
6
- metadata.gz: 97b0b50d74727b70076bfba5a77616b94b97f51ed94bec6de610ebc350ee7c2012069828dc4c45700d8e6c4a512e923a2ccbde10ec26a322ad2e4ef1d4cdeb2b
7
- data.tar.gz: 4d50aebd0d8d3b69d890f1a767e1b794b26bac2fe147fecbcf2643d11f054f1b05a2dec8643ea8a2a7a3ff040c6918869c80f0665c4bb126a92019b8795c1103
6
+ metadata.gz: 93a573baf9ccd3761819836bc36e790c8c3665ec2fed7507dbec63df2a8b9475335e390e184663e483cd5ac3039095f6d7af2e182dae8d6e6241b3a13f21cff6
7
+ data.tar.gz: a447a876a4796fe3775d2211cbe8cae280a92e3a7a0ffc688b15f3468278d332113fede7e0ce8cb1b27ad2ee7236bc74e7c584a1db0be463f674262a7ebc8258
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joosy",
3
- "version": "1.2.0-beta.2",
3
+ "version": "1.2.0-beta.3",
4
4
  "main": "build/joosy.js",
5
5
  "ignore": [
6
6
  "lib",
@@ -1 +1 @@
1
- (function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b};Joosy.Resources.Array=function(a){function c(){this.__fillData(arguments,!1)}return b(c,a),Joosy.Module.merge(c,Joosy.Module),c.include(Joosy.Modules.Events),c.include(Joosy.Modules.Filters),c.registerPlainFilters("beforeLoad"),c.build=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})},c.prototype.load=function(){return this.__fillData(arguments)},c.prototype.get=function(a){return this[a]},c.prototype.set=function(a,b){return this[a]=b,this.trigger("changed"),b},c.prototype.push=function(){var a;return a=c.__super__.push.apply(this,arguments),this.trigger("changed"),a},c.prototype.pop=function(){var a;return a=c.__super__.pop.apply(this,arguments),this.trigger("changed"),a},c.prototype.shift=function(){var a;return a=c.__super__.shift.apply(this,arguments),this.trigger("changed"),a},c.prototype.unshift=function(){var a;return a=c.__super__.unshift.apply(this,arguments),this.trigger("changed"),a},c.prototype.splice=function(){var a;return a=c.__super__.splice.apply(this,arguments),this.trigger("changed"),a},c.prototype.__fillData=function(a,b){var c,d,e,f;for(null==b&&(b=!0),a=this.slice.call(a,0),this.length>0&&this.splice(0,this.length),f=this.__applyBeforeLoads(a),d=0,e=f.length;e>d;d++)c=f[d],this.push(c);return b&&this.trigger("changed"),null},c}(Array),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/array",function(){return Joosy.Resources.Array})}).call(this),function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b};Joosy.Resources.Hash=function(a){function c(a){null==a&&(a={}),this.__fillData(a,!1)}return b(c,a),c.include(Joosy.Modules.Events),c.include(Joosy.Modules.Filters),c.registerPlainFilters("beforeLoad"),c.build=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})},c.prototype.__call=function(a,b){return arguments.length>1?this.set(a,b):this.get(a)},c.prototype.load=function(a){return this.__fillData(a),this},c.prototype.get=function(a){var b,c,d;return d=this.__callTarget(a,!0),b=d[0],c=d[1],b?b.get?b.get(c):b[c]:void 0},c.prototype.set=function(a,b){var c,d,e;return e=this.__callTarget(a),c=e[0],d=e[1],null!=c.set?c.set(d,b):c[d]=b,this.trigger("changed"),b},c.prototype.__callTarget=function(a,b){var c,d,e,f,g;if(null==b&&(b=!1),-1!==a.indexOf(".")&&null==this.data[a]){for(a=a.split("."),c=a.pop(),e=this.data,f=0,g=a.length;g>f;f++){if(d=a[f],b&&null==e[d])return!1;null==e[d]&&(e[d]={}),e=e.__get?e.__get(d):e[d]}return[e,c]}return[this.data,a]},c.prototype.__fillData=function(a,b){return null==b&&(b=!0),this.data=this.__applyBeforeLoads(a),b&&this.trigger("changed"),null},c.prototype.toString=function(){return"Hash: "+JSON.stringify(this.data)},c}(Joosy.Module),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/hash",function(){return Joosy.Resources.Hash})}.call(this),function(){Joosy.Modules.Resources={}}.call(this),function(){Joosy.Modules.Resources.Model={included:function(){return this.primaryKey=function(a){return this.prototype.__primaryKey=a},this.collection=function(a){return this.prototype.__collection=a},this.entity=function(a){return this.prototype.__entityName=a},this.map=function(a,b){if(null==b&&(b=!1),b||(b=window[inflection.camelize(inflection.singularize(a))]),!b)throw new Error(""+Joosy.Module.__className(this)+"> class can not be detected for '"+a+"' mapping");return this.beforeLoad(function(c){var d;return null==b.build&&(b=b()),c[a]instanceof Array?(d=c[a].map(function(a){return b.build(a)}),c[a]=function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(b.prototype.__collection,d,function(){})):c[a]&&(c[a]=b.build(c[a])),c})},this.grab=function(a){return this.build({}).grab(a)},this.attrAccessor=function(){var a,b,c,d,e=this;for(d=[],b=0,c=arguments.length;c>b;b++)a=arguments[b],d.push(function(a){return e.prototype[a]=function(b){return b?this.set(a,b):this.get(a)}}(a));return d}},__primaryKey:"id",__collection:Joosy.Resources.Array,id:function(){var a;return null!=(a=this.data)?a[this.__primaryKey]:void 0},knownAttributes:function(){return Object.keys(this.data)},load:function(a,b){return null==b&&(b=!1),b&&(this.data={}),this.__fillData(a),this},__fillData:function(a,b){return null==b&&(b=!0),this.raw=a,this.hasOwnProperty("data")||(this.data={}),Joosy.Module.merge(this.data,this.__applyBeforeLoads(a)),b&&this.trigger("changed"),null},grab:function(a){var b,c,d,e,f;for(b={},f=$(a).serializeArray(),d=0,e=f.length;e>d;d++)c=f[d],b[c.name]?(b[c.name]instanceof Array||(b[c.name]=[b[c.name]]),b[c.name].push(c.value)):b[c.name]=c.value;return this.load(b)},toString:function(){return"<Resource "+this.__entityName+"> "+JSON.stringify(this.data)}}}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},d=[].slice;Joosy.Resources.REST=function(b){function e(){return a=e.__super__.constructor.apply(this,arguments)}return c(e,b),e.include(Joosy.Modules.Resources.Model),e.registerPlainFilters("beforeSave"),e.beforeLoad(function(a){var b;return a.constructor===Object&&1===Object.keys(a).length&&this.__entityName&&(b=inflection.camelize(this.__entityName,!0),a[b]&&(a=a[b])),a}),e.requestOptions=function(a){return this.prototype.__requestOptions=a},e.source=function(a){return this.__source=a},e.__atWrapper=function(){var a,b,c=this;return b=arguments[0],a=2<=arguments.length?d.call(arguments,1):[],1===a.length&&a[0]instanceof Array?this.__atWrapper.apply(this,[b].concat(d.call(a[0]))):b(function(b){return b.__source=a.reduce(function(a,b){return a+=Joosy.Module.hasAncestor(b.constructor,Joosy.Resources.REST)?b.memberPath():b.replace(/^\/?/,"/")},""),b.__source+="/"+inflection.pluralize(c.prototype.__entityName)})},e.at=function(){var a=this;return this.__atWrapper.apply(this,[function(b){var d,e;return d=function(a){function d(){return e=d.__super__.constructor.apply(this,arguments)}return c(d,a),b(d),d}(a)}].concat(d.call(arguments)))},e.prototype.at=function(){var a,b;return a=1<=arguments.length?d.call(arguments,0):[],new((b=this.constructor).at.apply(b,a))(this.data)},e.prototype.__interpolatePath=function(a,b){return b instanceof Array||(b=[b]),b.reduce(function(a,b){return b instanceof Joosy.Resources.REST&&(b=b.id()),a.replace(/:[^\/]+/,b)},a)},e.collectionPath=function(){var a,b;return a=1<=arguments.length?d.call(arguments,0):[],(b=this.prototype).collectionPath.apply(b,a)},e.prototype.collectionPath=function(a,b){var c,d;return null==a&&(a=[]),null==b&&(b={}),a.constructor===Object&&(b=a,a=[]),b.url?b.url:(d=this.__source||this.constructor.__source,d?c=this.__interpolatePath(d,a):(c="/",this.constructor.__namespace__.length>0&&(c+=this.constructor.__namespace__.map(String.prototype.underscore).join("/")+"/"),c+=inflection.pluralize(this.__entityName)),b.action&&(c+="/"+b.action),c)},e.memberPath=function(){var a,b;return a=1<=arguments.length?d.call(arguments,0):[],(b=this.prototype).memberPath.apply(b,a)},e.prototype.memberPath=function(a,b){var c,d,e;return null==a&&(a=[]),null==b&&(b={}),a.constructor===Object&&(b=a,a=[]),b.url?b.url:(a instanceof Array||(a=[a]),d=this.id()||a.pop(),c=b.action,a.push(this.id()),e=this.collectionPath(a,Joosy.Module.merge(b,{action:void 0}))+("/"+d),null!=c&&(e+="/"+c),e)},e.send=function(a,b,c){var d;return d=this.prototype.__extractOptionsAndCallback(b,c),b=d[0],c=d[1],this.__query(this.collectionPath(b),a.toUpperCase(),b.params,c)},e.prototype.send=function(a,b,c){var d;return d=this.__extractOptionsAndCallback(b,c),b=d[0],c=d[1],this.constructor.__query(this.memberPath(b),a.toUpperCase(),b.params,c)},e.prototype.reload=function(a,b){var c,d=this;return null==a&&(a={}),null==b&&(b=!1),c=this.__extractOptionsAndCallback(a,b),a=c[0],b=c[1],this.constructor.__query(this.memberPath(a),"GET",a.params,function(a,c,e){return null!=c&&d.load(c),"function"==typeof b?b(a,d,c,e):void 0})},e.find=function(a,b,c){var d,e;return null==b&&(b={}),null==c&&(c=!1),e=this.prototype.__extractOptionsAndCallback(b,c),b=e[0],c=e[1],d={},d[this.prototype.__primaryKey]=a instanceof Array?a[a.length-1]:a,d=this.build(d),a instanceof Array&&a.length>1&&(d.__source=this.collectionPath(a)),this.__query(this.memberPath(a,b),"GET",b.params,function(a,b,e){return null!=b&&d.load(b),"function"==typeof c?c(a,d,b,e):void 0}),d},e.all=function(a,b,c){var d,e,f,g=this;return null==b&&(b={}),null==c&&(c=!1),"function"==typeof a||a.constructor===Object?(e=this.prototype.__extractOptionsAndCallback(a,b),b=e[0],c=e[1],a=[]):(f=this.prototype.__extractOptionsAndCallback(b,c),b=f[0],c=f[1]),d=new this.prototype.__collection,this.__query(this.collectionPath(a,b),"GET",b.params,function(b,e,f){var h;if(null!=(h=e)){if(h.constructor===Object&&!(h=h[inflection.pluralize(g.prototype.__entityName)]))throw new Error("Invalid data for `all` received: "+JSON.stringify(h));h=h.map(function(b){var c;return c=g.build(b),a.length>1&&(c.__source=g.collectionPath(a)),c}),d.load.apply(d,h)}return"function"==typeof c?c(b,d,e,f):void 0}),d},e.prototype.update=function(a){var b=this;return this.send("put",{params:this.__applyBeforeSaves(this.data)},function(c,d){return c||b.load(d),"function"==typeof a?a(c,b):void 0})},e.prototype.create=function(a){var b=this;return this.constructor.send("post",{params:this.__applyBeforeSaves(this.data)},function(c,d){return c||b.load(d),"function"==typeof a?a(c,b):void 0})},e.prototype.save=function(a){return this.id()?this.update(a):this.create(a)},e.__query=function(a,b,c,d){var e;return e={url:a,data:c,type:b,cache:!1,dataType:"json"},"function"==typeof d?(e.success=function(a,b,c){return d(!1,a,c)},e.error=function(a){return d(a)}):Joosy.Module.merge(e,d),this.prototype.__requestOptions instanceof Function?this.prototype.__requestOptions(e):this.prototype.__requestOptions&&Joosy.Module.merge(e,this.prototype.__requestOptions),$.ajax(e)},e.prototype.__extractOptionsAndCallback=function(a,b){return"function"==typeof a&&(b=a,a={}),[a,b]},e}(Joosy.Resources.Hash),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/rest",function(){return Joosy.Resources.REST})}.call(this),function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b};Joosy.Resources.Scalar=function(a){function c(a){this.load(a)}return b(c,a),c.include(Joosy.Modules.Events),c.include(Joosy.Modules.Filters),c.registerPlainFilters("beforeLoad"),c.build=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})},c.prototype.__call=function(){return arguments.length>0?this.set(arguments[0]):this.get()},c.prototype.load=function(a){return this.value=this.__applyBeforeLoads(a),this.trigger("changed"),this.value},c.prototype.get=function(){return this.value},c.prototype.set=function(a){return this.value=a,this.trigger("changed")},c.prototype.valueOf=function(){return this.value.valueOf()},c.prototype.toString=function(){return this.value.toString()},c}(Joosy.Module),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/scalar",function(){return Joosy.Resources.Scalar})}.call(this),function(){var a=[].slice;Joosy.Modules.Resources.Cacher={included:function(){return this.cache=function(a){return this.prototype.__cacheKey=a},this.fetcher=function(a){return this.prototype.__fetcher=a},this.cached=function(a,b,c){var d,e=this;return null==b&&(b=!1),null==c&&(c=!1),"function"==typeof b&&(c=b,b=void 0),b||(b=this.prototype.__cacheKey),c||(c=this.prototype.__fetcher),b&&localStorage&&localStorage[b]?(d=this.build.apply(this,JSON.parse(localStorage[b])),"function"==typeof a&&a(d),d.refresh()):this.fetch(function(b){return d=e.build.apply(e,b),"function"==typeof a?a(d):void 0})},this.fetch=function(b){var c=this;return this.prototype.__fetcher(function(){var d;return d=1<=arguments.length?a.call(arguments,0):[],c.prototype.__cacheKey&&localStorage&&(localStorage[c.prototype.__cacheKey]=JSON.stringify(d)),b(d)})}},refresh:function(a){var b=this;return this.constructor.fetch(function(c){return b.load.apply(b,c),"function"==typeof a?a(b):void 0})}},null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/modules/resources/cacher",function(){return Joosy.Modules.Resources.Cacher})}.call(this),function(){Joosy.Modules.Resources.Function={extended:function(){return this.build?this.aliasStaticMethodChain("build","function"):(this.build=this.buildWithFunction,this.buildWithoutFunction=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})})},buildWithFunction:function(){var a,b,c,d;if(c=function(){return c.__call.apply(c,arguments)},b=this.buildWithoutFunction.apply(this,arguments),c.__proto__)c.__proto__=b;else for(a in b)d=b[a],c[a]=d;return c.constructor=b.constructor,c}}}.call(this),function(){Joosy.Modules.Resources.IdentityMap={extended:function(){return this.prototype.__identityHolder=this,this.aliasStaticMethodChain("build","identityMap")},identityReset:function(){return this.prototype.__identityHolder.identity={}},identityPath:function(a){return[this.prototype.__entityName,"s"+(this.__source||""),a[this.prototype.__primaryKey]]},buildWithIdentityMap:function(a){var b,c,d,e,f,g,h,i;if(null==a&&(a={}),d=this.identityPath(a),0===d.filter(function(a){return null==a}).length){for(e=null!=(g=this.prototype.__identityHolder).identity?(g=this.prototype.__identityHolder).identity:g.identity={},b=d.pop(),h=0,i=d.length;i>h;h++)c=d[h],e=null!=e[c]?e[c]:e[c]={};return f={},f[this.prototype.__primaryKey]=a[this.prototype.__primaryKey],null==e[b]&&(e[b]=this.buildWithoutIdentityMap(f)),e[b].load(a)}return this.buildWithoutIdentityMap(a)}}}.call(this),function(){}.call(this);
1
+ (function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b};Joosy.Resources.Array=function(a){function c(){this.__fillData(arguments,!1)}return b(c,a),Joosy.Module.merge(c,Joosy.Module),c.include(Joosy.Modules.Events),c.include(Joosy.Modules.Filters),c.registerPlainFilters("beforeLoad"),c.build=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})},c.prototype.load=function(){return this.__fillData(arguments)},c.prototype.get=function(a){return this[a]},c.prototype.set=function(a,b){return this[a]=b,this.trigger("changed"),b},c.prototype.push=function(){var a;return a=c.__super__.push.apply(this,arguments),this.trigger("changed"),a},c.prototype.pop=function(){var a;return a=c.__super__.pop.apply(this,arguments),this.trigger("changed"),a},c.prototype.shift=function(){var a;return a=c.__super__.shift.apply(this,arguments),this.trigger("changed"),a},c.prototype.unshift=function(){var a;return a=c.__super__.unshift.apply(this,arguments),this.trigger("changed"),a},c.prototype.splice=function(){var a;return a=c.__super__.splice.apply(this,arguments),this.trigger("changed"),a},c.prototype.__fillData=function(a,b){var c,d,e,f;for(null==b&&(b=!0),a=this.slice.call(a,0),this.length>0&&this.splice(0,this.length),f=this.__applyBeforeLoads(a),d=0,e=f.length;e>d;d++)c=f[d],this.push(c);return b&&this.trigger("changed"),null},c}(Array),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/array",function(){return Joosy.Resources.Array})}).call(this),function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b};Joosy.Resources.Hash=function(a){function c(a){null==a&&(a={}),this.__fillData(a,!1)}return b(c,a),c.include(Joosy.Modules.Events),c.include(Joosy.Modules.Filters),c.registerPlainFilters("beforeLoad"),c.build=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})},c.prototype.__call=function(a,b){return arguments.length>1?this.set(a,b):this.get(a)},c.prototype.load=function(a){return this.__fillData(a),this},c.prototype.get=function(a){var b,c,d;return d=this.__callTarget(a,!0),b=d[0],c=d[1],b?b.get?b.get(c):b[c]:void 0},c.prototype.set=function(a,b){var c,d,e;return e=this.__callTarget(a),c=e[0],d=e[1],null!=c.set?c.set(d,b):c[d]=b,this.trigger("changed"),b},c.prototype.__callTarget=function(a,b){var c,d,e,f,g;if(null==b&&(b=!1),-1!==a.indexOf(".")&&null==this.data[a]){for(a=a.split("."),c=a.pop(),e=this.data,f=0,g=a.length;g>f;f++){if(d=a[f],b&&null==e[d])return!1;null==e[d]&&(e[d]={}),e=e.__get?e.__get(d):e[d]}return[e,c]}return[this.data,a]},c.prototype.__fillData=function(a,b){return null==b&&(b=!0),this.data=this.__applyBeforeLoads(a),b&&this.trigger("changed"),null},c.prototype.toString=function(){return"Hash: "+JSON.stringify(this.data)},c}(Joosy.Module),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/hash",function(){return Joosy.Resources.Hash})}.call(this),function(){Joosy.Modules.Resources={}}.call(this),function(){Joosy.Modules.Resources.Model={included:function(){return this.primaryKey=function(a){return this.prototype.__primaryKey=a},this.collection=function(a){return this.prototype.__collection=a},this.entity=function(a){return this.prototype.__entityName=a},this.map=function(a,b){if(null==b&&(b=!1),b||(b=window[inflection.camelize(inflection.singularize(a))]),!b)throw new Error(""+Joosy.Module.__className(this)+"> class can not be detected for '"+a+"' mapping");return this.beforeLoad(function(c){var d;return null==b.build&&(b=b()),c[a]instanceof Array?(d=c[a].map(function(a){return b.build(a)}),c[a]=function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(b.prototype.__collection,d,function(){})):c[a]&&(c[a]=b.build(c[a])),c})},this.grab=function(a){return this.build({}).grab(a)},this.attrAccessor=function(){var a,b,c,d,e=this;for(d=[],b=0,c=arguments.length;c>b;b++)a=arguments[b],d.push(function(a){return e.prototype[a]=function(b){return null!=b?this.set(a,b):this.get(a)}}(a));return d}},__primaryKey:"id",__collection:Joosy.Resources.Array,id:function(){var a;return null!=(a=this.data)?a[this.__primaryKey]:void 0},knownAttributes:function(){return Object.keys(this.data)},load:function(a,b){return null==b&&(b=!1),b&&(this.data={}),this.__fillData(a),this},__fillData:function(a,b){return null==b&&(b=!0),this.raw=a,this.hasOwnProperty("data")||(this.data={}),Joosy.Module.merge(this.data,this.__applyBeforeLoads(a)),b&&this.trigger("changed"),null},grab:function(a){var b,c,d,e,f;for(b={},f=$(a).serializeArray(),d=0,e=f.length;e>d;d++)c=f[d],b[c.name]?(b[c.name]instanceof Array||(b[c.name]=[b[c.name]]),b[c.name].push(c.value)):b[c.name]=c.value;return this.load(b)},toString:function(){return"<Resource "+this.__entityName+"> "+JSON.stringify(this.data)}}}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},d=[].slice;Joosy.Resources.REST=function(b){function e(){return a=e.__super__.constructor.apply(this,arguments)}return c(e,b),e.include(Joosy.Modules.Resources.Model),e.registerPlainFilters("beforeSave"),e.beforeLoad(function(a){var b;return a.constructor===Object&&1===Object.keys(a).length&&this.__entityName&&(b=inflection.camelize(this.__entityName,!0),a[b]&&(a=a[b])),a}),e.requestOptions=function(a){return this.prototype.__requestOptions=a},e.source=function(a){return this.__source=a},e.__atWrapper=function(){var a,b,c=this;return b=arguments[0],a=2<=arguments.length?d.call(arguments,1):[],1===a.length&&a[0]instanceof Array?this.__atWrapper.apply(this,[b].concat(d.call(a[0]))):b(function(b){return b.__source=a.reduce(function(a,b){return a+=Joosy.Module.hasAncestor(b.constructor,Joosy.Resources.REST)?b.memberPath():b.replace(/^\/?/,"/")},""),b.__source+="/"+inflection.pluralize(c.prototype.__entityName)})},e.at=function(){var a=this;return this.__atWrapper.apply(this,[function(b){var d,e;return d=function(a){function d(){return e=d.__super__.constructor.apply(this,arguments)}return c(d,a),b(d),d}(a)}].concat(d.call(arguments)))},e.prototype.at=function(){var a,b;return a=1<=arguments.length?d.call(arguments,0):[],new((b=this.constructor).at.apply(b,a))(this.data)},e.prototype.__interpolatePath=function(a,b){return b instanceof Array||(b=[b]),b.reduce(function(a,b){return b instanceof Joosy.Resources.REST&&(b=b.id()),a.replace(/:[^\/]+/,b)},a)},e.collectionPath=function(){var a,b;return a=1<=arguments.length?d.call(arguments,0):[],(b=this.prototype).collectionPath.apply(b,a)},e.prototype.collectionPath=function(a,b){var c,d,e;return null==a&&(a=[]),null==b&&(b={}),a.constructor===Object&&(b=a,a=[]),b.url?b.url:(e=this.__source||this.constructor.__source,e?d=this.__interpolatePath(e,a):(d="/",this.constructor.__namespace__.length>0&&(c=this.constructor.__namespace__.map(function(a){return inflection.underscore(a)}),d+=c.join("/")+"/"),d+=inflection.pluralize(this.__entityName)),b.action&&(d+="/"+b.action),d)},e.memberPath=function(){var a,b;return a=1<=arguments.length?d.call(arguments,0):[],(b=this.prototype).memberPath.apply(b,a)},e.prototype.memberPath=function(a,b){var c,d,e;return null==a&&(a=[]),null==b&&(b={}),a.constructor===Object&&(b=a,a=[]),b.url?b.url:(a instanceof Array||(a=[a]),d=this.id()||a.pop(),c=b.action,a.push(this.id()),e=this.collectionPath(a,Joosy.Module.merge(b,{action:void 0}))+("/"+d),null!=c&&(e+="/"+c),e)},e.send=function(a,b,c){var d;return d=this.prototype.__extractOptionsAndCallback(b,c),b=d[0],c=d[1],this.__query(this.collectionPath(b),a.toUpperCase(),b.params,c)},e.prototype.send=function(a,b,c){var d;return d=this.__extractOptionsAndCallback(b,c),b=d[0],c=d[1],this.constructor.__query(this.memberPath(b),a.toUpperCase(),b.params,c)},e.prototype.reload=function(a,b){var c,d=this;return null==a&&(a={}),null==b&&(b=!1),c=this.__extractOptionsAndCallback(a,b),a=c[0],b=c[1],this.constructor.__query(this.memberPath(a),"GET",a.params,function(a,c,e){return null!=c&&d.load(c),"function"==typeof b?b(a,d,c,e):void 0})},e.find=function(a,b,c){var d,e;return null==b&&(b={}),null==c&&(c=!1),e=this.prototype.__extractOptionsAndCallback(b,c),b=e[0],c=e[1],d={},d[this.prototype.__primaryKey]=a instanceof Array?a[a.length-1]:a,d=this.build(d),a instanceof Array&&a.length>1&&(d.__source=this.collectionPath(a)),this.__query(this.memberPath(a,b),"GET",b.params,function(a,b,e){return null!=b&&d.load(b),"function"==typeof c?c(a,d,b,e):void 0}),d},e.all=function(a,b,c){var d,e,f,g=this;return null==b&&(b={}),null==c&&(c=!1),"function"==typeof a||a.constructor===Object?(e=this.prototype.__extractOptionsAndCallback(a,b),b=e[0],c=e[1],a=[]):(f=this.prototype.__extractOptionsAndCallback(b,c),b=f[0],c=f[1]),d=new this.prototype.__collection,this.__query(this.collectionPath(a,b),"GET",b.params,function(b,e,f){var h;if(null!=(h=e)){if(h.constructor===Object&&!(h=h[inflection.pluralize(g.prototype.__entityName)]))throw new Error("Invalid data for `all` received: "+JSON.stringify(h));h=h.map(function(b){var c;return c=g.build(b),a.length>1&&(c.__source=g.collectionPath(a)),c}),d.load.apply(d,h)}return"function"==typeof c?c(b,d,e,f):void 0}),d},e.prototype.update=function(a){var b=this;return this.send("put",{params:this.__applyBeforeSaves(this.data)},function(c,d){return c||b.load(d),"function"==typeof a?a(c,b):void 0})},e.prototype.create=function(a){var b=this;return this.constructor.send("post",{params:this.__applyBeforeSaves(this.data)},function(c,d){return c||b.load(d),"function"==typeof a?a(c,b):void 0})},e.prototype.save=function(a){return this.id()?this.update(a):this.create(a)},e.__query=function(a,b,c,d){var e;return e={url:a,data:c,type:b,cache:!1,dataType:"json"},"function"==typeof d?(e.success=function(a,b,c){return d(!1,a,c)},e.error=function(a){return d(a)}):Joosy.Module.merge(e,d),this.prototype.__requestOptions instanceof Function?this.prototype.__requestOptions(e):this.prototype.__requestOptions&&Joosy.Module.merge(e,this.prototype.__requestOptions),$.ajax(e)},e.prototype.__extractOptionsAndCallback=function(a,b){return"function"==typeof a&&(b=a,a={}),[a,b]},e}(Joosy.Resources.Hash),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/rest",function(){return Joosy.Resources.REST})}.call(this),function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b};Joosy.Resources.Scalar=function(a){function c(a){this.load(a)}return b(c,a),c.include(Joosy.Modules.Events),c.include(Joosy.Modules.Filters),c.registerPlainFilters("beforeLoad"),c.build=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})},c.prototype.__call=function(){return arguments.length>0?this.set(arguments[0]):this.get()},c.prototype.load=function(a){return this.value=this.__applyBeforeLoads(a),this.trigger("changed"),this.value},c.prototype.get=function(){return this.value},c.prototype.set=function(a){return this.value=a,this.trigger("changed")},c.prototype.valueOf=function(){return this.value.valueOf()},c.prototype.toString=function(){return this.value.toString()},c}(Joosy.Module),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/scalar",function(){return Joosy.Resources.Scalar})}.call(this),function(){var a=[].slice;Joosy.Modules.Resources.Cacher={included:function(){return this.cache=function(a){return this.prototype.__cacheKey=a},this.fetcher=function(a){return this.prototype.__fetcher=a},this.cached=function(a,b,c){var d,e=this;return null==b&&(b=!1),null==c&&(c=!1),"function"==typeof b&&(c=b,b=void 0),b||(b=this.prototype.__cacheKey),c||(c=this.prototype.__fetcher),b&&localStorage&&localStorage[b]?(d=this.build.apply(this,JSON.parse(localStorage[b])),"function"==typeof a&&a(d),d.refresh()):this.fetch(function(b){return d=e.build.apply(e,b),"function"==typeof a?a(d):void 0})},this.fetch=function(b){var c=this;return this.prototype.__fetcher(function(){var d;return d=1<=arguments.length?a.call(arguments,0):[],c.prototype.__cacheKey&&localStorage&&(localStorage[c.prototype.__cacheKey]=JSON.stringify(d)),b(d)})}},refresh:function(a){var b=this;return this.constructor.fetch(function(c){return b.load.apply(b,c),"function"==typeof a?a(b):void 0})}},null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/modules/resources/cacher",function(){return Joosy.Modules.Resources.Cacher})}.call(this),function(){Joosy.Modules.Resources.Function={extended:function(){return this.build?this.aliasStaticMethodChain("build","function"):(this.build=this.buildWithFunction,this.buildWithoutFunction=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})})},buildWithFunction:function(){var a,b,c,d;if(c=function(){return c.__call.apply(c,arguments)},b=this.buildWithoutFunction.apply(this,arguments),c.__proto__)c.__proto__=b;else for(a in b)d=b[a],c[a]=d;return c.constructor=b.constructor,c}}}.call(this),function(){Joosy.Modules.Resources.IdentityMap={extended:function(){return this.prototype.__identityHolder=this,this.aliasStaticMethodChain("build","identityMap")},identityReset:function(){return this.prototype.__identityHolder.identity={}},identityPath:function(a){return[this.prototype.__entityName,"s"+(this.__source||""),a[this.prototype.__primaryKey]]},buildWithIdentityMap:function(a){var b,c,d,e,f,g,h,i;if(null==a&&(a={}),d=this.identityPath(a),0===d.filter(function(a){return null==a}).length){for(e=null!=(g=this.prototype.__identityHolder).identity?(g=this.prototype.__identityHolder).identity:g.identity={},b=d.pop(),h=0,i=d.length;i>h;h++)c=d[h],e=null!=e[c]?e[c]:e[c]={};return f={},f[this.prototype.__primaryKey]=a[this.prototype.__primaryKey],null==e[b]&&(e[b]=this.buildWithoutIdentityMap(f)),e[b].load(a)}return this.buildWithoutIdentityMap(a)}}}.call(this),function(){}.call(this);
data/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "joosy"
6
6
  ],
7
- "version": "1.2.0-beta.2",
7
+ "version": "1.2.0-beta.3",
8
8
  "author": "Boris Staal <boris@staal.io>",
9
9
  "homepage": "http://joosy.ws/",
10
10
  "repository": {
@@ -1,5 +1,6 @@
1
1
  #= require ../resources
2
2
 
3
+ # @mixin
3
4
  Joosy.Modules.Resources.Cacher =
4
5
 
5
6
  included: ->
@@ -1,5 +1,6 @@
1
1
  #= require ../resources
2
2
 
3
+ # @mixin
3
4
  Joosy.Modules.Resources.IdentityMap =
4
5
 
5
6
  extended: ->
@@ -1,5 +1,6 @@
1
1
  #= require ../resources
2
2
 
3
+ # @mixin
3
4
  Joosy.Modules.Resources.Model =
4
5
 
5
6
  included: ->
@@ -83,7 +84,7 @@ Joosy.Modules.Resources.Model =
83
84
  for attribute in arguments
84
85
  do (attribute) =>
85
86
  @::[attribute] = (value) ->
86
- if value
87
+ if value?
87
88
  @set attribute, value
88
89
  else
89
90
  @get attribute
@@ -124,7 +124,11 @@ class Joosy.Resources.REST extends Joosy.Resources.Hash
124
124
  path = @__interpolatePath source, ids
125
125
  else
126
126
  path = '/'
127
- path += @constructor.__namespace__.map(String::underscore).join('/') + '/' if @constructor.__namespace__.length > 0
127
+
128
+ if @constructor.__namespace__.length > 0
129
+ namespace = @constructor.__namespace__.map (x) -> inflection.underscore(x)
130
+ path += namespace.join('/') + '/'
131
+
128
132
  path += inflection.pluralize(@__entityName)
129
133
 
130
134
  path += "/#{options.action}" if options.action
@@ -14,6 +14,10 @@ describe "Joosy.Resources.REST", ->
14
14
  @entity 'test'
15
15
  @source '/grand_parents/:grand_parent_id/parents/:parent_id/tests'
16
16
 
17
+ Joosy.namespace 'Deeply.Nested', ->
18
+ class @Entity extends Joosy.Resources.REST
19
+ @entity 'entity'
20
+
17
21
  Joosy.namespace 'Animal', ->
18
22
  class @Cat extends Joosy.Resources.REST
19
23
  @entity 'cat'
@@ -120,6 +124,9 @@ describe "Joosy.Resources.REST", ->
120
124
  it 'builds collection path', ->
121
125
  expect(Interpolated.collectionPath([1,2])).toEqual '/grand_parents/1/parents/2/tests'
122
126
 
127
+ describe 'with namespace', ->
128
+ it 'builds collection path', ->
129
+ expect(Deeply.Nested.Entity.collectionPath([1,2])).toEqual '/deeply/nested/entities'
123
130
 
124
131
  describe '@find(:id)', ->
125
132
  rawData = '{"fluffy": {"id": 1, "name": "test1"}}'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joosy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.beta.2
4
+ version: 1.2.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-10 00:00:00.000000000 Z
13
+ date: 2013-10-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sprockets
@@ -178,3 +178,4 @@ signing_key:
178
178
  specification_version: 4
179
179
  summary: Joosy Framework
180
180
  test_files: []
181
+ has_rdoc: