spine-rails 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -358,7 +358,7 @@
358
358
  _results = [];
359
359
  for (key in atts) {
360
360
  value = atts[key];
361
- _results.push(this[key] = value);
361
+ _results.push(typeof this[key] === 'function' ? this[key](value) : this[key] = value);
362
362
  }
363
363
  return _results;
364
364
  };
@@ -368,9 +368,17 @@
368
368
  _ref = this.constructor.attributes;
369
369
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
370
370
  key = _ref[_i];
371
- result[key] = this[key];
371
+ if (key in this) {
372
+ if (typeof this[key] === 'function') {
373
+ result[key] = this[key]();
374
+ } else {
375
+ result[key] = this[key];
376
+ }
377
+ }
378
+ }
379
+ if (this.id) {
380
+ result.id = this.id;
372
381
  }
373
- result.id = this.id;
374
382
  return result;
375
383
  };
376
384
  Model.prototype.eql = function(rec) {
@@ -665,7 +673,7 @@
665
673
  if (typeof module !== "undefined" && module !== null) {
666
674
  module.exports = Spine;
667
675
  }
668
- Spine.version = '0.0.9';
676
+ Spine.version = '1.0.0';
669
677
  Spine.isArray = isArray;
670
678
  Spine.isBlank = isBlank;
671
679
  Spine.$ = $;
@@ -714,4 +722,5 @@
714
722
  return new this(a1, a2, a3, a4, a5);
715
723
  };
716
724
  Spine.Class = Module;
725
+ Spine.App = new Controller;
717
726
  }).call(this);
@@ -1,5 +1,5 @@
1
1
  (function() {
2
- var $, Ajax, Base, Collection, Include, Model, Singleton;
2
+ var $, Ajax, Base, Collection, Extend, Include, Model, Singleton;
3
3
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
4
4
  for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
5
5
  function ctor() { this.constructor = child; }
@@ -9,7 +9,7 @@
9
9
  return child;
10
10
  };
11
11
  if (typeof Spine === "undefined" || Spine === null) {
12
- Spine = require("spine");
12
+ Spine = require('spine');
13
13
  }
14
14
  $ = Spine.$;
15
15
  Model = Spine.Model;
@@ -44,18 +44,19 @@
44
44
  return;
45
45
  }
46
46
  if (this.pending) {
47
- return this.requests.push(callback);
47
+ this.requests.push(callback);
48
48
  } else {
49
49
  this.pending = true;
50
- return this.request(callback);
50
+ this.request(callback);
51
51
  }
52
+ return callback;
52
53
  }
53
54
  };
54
55
  Base = (function() {
55
56
  function Base() {}
56
57
  Base.prototype.defaults = {
57
- contentType: "application/json",
58
- dataType: "json",
58
+ contentType: 'application/json',
59
+ dataType: 'json',
59
60
  processData: false
60
61
  };
61
62
  Base.prototype.ajax = function(params, defaults) {
@@ -75,20 +76,20 @@
75
76
  }
76
77
  Collection.prototype.findAll = function(params) {
77
78
  return this.ajax(params, {
78
- type: "GET",
79
+ type: 'GET',
79
80
  url: Ajax.getURL(this.model)
80
81
  }).success(this.recordsResponse).error(this.errorResponse);
81
82
  };
82
- Collection.prototype.fetch = function() {
83
- return this.findAll().success(__bind(function(records) {
83
+ Collection.prototype.fetch = function(params) {
84
+ return this.findAll(params).success(__bind(function(records) {
84
85
  return this.model.refresh(records);
85
86
  }, this));
86
87
  };
87
88
  Collection.prototype.recordsResponse = function(data, status, xhr) {
88
- return this.model.trigger("ajaxSuccess", null, status, xhr);
89
+ return this.model.trigger('ajaxSuccess', null, status, xhr);
89
90
  };
90
91
  Collection.prototype.errorResponse = function(xhr, statusText, error) {
91
- return this.model.trigger("ajaxError", null, xhr, statusText, error);
92
+ return this.model.trigger('ajaxError', null, xhr, statusText, error);
92
93
  };
93
94
  return Collection;
94
95
  })();
@@ -103,14 +104,14 @@
103
104
  }
104
105
  Singleton.prototype.find = function(params) {
105
106
  return this.ajax(params, {
106
- type: "GET",
107
+ type: 'GET',
107
108
  url: this.url
108
109
  });
109
110
  };
110
111
  Singleton.prototype.create = function(params) {
111
112
  return this.queue(__bind(function() {
112
113
  return this.ajax(params, {
113
- type: "POST",
114
+ type: 'POST',
114
115
  data: JSON.stringify(this.record),
115
116
  url: Ajax.getURL(this.model)
116
117
  }).success(this.recordResponse).error(this.errorResponse);
@@ -119,7 +120,7 @@
119
120
  Singleton.prototype.update = function(params) {
120
121
  return this.queue(__bind(function() {
121
122
  return this.ajax(params, {
122
- type: "PUT",
123
+ type: 'PUT',
123
124
  data: JSON.stringify(this.record),
124
125
  url: Ajax.getURL(this.record)
125
126
  }).success(this.recordResponse).error(this.errorResponse);
@@ -128,13 +129,13 @@
128
129
  Singleton.prototype.destroy = function(params) {
129
130
  return this.queue(__bind(function() {
130
131
  return this.ajax(params, {
131
- type: "DELETE",
132
+ type: 'DELETE',
132
133
  url: Ajax.getURL(this.record)
133
134
  }).success(this.recordResponse).error(this.errorResponse);
134
135
  }, this));
135
136
  };
136
137
  Singleton.prototype.recordResponse = function(data, status, xhr) {
137
- this.record.trigger("ajaxSuccess", this.record, status, xhr);
138
+ this.record.trigger('ajaxSuccess', this.record, status, xhr);
138
139
  if (Spine.isBlank(data)) {
139
140
  return;
140
141
  }
@@ -147,14 +148,14 @@
147
148
  }, this));
148
149
  };
149
150
  Singleton.prototype.blankResponse = function(data, status, xhr) {
150
- return this.record.trigger("ajaxSuccess", this.record, status, xhr);
151
+ return this.record.trigger('ajaxSuccess', this.record, status, xhr);
151
152
  };
152
153
  Singleton.prototype.errorResponse = function(xhr, statusText, error) {
153
- return this.record.trigger("ajaxError", this.record, xhr, statusText, error);
154
+ return this.record.trigger('ajaxError', this.record, xhr, statusText, error);
154
155
  };
155
156
  return Singleton;
156
157
  })();
157
- Model.host = "";
158
+ Model.host = '';
158
159
  Include = {
159
160
  ajax: function() {
160
161
  return new Singleton(this);
@@ -162,17 +163,22 @@
162
163
  url: function() {
163
164
  var base;
164
165
  base = Ajax.getURL(this.constructor);
165
- if (base.charAt(base.length - 1) !== "/") {
166
- base += "/";
166
+ if (base.charAt(base.length - 1) !== '/') {
167
+ base += '/';
167
168
  }
168
169
  base += encodeURIComponent(this.id);
169
170
  return base;
170
171
  }
171
172
  };
172
- Model.Ajax = {
173
+ Extend = {
173
174
  ajax: function() {
174
175
  return new Collection(this);
175
176
  },
177
+ url: function() {
178
+ return "" + Model.host + "/" + (this.className.toLowerCase()) + "s";
179
+ }
180
+ };
181
+ Model.Ajax = {
176
182
  extended: function() {
177
183
  this.change(function(record, type) {
178
184
  return record.ajax()[type]();
@@ -181,10 +187,14 @@
181
187
  var _ref;
182
188
  return (_ref = this.ajax()).fetch.apply(_ref, arguments);
183
189
  });
190
+ this.extend(Extend);
191
+ return this.include(Include);
192
+ }
193
+ };
194
+ Model.Ajax.Methods = {
195
+ extended: function() {
196
+ this.extend(Extend);
184
197
  return this.include(Include);
185
- },
186
- url: function() {
187
- return "" + Model.host + "/" + (this.className.toLowerCase()) + "s";
188
198
  }
189
199
  };
190
200
  Spine.Ajax = Ajax;
@@ -9,18 +9,18 @@
9
9
  return child;
10
10
  };
11
11
  if (typeof Spine === "undefined" || Spine === null) {
12
- Spine = require("spine");
12
+ Spine = require('spine');
13
13
  }
14
14
  $ = Spine.$;
15
15
  Spine.List = (function() {
16
16
  __extends(List, Spine.Controller);
17
17
  List.prototype.events = {
18
- "click .item": "click"
18
+ 'click .item': 'click'
19
19
  };
20
20
  List.prototype.selectFirst = false;
21
21
  function List() {
22
22
  this.change = __bind(this.change, this); List.__super__.constructor.apply(this, arguments);
23
- this.bind("change", this.change);
23
+ this.bind('change', this.change);
24
24
  }
25
25
  List.prototype.template = function() {
26
26
  return arguments[0];
@@ -30,8 +30,8 @@
30
30
  return;
31
31
  }
32
32
  this.current = item;
33
- this.children().removeClass("active");
34
- return this.children().forItem(this.current).addClass("active");
33
+ this.children().removeClass('active');
34
+ return this.children().forItem(this.current).addClass('active');
35
35
  };
36
36
  List.prototype.render = function(items) {
37
37
  if (items) {
@@ -40,8 +40,8 @@
40
40
  this.html(this.template(this.items));
41
41
  this.change(this.current);
42
42
  if (this.selectFirst) {
43
- if (!this.children(".active").length) {
44
- return this.children(":first").click();
43
+ if (!this.children('.active').length) {
44
+ return this.children(':first').click();
45
45
  }
46
46
  }
47
47
  };
@@ -51,7 +51,7 @@
51
51
  List.prototype.click = function(e) {
52
52
  var item;
53
53
  item = $(e.target).item();
54
- return this.trigger("change", item);
54
+ return this.trigger('change', item);
55
55
  };
56
56
  return List;
57
57
  })();
@@ -1,6 +1,6 @@
1
1
  (function() {
2
2
  if (typeof Spine === "undefined" || Spine === null) {
3
- Spine = require("spine");
3
+ Spine = require('spine');
4
4
  }
5
5
  Spine.Model.Local = {
6
6
  extended: function() {
File without changes
@@ -1,10 +1,23 @@
1
1
  (function() {
2
- var Collection, Instance, singularize, underscore;
3
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
2
+ var Collection, Instance, Singleton, require, singularize, underscore;
3
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
4
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
5
+ function ctor() { this.constructor = child; }
6
+ ctor.prototype = parent.prototype;
7
+ child.prototype = new ctor;
8
+ child.__super__ = parent.prototype;
9
+ return child;
10
+ }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
4
11
  if (typeof Spine === "undefined" || Spine === null) {
5
- Spine = require("spine");
12
+ Spine = require('spine');
13
+ }
14
+ if (typeof require === "undefined" || require === null) {
15
+ require = (function(value) {
16
+ return eval(value);
17
+ });
6
18
  }
7
19
  Collection = (function() {
20
+ __extends(Collection, Spine.Module);
8
21
  function Collection(options) {
9
22
  var key, value;
10
23
  if (options == null) {
@@ -34,7 +47,7 @@
34
47
  return this.associated(rec) && rec.id === id;
35
48
  }, this));
36
49
  if (!records[0]) {
37
- throw "Unknown record";
50
+ throw 'Unknown record';
38
51
  }
39
52
  return records[0];
40
53
  };
@@ -57,7 +70,7 @@
57
70
  value[this.fkey] = this.record.id;
58
71
  this.model.records[value.id] = value;
59
72
  }
60
- return this.model.trigger("refresh");
73
+ return this.model.trigger('refresh');
61
74
  };
62
75
  Collection.prototype.create = function(record) {
63
76
  record[this.fkey] = this.record.id;
@@ -69,6 +82,7 @@
69
82
  return Collection;
70
83
  })();
71
84
  Instance = (function() {
85
+ __extends(Instance, Spine.Module);
72
86
  function Instance(options) {
73
87
  var key, value;
74
88
  if (options == null) {
@@ -79,14 +93,37 @@
79
93
  this[key] = value;
80
94
  }
81
95
  }
82
- Instance.prototype.find = function() {
83
- return this.record[this.fkey] && this.model.find(this.record[this.fkey]);
96
+ Instance.prototype.exists = function() {
97
+ return this.record[this.fkey] && this.model.exists(this.record[this.fkey]);
84
98
  };
85
99
  Instance.prototype.update = function(value) {
86
100
  return this.record[this.fkey] = value && value.id;
87
101
  };
88
102
  return Instance;
89
103
  })();
104
+ Singleton = (function() {
105
+ __extends(Singleton, Spine.Module);
106
+ function Singleton(options) {
107
+ var key, value;
108
+ if (options == null) {
109
+ options = {};
110
+ }
111
+ for (key in options) {
112
+ value = options[key];
113
+ this[key] = value;
114
+ }
115
+ }
116
+ Singleton.prototype.find = function() {
117
+ return this.record.id && this.model.findByAttribute(this.fkey, this.record.id);
118
+ };
119
+ Singleton.prototype.update = function(value) {
120
+ if (value != null) {
121
+ value[this.fkey] = this.id;
122
+ }
123
+ return value;
124
+ };
125
+ return Singleton;
126
+ })();
90
127
  singularize = function(str) {
91
128
  return str.replace(/s$/, '');
92
129
  };
@@ -94,13 +131,13 @@
94
131
  return str.replace(/::/g, '/').replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').replace(/-/g, '_').toLowerCase();
95
132
  };
96
133
  Spine.Model.extend({
97
- many: function(name, model, fkey) {
134
+ hasMany: function(name, model, fkey) {
98
135
  var association;
99
136
  if (fkey == null) {
100
137
  fkey = "" + (underscore(this.className)) + "_id";
101
138
  }
102
139
  association = function(record) {
103
- if (typeof model === "string") {
140
+ if (typeof model === 'string') {
104
141
  model = require(model);
105
142
  }
106
143
  return new Collection({
@@ -110,20 +147,20 @@
110
147
  fkey: fkey
111
148
  });
112
149
  };
113
- this.prototype.__defineGetter__(name, function() {
150
+ return this.prototype[name] = function(value) {
151
+ if (value != null) {
152
+ association(this).refresh(value);
153
+ }
114
154
  return association(this);
115
- });
116
- return this.prototype.__defineSetter__(name, function(value) {
117
- return association(this).refresh(value);
118
- });
155
+ };
119
156
  },
120
- belongs: function(name, model, fkey) {
157
+ belongsTo: function(name, model, fkey) {
121
158
  var association;
122
159
  if (fkey == null) {
123
160
  fkey = "" + (singularize(name)) + "_id";
124
161
  }
125
162
  association = function(record) {
126
- if (typeof model === "string") {
163
+ if (typeof model === 'string') {
127
164
  model = require(model);
128
165
  }
129
166
  return new Instance({
@@ -133,13 +170,36 @@
133
170
  fkey: fkey
134
171
  });
135
172
  };
136
- this.prototype.__defineGetter__(name, function() {
137
- return association(this).find();
138
- });
139
- this.prototype.__defineSetter__(name, function(value) {
140
- return association(this).update(value);
141
- });
173
+ this.prototype[name] = function(value) {
174
+ if (value != null) {
175
+ association(this).update(value);
176
+ }
177
+ return association(this).exists();
178
+ };
142
179
  return this.attributes.push(fkey);
180
+ },
181
+ hasOne: function(name, model, fkey) {
182
+ var association;
183
+ if (fkey == null) {
184
+ fkey = "" + (underscore(this.className)) + "_id";
185
+ }
186
+ association = function(record) {
187
+ if (typeof model === 'string') {
188
+ model = require(model);
189
+ }
190
+ return new Singleton({
191
+ name: name,
192
+ model: model,
193
+ record: record,
194
+ fkey: fkey
195
+ });
196
+ };
197
+ return this.prototype[name] = function(value) {
198
+ if (value != null) {
199
+ association(this).update(value);
200
+ }
201
+ return association(this).find();
202
+ };
143
203
  }
144
204
  });
145
205
  }).call(this);
@@ -9,7 +9,7 @@
9
9
  return child;
10
10
  }, __slice = Array.prototype.slice;
11
11
  if (typeof Spine === "undefined" || Spine === null) {
12
- Spine = require("spine");
12
+ Spine = require('spine');
13
13
  }
14
14
  $ = Spine.$;
15
15
  hashStrip = /^#*/;
@@ -9,7 +9,7 @@
9
9
  return child;
10
10
  };
11
11
  if (typeof Spine === "undefined" || Spine === null) {
12
- Spine = require("spine");
12
+ Spine = require('spine');
13
13
  }
14
14
  $ = Spine.$;
15
15
  Spine.Tabs = (function() {
File without changes
@@ -1,6 +1,6 @@
1
1
  module Spine
2
2
  module Rails
3
- VERSION = "0.0.2"
4
- SPINE_VERSION = "0.0.9"
3
+ VERSION = "0.0.3"
4
+ SPINE_VERSION = "1.0.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spine-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2011-09-27 00:00:00.000000000Z
12
+ date: 2011-10-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
16
- requirement: &70181005400000 !ruby/object:Gem::Requirement
16
+ requirement: &70355697280880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70181005400000
24
+ version_requirements: *70355697280880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70181005399540 !ruby/object:Gem::Requirement
27
+ requirement: &70355697280420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70181005399540
35
+ version_requirements: *70355697280420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &70181005399080 !ruby/object:Gem::Requirement
38
+ requirement: &70355697279960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '3.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70181005399080
46
+ version_requirements: *70355697279960
47
47
  description: This gem provides Spine for your Rails 3 application.
48
48
  email:
49
49
  - info@eribium.org