wingman_rails 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/vendor/assets/javascripts/wingman.js +264 -208
  2. metadata +4 -4
@@ -64,6 +64,8 @@
64
64
 
65
65
  exports.View = require('./wingman/view');
66
66
 
67
+ exports.Store = require('./wingman/store');
68
+
67
69
  exports.Model = require('./wingman/model');
68
70
 
69
71
  exports.Controller = require('./wingman/controller');
@@ -74,6 +76,10 @@
74
76
 
75
77
  exports.Events = require('./wingman/shared/events');
76
78
 
79
+ exports.store = function() {
80
+ return this._store || (this._store = new exports.Store);
81
+ };
82
+
77
83
  }).call(this);
78
84
  }, "wingman/application": function(exports, require, module) {(function() {
79
85
  var Application, Events, Fleck, Navigator, Wingman, WingmanObject,
@@ -245,7 +251,7 @@
245
251
 
246
252
  }).call(this);
247
253
  }, "wingman/model": function(exports, require, module) {(function() {
248
- var Fleck, HasManyAssociation, Model, Scope, StorageAdapter, Store, Wingman, WingmanObject,
254
+ var Fleck, HasManyAssociation, Model, StorageAdapter, Wingman, WingmanObject,
249
255
  __hasProp = Object.prototype.hasOwnProperty,
250
256
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; },
251
257
  __slice = Array.prototype.slice;
@@ -256,10 +262,6 @@
256
262
 
257
263
  StorageAdapter = require('./model/storage_adapter');
258
264
 
259
- Store = require('./model/store');
260
-
261
- Scope = require('./model/scope');
262
-
263
265
  HasManyAssociation = require('./model/has_many_association');
264
266
 
265
267
  Fleck = require('fleck');
@@ -270,12 +272,12 @@
270
272
 
271
273
  Model.extend(StorageAdapter);
272
274
 
273
- Model.store = function() {
274
- return this._store || (this._store = new Store);
275
+ Model.collection = function() {
276
+ return Wingman.store().collection(this);
275
277
  };
276
278
 
277
279
  Model.count = function() {
278
- return this.store().count();
280
+ return this.collection().count();
279
281
  };
280
282
 
281
283
  Model.load = function() {
@@ -320,11 +322,11 @@
320
322
  };
321
323
 
322
324
  Model.scoped = function(params) {
323
- return new Scope(this.store(), params);
325
+ return this.collection().scoped(params);
324
326
  };
325
327
 
326
328
  Model.find = function(id) {
327
- return this.store().find(id);
329
+ return this.collection().find(id);
328
330
  };
329
331
 
330
332
  function Model(properties, options) {
@@ -333,7 +335,7 @@
333
335
  this.dirtyStaticPropertyNames = [];
334
336
  if (this.constructor.hasManyNames) this.setupHasManyAssociations();
335
337
  this.observeOnce('id', function() {
336
- return _this.constructor.store().add(_this);
338
+ return _this.constructor.collection().add(_this);
337
339
  });
338
340
  this.set(properties);
339
341
  }
@@ -555,119 +557,6 @@
555
557
 
556
558
  })(Module);
557
559
 
558
- }).call(this);
559
- }, "wingman/model/scope": function(exports, require, module) {(function() {
560
- var Events, Module, Scope,
561
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
562
- __hasProp = Object.prototype.hasOwnProperty,
563
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
564
-
565
- Module = require('./../shared/module');
566
-
567
- Events = require('./../shared/events');
568
-
569
- module.exports = Scope = (function(_super) {
570
-
571
- __extends(Scope, _super);
572
-
573
- Scope.include(Events);
574
-
575
- function Scope(store, params) {
576
- var _this = this;
577
- this.params = params;
578
- this.remove = __bind(this.remove, this);
579
- this.check = __bind(this.check, this);
580
- this.listen = __bind(this.listen, this);
581
- this.models = {};
582
- store.forEach(function(model) {
583
- return _this.check(model);
584
- });
585
- store.bind('add', this.listen);
586
- }
587
-
588
- Scope.prototype.listen = function(model) {
589
- var key, _i, _len, _ref, _results,
590
- _this = this;
591
- this.check(model);
592
- _ref = Object.keys(this.params);
593
- _results = [];
594
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
595
- key = _ref[_i];
596
- _results.push(model.observe(key, function() {
597
- return _this.check(model);
598
- }));
599
- }
600
- return _results;
601
- };
602
-
603
- Scope.prototype.check = function(model) {
604
- if (this.shouldBeAdded(model)) {
605
- return this.add(model);
606
- } else if (this.shouldBeRemoved(model)) {
607
- return this.remove(model);
608
- }
609
- };
610
-
611
- Scope.prototype.shouldBeAdded = function(model) {
612
- return this.matches(model) && !this.exists(model);
613
- };
614
-
615
- Scope.prototype.shouldBeRemoved = function(model) {
616
- return !this.matches(model) && this.exists(model);
617
- };
618
-
619
- Scope.prototype.add = function(model) {
620
- if (!model.get('id')) throw new Error('Model must have ID to be stored.');
621
- if (this.exists(model)) {
622
- throw new Error("" + model.constructor.name + " model with ID " + (model.get('id')) + " already in scope.");
623
- }
624
- this.models[model.get('id')] = model;
625
- this.trigger('add', model);
626
- return model.bind('destroy', this.remove);
627
- };
628
-
629
- Scope.prototype.matches = function(model) {
630
- var _this = this;
631
- return Object.keys(this.params).every(function(key) {
632
- return model.get(key) === _this.params[key];
633
- });
634
- };
635
-
636
- Scope.prototype.count = function() {
637
- return Object.keys(this.models).length;
638
- };
639
-
640
- Scope.prototype.find = function(id) {
641
- return this.models[id] || (function() {
642
- throw new Error('Model not found in scope.');
643
- })();
644
- };
645
-
646
- Scope.prototype.remove = function(model) {
647
- delete this.models[model.get('id')];
648
- model.unbind('destroy', this.remove);
649
- return this.trigger('remove', model);
650
- };
651
-
652
- Scope.prototype.exists = function(model) {
653
- return !!this.models[model.get('id')];
654
- };
655
-
656
- Scope.prototype.forEach = function(callback) {
657
- var key, value, _ref, _results;
658
- _ref = this.models;
659
- _results = [];
660
- for (key in _ref) {
661
- value = _ref[key];
662
- _results.push(callback(value));
663
- }
664
- return _results;
665
- };
666
-
667
- return Scope;
668
-
669
- })(Module);
670
-
671
560
  }).call(this);
672
561
  }, "wingman/model/storage_adapter": function(exports, require, module) {(function() {
673
562
  var LocalStorage, RestStorage;
@@ -764,6 +653,10 @@
764
653
  return Math.round(Math.random() * 5000000);
765
654
  };
766
655
 
656
+ _Class.prototype["delete"] = function(id) {
657
+ return Wingman.localStorage.removeItem(this.key(id));
658
+ };
659
+
767
660
  return _Class;
768
661
 
769
662
  })();
@@ -828,90 +721,6 @@
828
721
 
829
722
  })();
830
723
 
831
- }).call(this);
832
- }, "wingman/model/store": function(exports, require, module) {(function() {
833
- var Events, Module, Store,
834
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
835
- __hasProp = Object.prototype.hasOwnProperty,
836
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
837
-
838
- Module = require('./../shared/module');
839
-
840
- Events = require('./../shared/events');
841
-
842
- module.exports = Store = (function(_super) {
843
-
844
- __extends(Store, _super);
845
-
846
- Store.include(Events);
847
-
848
- function Store() {
849
- this.remove = __bind(this.remove, this); this.models = {};
850
- }
851
-
852
- Store.prototype.add = function(model) {
853
- if (!model.get('id')) throw new Error('Model must have ID to be stored.');
854
- if (this.exists(model)) {
855
- return this.update(this.models[model.get('id')], model);
856
- } else {
857
- return this.insert(model);
858
- }
859
- };
860
-
861
- Store.prototype.insert = function(model) {
862
- this.models[model.get('id')] = model;
863
- this.trigger('add', model);
864
- return model.bind('destroy', this.remove);
865
- };
866
-
867
- Store.prototype.update = function(model, model2) {
868
- var key, value, _ref, _results;
869
- _ref = model2.toJSON();
870
- _results = [];
871
- for (key in _ref) {
872
- value = _ref[key];
873
- if (key !== 'id') {
874
- _results.push(model.setProperty(key, value));
875
- } else {
876
- _results.push(void 0);
877
- }
878
- }
879
- return _results;
880
- };
881
-
882
- Store.prototype.find = function(id) {
883
- return this.models[id];
884
- };
885
-
886
- Store.prototype.count = function() {
887
- return Object.keys(this.models).length;
888
- };
889
-
890
- Store.prototype.remove = function(model) {
891
- delete this.models[model.get('id')];
892
- model.unbind(this.remove);
893
- return this.trigger('remove', model);
894
- };
895
-
896
- Store.prototype.exists = function(model) {
897
- return !!this.models[model.get('id')];
898
- };
899
-
900
- Store.prototype.forEach = function(callback) {
901
- var key, value, _ref, _results;
902
- _ref = this.models;
903
- _results = [];
904
- for (key in _ref) {
905
- value = _ref[key];
906
- _results.push(callback(value));
907
- }
908
- return _results;
909
- };
910
-
911
- return Store;
912
-
913
- })(Module);
914
-
915
724
  }).call(this);
916
725
  }, "wingman/request": function(exports, require, module) {(function() {
917
726
  var Wingman, request,
@@ -1374,6 +1183,253 @@
1374
1183
 
1375
1184
  module.exports = WingmanObject;
1376
1185
 
1186
+ }).call(this);
1187
+ }, "wingman/store": function(exports, require, module) {(function() {
1188
+ var Collection, Store;
1189
+
1190
+ Collection = require('./store/collection');
1191
+
1192
+ module.exports = Store = (function() {
1193
+
1194
+ function Store(options) {
1195
+ var _ref;
1196
+ this.options = options;
1197
+ this.collections = {};
1198
+ this.collectionClass = ((_ref = this.options) != null ? _ref.collectionClass : void 0) || Collection;
1199
+ }
1200
+
1201
+ Store.prototype.collection = function(klass) {
1202
+ return this.collections[klass] || this.createCollection(klass);
1203
+ };
1204
+
1205
+ Store.prototype.createCollection = function(klass) {
1206
+ return this.collections[klass] = new this.collectionClass(klass);
1207
+ };
1208
+
1209
+ Store.prototype.clear = function() {
1210
+ var collection, klass, _ref, _results;
1211
+ _ref = this.collections;
1212
+ _results = [];
1213
+ for (klass in _ref) {
1214
+ collection = _ref[klass];
1215
+ _results.push(collection.clear());
1216
+ }
1217
+ return _results;
1218
+ };
1219
+
1220
+ return Store;
1221
+
1222
+ })();
1223
+
1224
+ }).call(this);
1225
+ }, "wingman/store/collection": function(exports, require, module) {(function() {
1226
+ var Events, Module, Scope, Store,
1227
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
1228
+ __hasProp = Object.prototype.hasOwnProperty,
1229
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
1230
+
1231
+ Module = require('./../shared/module');
1232
+
1233
+ Events = require('./../shared/events');
1234
+
1235
+ Scope = require('./scope');
1236
+
1237
+ module.exports = Store = (function(_super) {
1238
+
1239
+ __extends(Store, _super);
1240
+
1241
+ Store.include(Events);
1242
+
1243
+ function Store() {
1244
+ this.remove = __bind(this.remove, this); this.models = {};
1245
+ }
1246
+
1247
+ Store.prototype.add = function(model) {
1248
+ if (!model.get('id')) throw new Error('Model must have ID to be stored.');
1249
+ if (this.exists(model)) {
1250
+ return this.update(this.models[model.get('id')], model);
1251
+ } else {
1252
+ return this.insert(model);
1253
+ }
1254
+ };
1255
+
1256
+ Store.prototype.insert = function(model) {
1257
+ this.models[model.get('id')] = model;
1258
+ this.trigger('add', model);
1259
+ return model.bind('destroy', this.remove);
1260
+ };
1261
+
1262
+ Store.prototype.update = function(model, model2) {
1263
+ var key, value, _ref, _results;
1264
+ _ref = model2.toJSON();
1265
+ _results = [];
1266
+ for (key in _ref) {
1267
+ value = _ref[key];
1268
+ if (key !== 'id') {
1269
+ _results.push(model.setProperty(key, value));
1270
+ } else {
1271
+ _results.push(void 0);
1272
+ }
1273
+ }
1274
+ return _results;
1275
+ };
1276
+
1277
+ Store.prototype.find = function(id) {
1278
+ return this.models[id];
1279
+ };
1280
+
1281
+ Store.prototype.count = function() {
1282
+ return Object.keys(this.models).length;
1283
+ };
1284
+
1285
+ Store.prototype.remove = function(model) {
1286
+ delete this.models[model.get('id')];
1287
+ model.unbind(this.remove);
1288
+ return this.trigger('remove', model);
1289
+ };
1290
+
1291
+ Store.prototype.exists = function(model) {
1292
+ return !!this.models[model.get('id')];
1293
+ };
1294
+
1295
+ Store.prototype.forEach = function(callback) {
1296
+ var key, value, _ref, _results;
1297
+ _ref = this.models;
1298
+ _results = [];
1299
+ for (key in _ref) {
1300
+ value = _ref[key];
1301
+ _results.push(callback(value));
1302
+ }
1303
+ return _results;
1304
+ };
1305
+
1306
+ Store.prototype.scoped = function(params) {
1307
+ return new Scope(this, params);
1308
+ };
1309
+
1310
+ Store.prototype.clear = function() {
1311
+ return this.forEach(function(model) {
1312
+ return model.destroy();
1313
+ });
1314
+ };
1315
+
1316
+ return Store;
1317
+
1318
+ })(Module);
1319
+
1320
+ }).call(this);
1321
+ }, "wingman/store/scope": function(exports, require, module) {(function() {
1322
+ var Events, Module, Scope,
1323
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
1324
+ __hasProp = Object.prototype.hasOwnProperty,
1325
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
1326
+
1327
+ Module = require('./../shared/module');
1328
+
1329
+ Events = require('./../shared/events');
1330
+
1331
+ module.exports = Scope = (function(_super) {
1332
+
1333
+ __extends(Scope, _super);
1334
+
1335
+ Scope.include(Events);
1336
+
1337
+ function Scope(collection, params) {
1338
+ var _this = this;
1339
+ this.params = params;
1340
+ this.remove = __bind(this.remove, this);
1341
+ this.check = __bind(this.check, this);
1342
+ this.listen = __bind(this.listen, this);
1343
+ this.models = {};
1344
+ collection.forEach(function(model) {
1345
+ return _this.check(model);
1346
+ });
1347
+ collection.bind('add', this.listen);
1348
+ }
1349
+
1350
+ Scope.prototype.listen = function(model) {
1351
+ var key, _i, _len, _ref, _results,
1352
+ _this = this;
1353
+ this.check(model);
1354
+ _ref = Object.keys(this.params);
1355
+ _results = [];
1356
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1357
+ key = _ref[_i];
1358
+ _results.push(model.observe(key, function() {
1359
+ return _this.check(model);
1360
+ }));
1361
+ }
1362
+ return _results;
1363
+ };
1364
+
1365
+ Scope.prototype.check = function(model) {
1366
+ if (this.shouldBeAdded(model)) {
1367
+ return this.add(model);
1368
+ } else if (this.shouldBeRemoved(model)) {
1369
+ return this.remove(model);
1370
+ }
1371
+ };
1372
+
1373
+ Scope.prototype.shouldBeAdded = function(model) {
1374
+ return this.matches(model) && !this.exists(model);
1375
+ };
1376
+
1377
+ Scope.prototype.shouldBeRemoved = function(model) {
1378
+ return !this.matches(model) && this.exists(model);
1379
+ };
1380
+
1381
+ Scope.prototype.add = function(model) {
1382
+ if (!model.get('id')) throw new Error('Model must have ID to be stored.');
1383
+ if (this.exists(model)) {
1384
+ throw new Error("" + model.constructor.name + " model with ID " + (model.get('id')) + " already in scope.");
1385
+ }
1386
+ this.models[model.get('id')] = model;
1387
+ this.trigger('add', model);
1388
+ return model.bind('destroy', this.remove);
1389
+ };
1390
+
1391
+ Scope.prototype.matches = function(model) {
1392
+ var _this = this;
1393
+ return Object.keys(this.params).every(function(key) {
1394
+ return model.get(key) === _this.params[key];
1395
+ });
1396
+ };
1397
+
1398
+ Scope.prototype.count = function() {
1399
+ return Object.keys(this.models).length;
1400
+ };
1401
+
1402
+ Scope.prototype.find = function(id) {
1403
+ return this.models[id] || (function() {
1404
+ throw new Error('Model not found in scope.');
1405
+ })();
1406
+ };
1407
+
1408
+ Scope.prototype.remove = function(model) {
1409
+ delete this.models[model.get('id')];
1410
+ model.unbind('destroy', this.remove);
1411
+ return this.trigger('remove', model);
1412
+ };
1413
+
1414
+ Scope.prototype.exists = function(model) {
1415
+ return !!this.models[model.get('id')];
1416
+ };
1417
+
1418
+ Scope.prototype.forEach = function(callback) {
1419
+ var key, value, _ref, _results;
1420
+ _ref = this.models;
1421
+ _results = [];
1422
+ for (key in _ref) {
1423
+ value = _ref[key];
1424
+ _results.push(callback(value));
1425
+ }
1426
+ return _results;
1427
+ };
1428
+
1429
+ return Scope;
1430
+
1431
+ })(Module);
1432
+
1377
1433
  }).call(this);
1378
1434
  }, "wingman/template": function(exports, require, module) {(function() {
1379
1435
  var Fleck, HandlerFactory, Parser, Template;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wingman_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-19 00:00:00.000000000 Z
12
+ date: 2012-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70123886167620 !ruby/object:Gem::Requirement
16
+ requirement: &70186217504960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,7 +24,7 @@ dependencies:
24
24
  version: '5.0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70123886167620
27
+ version_requirements: *70186217504960
28
28
  description: This gem provides Wingman for your Rails 3 application.
29
29
  email:
30
30
  - rasmusrnielsen@gmail.com