databound 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/README.md +19 -47
- data/databound.gemspec +2 -2
- data/lib/databound/manager.rb +3 -3
- data/lib/databound/utils.rb +3 -3
- data/lib/databound/version.rb +1 -1
- data/lib/generators/databound/install/install_generator.rb +27 -0
- data/lib/generators/databound/install/templates/application.js +10 -0
- data/spec/controllers/databound_spec.rb +0 -7
- data/spec/controllers/dsl_controller_spec.rb +0 -6
- data/spec/controllers/loose_dsl_controller_spec.rb +0 -4
- data/spec/controllers/on_the_fly_spec.rb +0 -1
- data/spec/controllers/permitted_columns_controller_spec.rb +0 -6
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e9250396be3c8b5dd3329f0a840c37711889491
|
4
|
+
data.tar.gz: 82e2e65d820a8b51088cbf72cd9f9b54b74748bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8b2f5ac35c2bf731f3284ada7f079ce76dc89966361df2db74596549a85d635d08655d5b444c74221c87b3d7f975e7a0d2eb3293a44a7fdcdd5501d553ab1a5
|
7
|
+
data.tar.gz: 97238b8ccf2f8f0004b447704d68f10ec7f86657cd82bb2a586b25f9a509934c126c6aa67c546d486714ca57e53199e88ede49dfcbf16ec1cd68d54ef3e141d1
|
data/.gitmodules
ADDED
data/README.md
CHANGED
@@ -1,63 +1,35 @@
|
|
1
|
-
[![Code Climate](https://codeclimate.com/github/Nedomas/databound-rails/badges/gpa.svg)](https://codeclimate.com/github/Nedomas/databound-rails)
|
2
1
|
[![Gem Version](https://badge.fury.io/rb/databound.svg)](http://badge.fury.io/rb/databound)
|
3
|
-
[![
|
4
|
-
[![
|
2
|
+
[![Bower version](https://badge.fury.io/bo/databound.svg)](http://badge.fury.io/bo/databound)
|
3
|
+
[![NPM version](https://badge.fury.io/js/databound.svg)](http://badge.fury.io/js/databound)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/Nedomas/databound/badges/gpa.svg)](https://codeclimate.com/github/Nedomas/databound)
|
5
|
+
[![Build Status](https://travis-ci.org/Nedomas/databound.svg)](https://travis-ci.org/Nedomas/databound)
|
5
6
|
|
6
7
|
![Databound](https://cloud.githubusercontent.com/assets/1877286/4743542/df89dcec-5a28-11e4-9114-6f383fe269cb.png)
|
7
8
|
|
8
|
-
Exposes database
|
9
|
+
Exposes Ruby on Rails database to the Javascript side.
|
9
10
|
|
10
|
-
Ruby on Rails backend
|
11
|
+
This repo is for Ruby on Rails backend part of Databound.
|
11
12
|
|
12
|
-
|
13
|
+
**Check out live examples on the Databound website** [databound.me](http://databound.me).
|
13
14
|
|
14
|
-
|
15
|
+
**You can also check out the javascript** [Databound repo](https://github.com/Nedomas/databound).
|
15
16
|
|
16
|
-
|
17
|
+
## Usage
|
17
18
|
|
18
19
|
```js
|
19
|
-
User = new Databound('/users')
|
20
|
+
User = new Databound('/users')
|
20
21
|
|
21
|
-
User.
|
22
|
+
User.where({ name: 'John' }).then(function(users) {
|
23
|
+
alert('Users called John');
|
22
24
|
});
|
23
|
-
```
|
24
|
-
|
25
|
-
## Installation
|
26
|
-
|
27
|
-
The library has two parts and has Lodash as a dependency.
|
28
|
-
|
29
|
-
#### I. Javascript part
|
30
|
-
|
31
|
-
Follow the guide on [javascript Databound repo](https://github.com/Nedomas/databound).
|
32
|
-
|
33
|
-
#### II. Ruby on Rails part
|
34
|
-
|
35
|
-
**1.** Add ``gem 'databound'`` to ``Gemfile``.
|
36
|
-
|
37
|
-
**2.** Create a controller with method ``model`` which returns the model to be accessed.
|
38
|
-
Also include ``Databound``
|
39
25
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def model
|
47
|
-
User
|
48
|
-
end
|
49
|
-
end
|
50
|
-
```
|
51
|
-
|
52
|
-
**3.** Add a route to ``routes.rb``
|
53
|
-
|
54
|
-
```ruby
|
55
|
-
# This creates POST routes on /users to UsersController
|
56
|
-
# For where, create, update, destroy
|
26
|
+
User.find(15).then(function(user) {
|
27
|
+
print('User no. 15: ' + user.name);
|
28
|
+
});
|
57
29
|
|
58
|
-
|
30
|
+
User.create({ name: 'Peter' }).then(function(user) {
|
31
|
+
print('I am ' + user.name + ' from database');
|
32
|
+
});
|
59
33
|
```
|
60
34
|
|
61
|
-
|
62
|
-
|
63
|
-
All features are described in [javascript Databound repo](https://github.com/Nedomas/databound).
|
35
|
+
[More API docs](http://nedomas.github.io/databound/src/databound.html)
|
data/databound.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Databound::VERSION
|
9
9
|
spec.authors = ['Domas Bitvinskas']
|
10
10
|
spec.email = ['domas.bitvinskas@me.com']
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Databound exposes Ruby on Rails database to the Javascript side}
|
12
|
+
spec.description = %q{Works with ActiveRecord and Mongoid out of the box}
|
13
13
|
spec.homepage = 'https://github.com/Nedomas/databound'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
data/lib/databound/manager.rb
CHANGED
@@ -7,12 +7,12 @@ module Databound
|
|
7
7
|
|
8
8
|
scope_js = controller.params[:scope]
|
9
9
|
data_js = controller.params[:data]
|
10
|
-
|
10
|
+
extra_where_scopes_js = controller.params[:extra_where_scopes] || '[]'
|
11
11
|
|
12
12
|
@scope = Databound::Data.new(controller, scope_js)
|
13
13
|
@data = Databound::Data.new(controller, data_js).to_h
|
14
14
|
|
15
|
-
@
|
15
|
+
@extra_where_scopes = JSON.parse(extra_where_scopes_js).map do |extra_scope|
|
16
16
|
Databound::Data.new(controller, extra_scope)
|
17
17
|
end
|
18
18
|
end
|
@@ -21,7 +21,7 @@ module Databound
|
|
21
21
|
records = []
|
22
22
|
records << @scope.records(@model)
|
23
23
|
|
24
|
-
@
|
24
|
+
@extra_where_scopes.each do |extra_scope|
|
25
25
|
records << extra_scope.records(@model)
|
26
26
|
end
|
27
27
|
|
data/lib/databound/utils.rb
CHANGED
@@ -9,12 +9,12 @@ module Databound
|
|
9
9
|
resource.to_s.classify.constantize
|
10
10
|
end
|
11
11
|
|
12
|
-
Object.const_set(
|
12
|
+
Object.const_set(controller_name(path), controller)
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.exists?(path)
|
16
16
|
begin
|
17
|
-
|
17
|
+
controller_name(path).constantize
|
18
18
|
rescue NameError
|
19
19
|
return false
|
20
20
|
end
|
@@ -22,7 +22,7 @@ module Databound
|
|
22
22
|
true
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.
|
25
|
+
def self.controller_name(path)
|
26
26
|
"#{path.camelize}Controller"
|
27
27
|
end
|
28
28
|
end
|
data/lib/databound/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Databound
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
desc 'This generator adds Databound to the asset pipeline'
|
8
|
+
|
9
|
+
def add_assets
|
10
|
+
js_manifest = 'app/assets/javascripts/application.js'
|
11
|
+
coffee_manifest = 'app/assets/javascripts/application.coffee'
|
12
|
+
|
13
|
+
if File.exist?(js_manifest)
|
14
|
+
insert_into_file js_manifest, "//= require databound\n", after: "jquery_ujs\n"
|
15
|
+
elsif File.exist?(coffee_manifest)
|
16
|
+
insert_into_file coffee_manifest, "#= require databound\n", after: "jquery_ujs\n"
|
17
|
+
else
|
18
|
+
copy_file 'application.js', js_manifest
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_databound
|
23
|
+
copy_file 'js/dist/databound-standalone.js', 'vendor/assets/javascripts/databound.js'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require databound
|
10
|
+
//= require_tree .
|
@@ -8,7 +8,6 @@ describe UsersController, type: :controller do
|
|
8
8
|
name: 'John',
|
9
9
|
},
|
10
10
|
scope: {},
|
11
|
-
extra_find_scopes: [],
|
12
11
|
}
|
13
12
|
|
14
13
|
post(:create, javascriptize(data))
|
@@ -42,7 +41,6 @@ describe UsersController, type: :controller do
|
|
42
41
|
city: 'Los Angeles',
|
43
42
|
},
|
44
43
|
scope: {},
|
45
|
-
extra_find_scopes: [],
|
46
44
|
}
|
47
45
|
|
48
46
|
post(:where, javascriptize(data))
|
@@ -55,7 +53,6 @@ describe UsersController, type: :controller do
|
|
55
53
|
city: 'New York',
|
56
54
|
},
|
57
55
|
scope: {},
|
58
|
-
extra_find_scopes: [],
|
59
56
|
}
|
60
57
|
|
61
58
|
post(:where, javascriptize(data))
|
@@ -76,7 +73,6 @@ describe UsersController, type: :controller do
|
|
76
73
|
city: 'Moved to Los Angeles',
|
77
74
|
},
|
78
75
|
scope: {},
|
79
|
-
extra_find_scopes: [],
|
80
76
|
}
|
81
77
|
|
82
78
|
post(:update, javascriptize(data))
|
@@ -101,7 +97,6 @@ describe UsersController, type: :controller do
|
|
101
97
|
city: 'Moved to Los Angeles',
|
102
98
|
},
|
103
99
|
scope: {},
|
104
|
-
extra_find_scopes: [],
|
105
100
|
}
|
106
101
|
|
107
102
|
expect { post(:update, javascriptize(data)) }.to raise_error(ActiveRecord::RecordNotFound)
|
@@ -120,7 +115,6 @@ describe UsersController, type: :controller do
|
|
120
115
|
id: @user.id,
|
121
116
|
},
|
122
117
|
scope: {},
|
123
|
-
extra_find_scopes: [],
|
124
118
|
}
|
125
119
|
|
126
120
|
post(:destroy, javascriptize(data))
|
@@ -140,7 +134,6 @@ describe UsersController, type: :controller do
|
|
140
134
|
id: 2,
|
141
135
|
},
|
142
136
|
scope: {},
|
143
|
-
extra_find_scopes: [],
|
144
137
|
}
|
145
138
|
|
146
139
|
expect { post(:update, javascriptize(data)) }.to raise_error(ActiveRecord::RecordNotFound)
|
@@ -11,7 +11,6 @@ describe DslController, type: :controller do
|
|
11
11
|
city: 'hottest',
|
12
12
|
},
|
13
13
|
scope: {},
|
14
|
-
extra_find_scopes: [],
|
15
14
|
}
|
16
15
|
|
17
16
|
post(:create, javascriptize(data))
|
@@ -45,7 +44,6 @@ describe DslController, type: :controller do
|
|
45
44
|
city: 'coldest',
|
46
45
|
},
|
47
46
|
scope: {},
|
48
|
-
extra_find_scopes: [],
|
49
47
|
}
|
50
48
|
|
51
49
|
post(:create, javascriptize(data))
|
@@ -80,7 +78,6 @@ describe DslController, type: :controller do
|
|
80
78
|
city: 'New York',
|
81
79
|
},
|
82
80
|
scope: {},
|
83
|
-
extra_find_scopes: [],
|
84
81
|
}
|
85
82
|
|
86
83
|
expect { post(:create, javascriptize(data)) }.to raise_error(
|
@@ -104,7 +101,6 @@ describe DslController, type: :controller do
|
|
104
101
|
city: 'hottest',
|
105
102
|
},
|
106
103
|
scope: {},
|
107
|
-
extra_find_scopes: [],
|
108
104
|
}
|
109
105
|
|
110
106
|
post(:update, javascriptize(data))
|
@@ -141,7 +137,6 @@ describe DslController, type: :controller do
|
|
141
137
|
city: 'coldest',
|
142
138
|
},
|
143
139
|
scope: {},
|
144
|
-
extra_find_scopes: [],
|
145
140
|
}
|
146
141
|
|
147
142
|
post(:update, javascriptize(data))
|
@@ -179,7 +174,6 @@ describe DslController, type: :controller do
|
|
179
174
|
city: 'New York',
|
180
175
|
},
|
181
176
|
scope: {},
|
182
|
-
extra_find_scopes: [],
|
183
177
|
}
|
184
178
|
|
185
179
|
expect { post(:create, javascriptize(data)) }.to raise_error(
|
@@ -9,7 +9,6 @@ describe LooseDslController, type: :controller do
|
|
9
9
|
city: 'hottest',
|
10
10
|
},
|
11
11
|
scope: {},
|
12
|
-
extra_find_scopes: [],
|
13
12
|
}
|
14
13
|
|
15
14
|
post(:create, javascriptize(data))
|
@@ -43,7 +42,6 @@ describe LooseDslController, type: :controller do
|
|
43
42
|
city: 'New York',
|
44
43
|
},
|
45
44
|
scope: {},
|
46
|
-
extra_find_scopes: [],
|
47
45
|
}
|
48
46
|
|
49
47
|
post(:create, javascriptize(data))
|
@@ -79,7 +77,6 @@ describe LooseDslController, type: :controller do
|
|
79
77
|
city: 'hottest',
|
80
78
|
},
|
81
79
|
scope: {},
|
82
|
-
extra_find_scopes: [],
|
83
80
|
}
|
84
81
|
|
85
82
|
post(:update, javascriptize(data))
|
@@ -115,7 +112,6 @@ describe LooseDslController, type: :controller do
|
|
115
112
|
city: 'Los Angeles',
|
116
113
|
},
|
117
114
|
scope: {},
|
118
|
-
extra_find_scopes: [],
|
119
115
|
}
|
120
116
|
|
121
117
|
post(:update, javascriptize(data))
|
@@ -8,7 +8,6 @@ describe PermittedColumnsController, type: :controller do
|
|
8
8
|
city: 'Barcelona',
|
9
9
|
},
|
10
10
|
scope: {},
|
11
|
-
extra_find_scopes: [],
|
12
11
|
}
|
13
12
|
|
14
13
|
expect { post(:create, javascriptize(data)) }.to raise_error(
|
@@ -23,7 +22,6 @@ describe PermittedColumnsController, type: :controller do
|
|
23
22
|
name: 'Nikki',
|
24
23
|
},
|
25
24
|
scope: {},
|
26
|
-
extra_find_scopes: [],
|
27
25
|
}
|
28
26
|
|
29
27
|
expect { post(:create, javascriptize(data)) }.not_to raise_error
|
@@ -42,7 +40,6 @@ describe PermittedColumnsController, type: :controller do
|
|
42
40
|
city: 'Barcelona',
|
43
41
|
},
|
44
42
|
scope: {},
|
45
|
-
extra_find_scopes: [],
|
46
43
|
}
|
47
44
|
|
48
45
|
expect { post(:update, javascriptize(data)) }.to raise_error(
|
@@ -58,7 +55,6 @@ describe PermittedColumnsController, type: :controller do
|
|
58
55
|
name: 'Nikki',
|
59
56
|
},
|
60
57
|
scope: {},
|
61
|
-
extra_find_scopes: [],
|
62
58
|
}
|
63
59
|
|
64
60
|
expect { post(:update, javascriptize(data)) }.not_to raise_error
|
@@ -73,7 +69,6 @@ describe PermittedColumnsController, type: :controller do
|
|
73
69
|
name: 'Nikki',
|
74
70
|
},
|
75
71
|
scope: { city: 'Barcelona' },
|
76
|
-
extra_find_scopes: [],
|
77
72
|
}
|
78
73
|
|
79
74
|
expect { post(:create, javascriptize(data)) }.to raise_error(
|
@@ -91,7 +86,6 @@ describe PermittedColumnsController, type: :controller do
|
|
91
86
|
name: 'Nikki',
|
92
87
|
},
|
93
88
|
scope: { city: 'Barcelona' },
|
94
|
-
extra_find_scopes: [],
|
95
89
|
}
|
96
90
|
|
97
91
|
expect { post(:update, javascriptize(data)) }.to raise_error(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: databound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domas Bitvinskas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -122,8 +122,7 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '10.0'
|
125
|
-
description:
|
126
|
-
and Mongoid
|
125
|
+
description: Works with ActiveRecord and Mongoid out of the box
|
127
126
|
email:
|
128
127
|
- domas.bitvinskas@me.com
|
129
128
|
executables: []
|
@@ -131,6 +130,7 @@ extensions: []
|
|
131
130
|
extra_rdoc_files: []
|
132
131
|
files:
|
133
132
|
- ".gitignore"
|
133
|
+
- ".gitmodules"
|
134
134
|
- ".travis.yml"
|
135
135
|
- Gemfile
|
136
136
|
- LICENSE.txt
|
@@ -145,6 +145,8 @@ files:
|
|
145
145
|
- lib/databound/rails/routes.rb
|
146
146
|
- lib/databound/utils.rb
|
147
147
|
- lib/databound/version.rb
|
148
|
+
- lib/generators/databound/install/install_generator.rb
|
149
|
+
- lib/generators/databound/install/templates/application.js
|
148
150
|
- spec/controllers/databound_spec.rb
|
149
151
|
- spec/controllers/dsl_controller_spec.rb
|
150
152
|
- spec/controllers/loose_dsl_controller_spec.rb
|
@@ -238,7 +240,7 @@ rubyforge_project:
|
|
238
240
|
rubygems_version: 2.2.2
|
239
241
|
signing_key:
|
240
242
|
specification_version: 4
|
241
|
-
summary:
|
243
|
+
summary: Databound exposes Ruby on Rails database to the Javascript side
|
242
244
|
test_files:
|
243
245
|
- spec/controllers/databound_spec.rb
|
244
246
|
- spec/controllers/dsl_controller_spec.rb
|
@@ -310,4 +312,3 @@ test_files:
|
|
310
312
|
- spec/support/rails_test_app/public/robots.txt
|
311
313
|
- spec/support/rails_test_app/vendor/assets/javascripts/.keep
|
312
314
|
- spec/support/rails_test_app/vendor/assets/stylesheets/.keep
|
313
|
-
has_rdoc:
|