cable_ready 5.0.0.pre1 → 5.0.0.pre2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +98 -92
- data/cable_ready.gemspec +27 -0
- data/lib/cable_ready.rb +3 -0
- data/lib/cable_ready/identifiable.rb +13 -2
- data/lib/cable_ready/operation_builder.rb +19 -5
- data/lib/cable_ready/sanity_checker.rb +50 -50
- data/lib/cable_ready/version.rb +1 -1
- data/package.json +41 -0
- data/tags +80 -0
- data/test/lib/cable_ready/cable_car_test.rb +22 -0
- data/test/lib/cable_ready/operation_builder_test.rb +83 -0
- data/yarn.lock +2562 -0
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8bb4eaf8d394d6148e9726fb043dcdd34e3ce9e893b8bfba84a5222481a1c951
|
|
4
|
+
data.tar.gz: f57b4d052d2fa2f3236f4d64528a8fd546c3983e567a813730f2480358805be1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 180c342be129e4c747823f9697363e3d8ffe50a58da146a2c1ea85f216018a59e333c44dfb89037e2fa7d6ba5f1f95feee4c4c756da97460ebb7e060b9a8566e
|
|
7
|
+
data.tar.gz: 9e0f2341bef2045587c54c2a3edfd38224471c2be3582e4e4fb1e1dfa5587e0a29e8148c650f1e39e26bbe96eede3242921e4dcffbd20a8fc924d184cc04b31d
|
data/Gemfile.lock
CHANGED
|
@@ -1,113 +1,121 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
cable_ready (5.0.0.
|
|
4
|
+
cable_ready (5.0.0.pre2)
|
|
5
5
|
rails (>= 5.2)
|
|
6
6
|
thread-local (>= 1.1.0)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
actioncable (6.1.
|
|
12
|
-
actionpack (= 6.1.
|
|
13
|
-
activesupport (= 6.1.
|
|
11
|
+
actioncable (6.1.4)
|
|
12
|
+
actionpack (= 6.1.4)
|
|
13
|
+
activesupport (= 6.1.4)
|
|
14
14
|
nio4r (~> 2.0)
|
|
15
15
|
websocket-driver (>= 0.6.1)
|
|
16
|
-
actionmailbox (6.1.
|
|
17
|
-
actionpack (= 6.1.
|
|
18
|
-
activejob (= 6.1.
|
|
19
|
-
activerecord (= 6.1.
|
|
20
|
-
activestorage (= 6.1.
|
|
21
|
-
activesupport (= 6.1.
|
|
16
|
+
actionmailbox (6.1.4)
|
|
17
|
+
actionpack (= 6.1.4)
|
|
18
|
+
activejob (= 6.1.4)
|
|
19
|
+
activerecord (= 6.1.4)
|
|
20
|
+
activestorage (= 6.1.4)
|
|
21
|
+
activesupport (= 6.1.4)
|
|
22
22
|
mail (>= 2.7.1)
|
|
23
|
-
actionmailer (6.1.
|
|
24
|
-
actionpack (= 6.1.
|
|
25
|
-
actionview (= 6.1.
|
|
26
|
-
activejob (= 6.1.
|
|
27
|
-
activesupport (= 6.1.
|
|
23
|
+
actionmailer (6.1.4)
|
|
24
|
+
actionpack (= 6.1.4)
|
|
25
|
+
actionview (= 6.1.4)
|
|
26
|
+
activejob (= 6.1.4)
|
|
27
|
+
activesupport (= 6.1.4)
|
|
28
28
|
mail (~> 2.5, >= 2.5.4)
|
|
29
29
|
rails-dom-testing (~> 2.0)
|
|
30
|
-
actionpack (6.1.
|
|
31
|
-
actionview (= 6.1.
|
|
32
|
-
activesupport (= 6.1.
|
|
30
|
+
actionpack (6.1.4)
|
|
31
|
+
actionview (= 6.1.4)
|
|
32
|
+
activesupport (= 6.1.4)
|
|
33
33
|
rack (~> 2.0, >= 2.0.9)
|
|
34
34
|
rack-test (>= 0.6.3)
|
|
35
35
|
rails-dom-testing (~> 2.0)
|
|
36
36
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
37
|
-
actiontext (6.1.
|
|
38
|
-
actionpack (= 6.1.
|
|
39
|
-
activerecord (= 6.1.
|
|
40
|
-
activestorage (= 6.1.
|
|
41
|
-
activesupport (= 6.1.
|
|
37
|
+
actiontext (6.1.4)
|
|
38
|
+
actionpack (= 6.1.4)
|
|
39
|
+
activerecord (= 6.1.4)
|
|
40
|
+
activestorage (= 6.1.4)
|
|
41
|
+
activesupport (= 6.1.4)
|
|
42
42
|
nokogiri (>= 1.8.5)
|
|
43
|
-
actionview (6.1.
|
|
44
|
-
activesupport (= 6.1.
|
|
43
|
+
actionview (6.1.4)
|
|
44
|
+
activesupport (= 6.1.4)
|
|
45
45
|
builder (~> 3.1)
|
|
46
46
|
erubi (~> 1.4)
|
|
47
47
|
rails-dom-testing (~> 2.0)
|
|
48
48
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
49
|
-
activejob (6.1.
|
|
50
|
-
activesupport (= 6.1.
|
|
49
|
+
activejob (6.1.4)
|
|
50
|
+
activesupport (= 6.1.4)
|
|
51
51
|
globalid (>= 0.3.6)
|
|
52
|
-
activemodel (6.1.
|
|
53
|
-
activesupport (= 6.1.
|
|
54
|
-
activerecord (6.1.
|
|
55
|
-
activemodel (= 6.1.
|
|
56
|
-
activesupport (= 6.1.
|
|
57
|
-
activestorage (6.1.
|
|
58
|
-
actionpack (= 6.1.
|
|
59
|
-
activejob (= 6.1.
|
|
60
|
-
activerecord (= 6.1.
|
|
61
|
-
activesupport (= 6.1.
|
|
52
|
+
activemodel (6.1.4)
|
|
53
|
+
activesupport (= 6.1.4)
|
|
54
|
+
activerecord (6.1.4)
|
|
55
|
+
activemodel (= 6.1.4)
|
|
56
|
+
activesupport (= 6.1.4)
|
|
57
|
+
activestorage (6.1.4)
|
|
58
|
+
actionpack (= 6.1.4)
|
|
59
|
+
activejob (= 6.1.4)
|
|
60
|
+
activerecord (= 6.1.4)
|
|
61
|
+
activesupport (= 6.1.4)
|
|
62
62
|
marcel (~> 1.0.0)
|
|
63
|
-
mini_mime (
|
|
64
|
-
activesupport (6.1.
|
|
63
|
+
mini_mime (>= 1.1.0)
|
|
64
|
+
activesupport (6.1.4)
|
|
65
65
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
66
66
|
i18n (>= 1.6, < 2)
|
|
67
67
|
minitest (>= 5.1)
|
|
68
68
|
tzinfo (~> 2.0)
|
|
69
69
|
zeitwerk (~> 2.3)
|
|
70
|
-
addressable (2.
|
|
70
|
+
addressable (2.8.0)
|
|
71
71
|
public_suffix (>= 2.0.2, < 5.0)
|
|
72
72
|
ast (2.4.2)
|
|
73
|
-
async (1.
|
|
73
|
+
async (1.30.0)
|
|
74
74
|
console (~> 1.10)
|
|
75
75
|
nio4r (~> 2.3)
|
|
76
76
|
timers (~> 4.1)
|
|
77
|
-
async-http (0.56.
|
|
78
|
-
async (
|
|
79
|
-
async-io (
|
|
80
|
-
async-pool (
|
|
77
|
+
async-http (0.56.5)
|
|
78
|
+
async (>= 1.25)
|
|
79
|
+
async-io (>= 1.28)
|
|
80
|
+
async-pool (>= 0.2)
|
|
81
81
|
protocol-http (~> 0.22.0)
|
|
82
82
|
protocol-http1 (~> 0.14.0)
|
|
83
83
|
protocol-http2 (~> 0.14.0)
|
|
84
|
-
async-http-faraday (0.
|
|
84
|
+
async-http-faraday (0.11.0)
|
|
85
85
|
async-http (~> 0.42)
|
|
86
86
|
faraday
|
|
87
|
-
async-io (1.
|
|
88
|
-
async
|
|
89
|
-
async-pool (0.3.
|
|
90
|
-
async (
|
|
87
|
+
async-io (1.32.2)
|
|
88
|
+
async
|
|
89
|
+
async-pool (0.3.8)
|
|
90
|
+
async (>= 1.25)
|
|
91
91
|
builder (3.2.4)
|
|
92
92
|
coderay (1.1.3)
|
|
93
|
-
concurrent-ruby (1.1.
|
|
94
|
-
console (1.
|
|
93
|
+
concurrent-ruby (1.1.9)
|
|
94
|
+
console (1.13.1)
|
|
95
95
|
fiber-local
|
|
96
96
|
crass (1.0.6)
|
|
97
97
|
erubi (1.10.0)
|
|
98
|
-
faraday (1.
|
|
98
|
+
faraday (1.5.1)
|
|
99
|
+
faraday-em_http (~> 1.0)
|
|
100
|
+
faraday-em_synchrony (~> 1.0)
|
|
99
101
|
faraday-excon (~> 1.1)
|
|
102
|
+
faraday-httpclient (~> 1.0.1)
|
|
100
103
|
faraday-net_http (~> 1.0)
|
|
101
104
|
faraday-net_http_persistent (~> 1.1)
|
|
105
|
+
faraday-patron (~> 1.0)
|
|
102
106
|
multipart-post (>= 1.2, < 3)
|
|
103
107
|
ruby2_keywords (>= 0.0.4)
|
|
108
|
+
faraday-em_http (1.0.0)
|
|
109
|
+
faraday-em_synchrony (1.0.0)
|
|
104
110
|
faraday-excon (1.1.0)
|
|
105
111
|
faraday-http-cache (2.2.0)
|
|
106
112
|
faraday (>= 0.8)
|
|
113
|
+
faraday-httpclient (1.0.1)
|
|
107
114
|
faraday-net_http (1.0.1)
|
|
108
|
-
faraday-net_http_persistent (1.
|
|
115
|
+
faraday-net_http_persistent (1.2.0)
|
|
116
|
+
faraday-patron (1.0.0)
|
|
109
117
|
fiber-local (1.0.0)
|
|
110
|
-
github_changelog_generator (1.16.
|
|
118
|
+
github_changelog_generator (1.16.4)
|
|
111
119
|
activesupport
|
|
112
120
|
async (>= 1.25.0)
|
|
113
121
|
async-http-faraday
|
|
@@ -116,12 +124,11 @@ GEM
|
|
|
116
124
|
octokit (~> 4.6)
|
|
117
125
|
rainbow (>= 2.2.1)
|
|
118
126
|
rake (>= 10.0)
|
|
119
|
-
retriable (~> 3.0)
|
|
120
127
|
globalid (0.4.2)
|
|
121
128
|
activesupport (>= 4.2.0)
|
|
122
129
|
i18n (1.8.10)
|
|
123
130
|
concurrent-ruby (~> 1.0)
|
|
124
|
-
loofah (2.
|
|
131
|
+
loofah (2.10.0)
|
|
125
132
|
crass (~> 1.0.2)
|
|
126
133
|
nokogiri (>= 1.5.9)
|
|
127
134
|
magic_frozen_string_literal (1.2.0)
|
|
@@ -129,24 +136,24 @@ GEM
|
|
|
129
136
|
mini_mime (>= 0.1.1)
|
|
130
137
|
marcel (1.0.1)
|
|
131
138
|
method_source (0.9.2)
|
|
132
|
-
mini_mime (1.0
|
|
133
|
-
mini_portile2 (2.5.
|
|
139
|
+
mini_mime (1.1.0)
|
|
140
|
+
mini_portile2 (2.5.3)
|
|
134
141
|
minitest (5.14.4)
|
|
135
|
-
mocha (1.
|
|
142
|
+
mocha (1.13.0)
|
|
136
143
|
multi_json (1.15.0)
|
|
137
144
|
multipart-post (2.1.1)
|
|
138
145
|
nio4r (2.5.7)
|
|
139
|
-
nokogiri (1.11.
|
|
146
|
+
nokogiri (1.11.7)
|
|
140
147
|
mini_portile2 (~> 2.5.0)
|
|
141
148
|
racc (~> 1.4)
|
|
142
149
|
octokit (4.21.0)
|
|
143
150
|
faraday (>= 0.9)
|
|
144
151
|
sawyer (~> 0.8.0, >= 0.5.3)
|
|
145
152
|
parallel (1.20.1)
|
|
146
|
-
parser (3.0.
|
|
153
|
+
parser (3.0.2.0)
|
|
147
154
|
ast (~> 2.4.1)
|
|
148
155
|
protocol-hpack (1.4.2)
|
|
149
|
-
protocol-http (0.22.
|
|
156
|
+
protocol-http (0.22.5)
|
|
150
157
|
protocol-http1 (0.14.1)
|
|
151
158
|
protocol-http (~> 0.22)
|
|
152
159
|
protocol-http2 (0.14.2)
|
|
@@ -162,53 +169,52 @@ GEM
|
|
|
162
169
|
rack (2.2.3)
|
|
163
170
|
rack-test (1.1.0)
|
|
164
171
|
rack (>= 1.0, < 3)
|
|
165
|
-
rails (6.1.
|
|
166
|
-
actioncable (= 6.1.
|
|
167
|
-
actionmailbox (= 6.1.
|
|
168
|
-
actionmailer (= 6.1.
|
|
169
|
-
actionpack (= 6.1.
|
|
170
|
-
actiontext (= 6.1.
|
|
171
|
-
actionview (= 6.1.
|
|
172
|
-
activejob (= 6.1.
|
|
173
|
-
activemodel (= 6.1.
|
|
174
|
-
activerecord (= 6.1.
|
|
175
|
-
activestorage (= 6.1.
|
|
176
|
-
activesupport (= 6.1.
|
|
172
|
+
rails (6.1.4)
|
|
173
|
+
actioncable (= 6.1.4)
|
|
174
|
+
actionmailbox (= 6.1.4)
|
|
175
|
+
actionmailer (= 6.1.4)
|
|
176
|
+
actionpack (= 6.1.4)
|
|
177
|
+
actiontext (= 6.1.4)
|
|
178
|
+
actionview (= 6.1.4)
|
|
179
|
+
activejob (= 6.1.4)
|
|
180
|
+
activemodel (= 6.1.4)
|
|
181
|
+
activerecord (= 6.1.4)
|
|
182
|
+
activestorage (= 6.1.4)
|
|
183
|
+
activesupport (= 6.1.4)
|
|
177
184
|
bundler (>= 1.15.0)
|
|
178
|
-
railties (= 6.1.
|
|
185
|
+
railties (= 6.1.4)
|
|
179
186
|
sprockets-rails (>= 2.0.0)
|
|
180
187
|
rails-dom-testing (2.0.3)
|
|
181
188
|
activesupport (>= 4.2.0)
|
|
182
189
|
nokogiri (>= 1.6)
|
|
183
190
|
rails-html-sanitizer (1.3.0)
|
|
184
191
|
loofah (~> 2.3)
|
|
185
|
-
railties (6.1.
|
|
186
|
-
actionpack (= 6.1.
|
|
187
|
-
activesupport (= 6.1.
|
|
192
|
+
railties (6.1.4)
|
|
193
|
+
actionpack (= 6.1.4)
|
|
194
|
+
activesupport (= 6.1.4)
|
|
188
195
|
method_source
|
|
189
|
-
rake (>= 0.
|
|
196
|
+
rake (>= 0.13)
|
|
190
197
|
thor (~> 1.0)
|
|
191
198
|
rainbow (3.0.0)
|
|
192
|
-
rake (13.0.
|
|
199
|
+
rake (13.0.6)
|
|
193
200
|
regexp_parser (2.1.1)
|
|
194
|
-
retriable (3.1.2)
|
|
195
201
|
rexml (3.2.5)
|
|
196
|
-
rubocop (1.
|
|
202
|
+
rubocop (1.18.3)
|
|
197
203
|
parallel (~> 1.10)
|
|
198
204
|
parser (>= 3.0.0.0)
|
|
199
205
|
rainbow (>= 2.2.2, < 4.0)
|
|
200
206
|
regexp_parser (>= 1.8, < 3.0)
|
|
201
207
|
rexml
|
|
202
|
-
rubocop-ast (>= 1.
|
|
208
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
|
203
209
|
ruby-progressbar (~> 1.7)
|
|
204
210
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
205
|
-
rubocop-ast (1.
|
|
211
|
+
rubocop-ast (1.8.0)
|
|
206
212
|
parser (>= 3.0.1.1)
|
|
207
|
-
rubocop-performance (1.11.
|
|
213
|
+
rubocop-performance (1.11.4)
|
|
208
214
|
rubocop (>= 1.7.0, < 2.0)
|
|
209
215
|
rubocop-ast (>= 0.4.0)
|
|
210
216
|
ruby-progressbar (1.11.0)
|
|
211
|
-
ruby2_keywords (0.0.
|
|
217
|
+
ruby2_keywords (0.0.5)
|
|
212
218
|
sawyer (0.8.2)
|
|
213
219
|
addressable (>= 2.3.5)
|
|
214
220
|
faraday (> 0.8, < 2.0)
|
|
@@ -219,9 +225,9 @@ GEM
|
|
|
219
225
|
actionpack (>= 4.0)
|
|
220
226
|
activesupport (>= 4.0)
|
|
221
227
|
sprockets (>= 3.0.0)
|
|
222
|
-
standard (1.1.
|
|
223
|
-
rubocop (= 1.
|
|
224
|
-
rubocop-performance (= 1.11.
|
|
228
|
+
standard (1.1.5)
|
|
229
|
+
rubocop (= 1.18.3)
|
|
230
|
+
rubocop-performance (= 1.11.4)
|
|
225
231
|
standardrb (1.0.0)
|
|
226
232
|
standard
|
|
227
233
|
thor (1.1.0)
|
|
@@ -230,7 +236,7 @@ GEM
|
|
|
230
236
|
tzinfo (2.0.4)
|
|
231
237
|
concurrent-ruby (~> 1.0)
|
|
232
238
|
unicode-display_width (2.0.0)
|
|
233
|
-
websocket-driver (0.7.
|
|
239
|
+
websocket-driver (0.7.5)
|
|
234
240
|
websocket-extensions (>= 0.1.0)
|
|
235
241
|
websocket-extensions (0.1.5)
|
|
236
242
|
zeitwerk (2.4.2)
|
|
@@ -249,4 +255,4 @@ DEPENDENCIES
|
|
|
249
255
|
standardrb
|
|
250
256
|
|
|
251
257
|
BUNDLED WITH
|
|
252
|
-
2.2.
|
|
258
|
+
2.2.19
|
data/cable_ready.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path("../lib/cable_ready/version", __FILE__)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.name = "cable_ready"
|
|
7
|
+
gem.license = "MIT"
|
|
8
|
+
gem.version = CableReady::VERSION
|
|
9
|
+
gem.authors = ["Nathan Hopkins"]
|
|
10
|
+
gem.email = ["natehop@gmail.com"]
|
|
11
|
+
gem.homepage = "https://github.com/stimulusreflex/cable_ready"
|
|
12
|
+
gem.summary = "Out-of-Band Server Triggered DOM Operations"
|
|
13
|
+
|
|
14
|
+
gem.files = Dir["lib/**/*.rb", "app/**/*.rb", "bin/*", "[A-Z]*"]
|
|
15
|
+
gem.test_files = Dir["test/**/*.rb"]
|
|
16
|
+
|
|
17
|
+
gem.add_dependency "rails", ">= 5.2"
|
|
18
|
+
gem.add_dependency "thread-local", ">= 1.1.0"
|
|
19
|
+
|
|
20
|
+
gem.add_development_dependency "github_changelog_generator"
|
|
21
|
+
gem.add_development_dependency "magic_frozen_string_literal"
|
|
22
|
+
gem.add_development_dependency "pry"
|
|
23
|
+
gem.add_development_dependency "pry-nav"
|
|
24
|
+
gem.add_development_dependency "rake"
|
|
25
|
+
gem.add_development_dependency "standardrb"
|
|
26
|
+
gem.add_development_dependency "mocha"
|
|
27
|
+
end
|
data/lib/cable_ready.rb
CHANGED
|
@@ -30,8 +30,11 @@ module CableReady
|
|
|
30
30
|
initializer "renderer" do
|
|
31
31
|
ActiveSupport.on_load(:action_controller) do
|
|
32
32
|
ActionController::Renderers.add :operations do |operations, options|
|
|
33
|
+
response.content_type ||= Mime[:cable_ready]
|
|
33
34
|
render json: operations.dispatch
|
|
34
35
|
end
|
|
36
|
+
|
|
37
|
+
Mime::Type.register "application/vnd.cable-ready.json", :cable_ready
|
|
35
38
|
end
|
|
36
39
|
end
|
|
37
40
|
end
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
module CableReady
|
|
4
4
|
module Identifiable
|
|
5
5
|
def dom_id(record, prefix = nil)
|
|
6
|
+
return record.to_dom_selector if record.respond_to?(:to_dom_selector)
|
|
7
|
+
|
|
6
8
|
prefix = prefix.to_s.strip if prefix
|
|
7
9
|
|
|
8
|
-
id = if record.
|
|
10
|
+
id = if record.respond_to?(:to_dom_id)
|
|
11
|
+
record.to_dom_id
|
|
12
|
+
elsif record.is_a?(ActiveRecord::Relation)
|
|
9
13
|
[prefix, record.model_name.plural].compact.join("_")
|
|
10
14
|
elsif record.is_a?(ActiveRecord::Base)
|
|
11
15
|
ActionView::RecordIdentifier.dom_id(record, prefix)
|
|
@@ -13,7 +17,14 @@ module CableReady
|
|
|
13
17
|
[prefix, record.to_s.strip].compact.join("_")
|
|
14
18
|
end
|
|
15
19
|
|
|
16
|
-
"##{id}".squeeze("#").strip
|
|
20
|
+
"##{id}".squeeze("#").strip.downcase
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def identifiable?(obj)
|
|
24
|
+
obj.respond_to?(:to_dom_selector) ||
|
|
25
|
+
obj.respond_to?(:to_dom_id) ||
|
|
26
|
+
obj.is_a?(ActiveRecord::Relation) ||
|
|
27
|
+
obj.is_a?(ActiveRecord::Base)
|
|
17
28
|
end
|
|
18
29
|
end
|
|
19
30
|
end
|
|
@@ -24,15 +24,29 @@ module CableReady
|
|
|
24
24
|
def add_operation_method(name)
|
|
25
25
|
return if respond_to?(name)
|
|
26
26
|
singleton_class.public_send :define_method, name, ->(*args) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
if args.one? && args.first.respond_to?(:to_operation_options) && [Array, Hash].include?(args.first.to_operation_options.class)
|
|
28
|
+
case args.first.to_operation_options
|
|
29
|
+
when Array
|
|
30
|
+
selector, options = nil, args.first.to_operation_options
|
|
31
|
+
.select { |e| e.is_a?(Symbol) && args.first.respond_to?("to_#{e}".to_sym) }
|
|
32
|
+
.each_with_object({}) { |option, memo| memo[option.to_s] = args.first.send("to_#{option}".to_sym) }
|
|
33
|
+
when Hash
|
|
34
|
+
selector, options = nil, args.first.to_operation_options
|
|
35
|
+
else
|
|
36
|
+
raise TypeError, ":to_operation_options returned an #{args.first.to_operation_options.class.name}. Must be an Array or Hash."
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
selector, options = nil, args.first || {} # 1 or 0 params
|
|
40
|
+
selector, options = options, {} unless options.is_a?(Hash) # swap if only selector provided
|
|
41
|
+
selector, options = args[0, 2] if args.many? # 2 or more params
|
|
42
|
+
options.stringify_keys!
|
|
43
|
+
options.each { |key, value| options[key] = value.send("to_#{key}".to_sym) if value.respond_to?("to_#{key}".to_sym) }
|
|
44
|
+
end
|
|
31
45
|
options["selector"] = selector if selector && options.exclude?("selector")
|
|
32
46
|
options["selector"] = previous_selector if previous_selector && options.exclude?("selector")
|
|
33
47
|
if options.include?("selector")
|
|
34
48
|
@previous_selector = options["selector"]
|
|
35
|
-
options["selector"] =
|
|
49
|
+
options["selector"] = identifiable?(previous_selector) ? dom_id(previous_selector) : previous_selector
|
|
36
50
|
end
|
|
37
51
|
@enqueued_operations[name.to_s] << options
|
|
38
52
|
self
|
|
@@ -7,48 +7,59 @@ class CableReady::SanityChecker
|
|
|
7
7
|
|
|
8
8
|
class << self
|
|
9
9
|
def check!
|
|
10
|
+
return if ENV["SKIP_SANITY_CHECK"]
|
|
10
11
|
return if CableReady.config.on_failed_sanity_checks == :ignore
|
|
11
12
|
return if called_by_generate_config?
|
|
13
|
+
return if called_by_rake?
|
|
12
14
|
|
|
13
15
|
instance = new
|
|
14
|
-
instance.
|
|
16
|
+
instance.check_package_versions_match
|
|
15
17
|
instance.check_new_version_available
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
private
|
|
19
21
|
|
|
20
22
|
def called_by_generate_config?
|
|
21
|
-
ARGV.include?
|
|
23
|
+
ARGV.include?("cable_ready:initializer")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def called_by_rake?
|
|
27
|
+
File.basename($PROGRAM_NAME) == "rake"
|
|
22
28
|
end
|
|
23
29
|
end
|
|
24
30
|
|
|
25
|
-
def
|
|
26
|
-
if
|
|
31
|
+
def check_package_versions_match
|
|
32
|
+
if npm_version.nil?
|
|
27
33
|
warn_and_exit <<~WARN
|
|
28
|
-
Can't locate the cable_ready npm package.
|
|
34
|
+
👉 Can't locate the cable_ready npm package.
|
|
35
|
+
|
|
36
|
+
yarn add cable_ready@#{gem_version}
|
|
37
|
+
|
|
29
38
|
Either add it to your package.json as a dependency or use "yarn link cable_ready" if you are doing development.
|
|
30
39
|
WARN
|
|
31
40
|
end
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
if package_version_mismatch?
|
|
34
43
|
warn_and_exit <<~WARN
|
|
35
|
-
The cable_ready npm package version (#{
|
|
44
|
+
👉 The cable_ready npm package version (#{npm_version}) does not match the Rubygem version (#{gem_version}).
|
|
45
|
+
|
|
36
46
|
To update the cable_ready npm package:
|
|
47
|
+
|
|
37
48
|
yarn upgrade cable_ready@#{gem_version}
|
|
38
49
|
WARN
|
|
39
50
|
end
|
|
40
51
|
end
|
|
41
52
|
|
|
42
53
|
def check_new_version_available
|
|
43
|
-
return unless Rails.env.development?
|
|
44
54
|
return if CableReady.config.on_new_version_available == :ignore
|
|
45
|
-
return
|
|
55
|
+
return if Rails.env.development? == false
|
|
56
|
+
return if using_preview_release?
|
|
46
57
|
begin
|
|
47
58
|
latest_version = URI.open("https://raw.githubusercontent.com/stimulusreflex/cable_ready/master/LATEST", open_timeout: 1, read_timeout: 1).read.strip
|
|
48
59
|
if latest_version != CableReady::VERSION
|
|
49
60
|
puts <<~WARN
|
|
50
61
|
|
|
51
|
-
There is a new version of CableReady available!
|
|
62
|
+
👉 There is a new version of CableReady available!
|
|
52
63
|
Current: #{CableReady::VERSION} Latest: #{latest_version}
|
|
53
64
|
|
|
54
65
|
If you upgrade, it is very important that you update BOTH Gemfile and package.json
|
|
@@ -58,31 +69,31 @@ class CableReady::SanityChecker
|
|
|
58
69
|
exit if CableReady.config.on_new_version_available == :exit
|
|
59
70
|
end
|
|
60
71
|
rescue
|
|
61
|
-
puts "CableReady #{CableReady::VERSION} update check skipped: connection timeout"
|
|
72
|
+
puts "👉 CableReady #{CableReady::VERSION} update check skipped: connection timeout"
|
|
62
73
|
end
|
|
63
74
|
end
|
|
64
75
|
|
|
65
76
|
private
|
|
66
77
|
|
|
67
|
-
def
|
|
68
|
-
|
|
78
|
+
def package_version_mismatch?
|
|
79
|
+
npm_version != gem_version
|
|
69
80
|
end
|
|
70
81
|
|
|
71
|
-
def
|
|
72
|
-
|
|
73
|
-
puts "CableReady #{CableReady::VERSION} update check skipped: pre-release build"
|
|
74
|
-
|
|
82
|
+
def using_preview_release?
|
|
83
|
+
preview = CableReady::VERSION.match?(LATEST_VERSION_FORMAT) == false
|
|
84
|
+
puts "👉 CableReady #{CableReady::VERSION} update check skipped: pre-release build" if preview
|
|
85
|
+
preview
|
|
75
86
|
end
|
|
76
87
|
|
|
77
88
|
def gem_version
|
|
78
89
|
@_gem_version ||= CableReady::VERSION.gsub(".pre", "-pre")
|
|
79
90
|
end
|
|
80
91
|
|
|
81
|
-
def
|
|
82
|
-
@
|
|
92
|
+
def npm_version
|
|
93
|
+
@_npm_version ||= find_npm_version
|
|
83
94
|
end
|
|
84
95
|
|
|
85
|
-
def
|
|
96
|
+
def find_npm_version
|
|
86
97
|
if (match = search_file(package_json_path, regex: /version/))
|
|
87
98
|
match[JSON_VERSION_FORMAT, 1]
|
|
88
99
|
elsif (match = search_file(yarn_lock_path, regex: /^cable_ready/))
|
|
@@ -91,7 +102,7 @@ class CableReady::SanityChecker
|
|
|
91
102
|
end
|
|
92
103
|
|
|
93
104
|
def search_file(path, regex:)
|
|
94
|
-
return
|
|
105
|
+
return if File.exist?(path) == false
|
|
95
106
|
File.foreach(path).grep(regex).first
|
|
96
107
|
end
|
|
97
108
|
|
|
@@ -103,49 +114,38 @@ class CableReady::SanityChecker
|
|
|
103
114
|
Rails.root.join("yarn.lock")
|
|
104
115
|
end
|
|
105
116
|
|
|
106
|
-
def
|
|
107
|
-
|
|
117
|
+
def initializer_missing?
|
|
118
|
+
File.exist?(Rails.root.join("config", "initializers", "cable_ready.rb")) == false
|
|
108
119
|
end
|
|
109
120
|
|
|
110
121
|
def warn_and_exit(text)
|
|
111
|
-
puts
|
|
122
|
+
puts
|
|
123
|
+
puts "Heads up! 🔥"
|
|
124
|
+
puts
|
|
112
125
|
puts text
|
|
113
|
-
exit_with_info if CableReady.config.on_failed_sanity_checks == :exit
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def exit_with_info
|
|
117
126
|
puts
|
|
118
|
-
|
|
119
|
-
if File.exist?(initializer_path)
|
|
127
|
+
if CableReady.config.on_failed_sanity_checks == :exit
|
|
120
128
|
puts <<~INFO
|
|
121
|
-
|
|
122
|
-
you can add the following directive to the CableReady initializer,
|
|
123
|
-
which is located at #{initializer_path}
|
|
129
|
+
To ignore any warnings and start the application anyway, you can set the SKIP_SANITY_CHECK environment variable:
|
|
124
130
|
|
|
125
|
-
|
|
126
|
-
config.on_failed_sanity_checks = :warn
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
INFO
|
|
130
|
-
else
|
|
131
|
-
puts <<~INFO
|
|
132
|
-
If you know what you are doing and you want to start the application anyway,
|
|
133
|
-
you can create a CableReady initializer with the command:
|
|
134
|
-
|
|
135
|
-
bundle exec rails generate cable_ready:config
|
|
131
|
+
SKIP_SANITY_CHECK=true rails
|
|
136
132
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
#{initializer_path}
|
|
140
|
-
|
|
141
|
-
and then add the following directive:
|
|
133
|
+
To do this permanently, add the following directive to the CableReady initializer:
|
|
142
134
|
|
|
143
135
|
CableReady.configure do |config|
|
|
144
136
|
config.on_failed_sanity_checks = :warn
|
|
145
137
|
end
|
|
146
138
|
|
|
147
139
|
INFO
|
|
140
|
+
if initializer_missing?
|
|
141
|
+
puts <<~INFO
|
|
142
|
+
You can create a CableReady initializer with the command:
|
|
143
|
+
|
|
144
|
+
bundle exec rails generate cable_ready:initializer
|
|
145
|
+
|
|
146
|
+
INFO
|
|
147
|
+
end
|
|
148
|
+
exit false if Rails.env.test? == false
|
|
148
149
|
end
|
|
149
|
-
exit false unless Rails.env.test?
|
|
150
150
|
end
|
|
151
151
|
end
|