databound 1.0.0 → 1.0.1

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: 3e9250396be3c8b5dd3329f0a840c37711889491
4
- data.tar.gz: 82e2e65d820a8b51088cbf72cd9f9b54b74748bd
3
+ metadata.gz: 1bd29d880c872ed29197c3669462e319b561cf56
4
+ data.tar.gz: 640782f2fa971eaba38fe606e08d2fe439dea4d1
5
5
  SHA512:
6
- metadata.gz: c8b2f5ac35c2bf731f3284ada7f079ce76dc89966361df2db74596549a85d635d08655d5b444c74221c87b3d7f975e7a0d2eb3293a44a7fdcdd5501d553ab1a5
7
- data.tar.gz: 97238b8ccf2f8f0004b447704d68f10ec7f86657cd82bb2a586b25f9a509934c126c6aa67c546d486714ca57e53199e88ede49dfcbf16ec1cd68d54ef3e141d1
6
+ metadata.gz: bc47482f28e2cde3e2392a02b3cc6b2c5078fba81e2a07aa3a6c2e7dcb3f00a57db22acfb298f36627a613bc1912c5d1f069bd7c1fed9d2021b5146585f5de89
7
+ data.tar.gz: e875a2b81496cbd0d778c7726abc3731a5a085d23e666a9c4eeee34d70f6897cb9e7066dc62dc96f9858bc2c27b98813d9dfb5c25ca42862c697123285aabb37
@@ -1,3 +1,3 @@
1
1
  module Databound
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -8,7 +8,7 @@ module Databound
8
8
 
9
9
  def add_assets
10
10
  js_manifest = 'app/assets/javascripts/application.js'
11
- coffee_manifest = 'app/assets/javascripts/application.coffee'
11
+ coffee_manifest = 'app/assets/javascripts/application.js.coffee'
12
12
 
13
13
  if File.exist?(js_manifest)
14
14
  insert_into_file js_manifest, "//= require databound\n", after: "jquery_ujs\n"
@@ -20,7 +20,7 @@ module Databound
20
20
  end
21
21
 
22
22
  def add_databound
23
- copy_file 'js/dist/databound-standalone.js', 'vendor/assets/javascripts/databound.js'
23
+ copy_file 'databound-standalone.js', 'vendor/assets/javascripts/databound.js'
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,118 @@
1
+ var Databound;
2
+
3
+ Databound = (function() {
4
+ function Databound(endpoint, scope, options) {
5
+ this.endpoint = endpoint;
6
+ this.scope = scope != null ? scope : {};
7
+ this.options = options != null ? options : {};
8
+ this.extra_where_scopes = this.options.extra_where_scopes || [];
9
+ this.records = [];
10
+ this.seeds = [];
11
+ this.properties = [];
12
+ }
13
+
14
+ Databound.API_URL = "";
15
+
16
+ Databound.prototype.request = function(action, params) {
17
+ return jQuery.post(this.url(action), this.data(params), 'json');
18
+ };
19
+
20
+ Databound.prototype.promise = function(result) {
21
+ var deferred;
22
+ deferred = jQuery.Deferred();
23
+ deferred.resolve(result);
24
+ return deferred.promise();
25
+ };
26
+
27
+ Databound.prototype.where = function(params) {
28
+ var _this;
29
+ _this = this;
30
+ return this.request('where', params).then(function(records) {
31
+ records = records.concat(_this.seeds);
32
+ _this.records = _.sortBy(records, 'id');
33
+ return _this.promise(_this.records);
34
+ });
35
+ };
36
+
37
+ Databound.prototype.find = function(id) {
38
+ var _this;
39
+ _this = this;
40
+ return this.where({
41
+ id: id
42
+ }).then(function() {
43
+ return _this.promise(_this.take(id));
44
+ });
45
+ };
46
+
47
+ Databound.prototype.findBy = function(params) {
48
+ var _this;
49
+ _this = this;
50
+ return this.where(params).then(function(resp) {
51
+ return _this.promise(_.first(_.values(resp)));
52
+ });
53
+ };
54
+
55
+ Databound.prototype.create = function(params) {
56
+ return this.requestAndRefresh('create', params);
57
+ };
58
+
59
+ Databound.prototype.update = function(params) {
60
+ return this.requestAndRefresh('update', params);
61
+ };
62
+
63
+ Databound.prototype.destroy = function(params) {
64
+ return this.requestAndRefresh('destroy', params);
65
+ };
66
+
67
+ Databound.prototype.take = function(id) {
68
+ return _.detect(this.records, function(record) {
69
+ return id.toString() === record.id.toString();
70
+ });
71
+ };
72
+
73
+ Databound.prototype.takeAll = function() {
74
+ return this.records;
75
+ };
76
+
77
+ Databound.prototype.injectSeedRecords = function(records) {
78
+ return this.seeds = records;
79
+ };
80
+
81
+ Databound.prototype.requestAndRefresh = function(action, params) {
82
+ var _this;
83
+ _this = this;
84
+ return this.request(action, params).then(function(resp) {
85
+ var records, records_with_seeds;
86
+ if (!(resp != null ? resp.success : void 0)) {
87
+ throw new Error('Error in the backend');
88
+ }
89
+ records = JSON.parse(resp.scoped_records);
90
+ records_with_seeds = records.concat(_this.seeds);
91
+ _this.records = _.sortBy(records_with_seeds, 'id');
92
+ if (resp.id) {
93
+ return _this.promise(_this.take(resp.id));
94
+ } else {
95
+ return _this.promise(resp.success);
96
+ }
97
+ });
98
+ };
99
+
100
+ Databound.prototype.url = function(action) {
101
+ if (_.isEmpty(Databound.API_URL)) {
102
+ return "" + this.endpoint + "/" + action;
103
+ } else {
104
+ return "" + Databound.API_URL + "/" + this.endpoint + "/" + action;
105
+ }
106
+ };
107
+
108
+ Databound.prototype.data = function(params) {
109
+ return {
110
+ scope: JSON.stringify(this.scope),
111
+ extra_where_scopes: JSON.stringify(this.extra_where_scopes),
112
+ data: JSON.stringify(params)
113
+ };
114
+ };
115
+
116
+ return Databound;
117
+
118
+ })();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: databound
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domas Bitvinskas
@@ -130,7 +130,6 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
- - ".gitmodules"
134
133
  - ".travis.yml"
135
134
  - Gemfile
136
135
  - LICENSE.txt
@@ -147,6 +146,7 @@ files:
147
146
  - lib/databound/version.rb
148
147
  - lib/generators/databound/install/install_generator.rb
149
148
  - lib/generators/databound/install/templates/application.js
149
+ - lib/generators/databound/install/templates/databound-standalone.js
150
150
  - spec/controllers/databound_spec.rb
151
151
  - spec/controllers/dsl_controller_spec.rb
152
152
  - spec/controllers/loose_dsl_controller_spec.rb
data/.gitmodules DELETED
@@ -1,3 +0,0 @@
1
- [submodule "lib/generators/databound/install/templates/js"]
2
- path = lib/generators/databound/install/templates/js
3
- url = https://github.com/Nedomas/databound.git