cable_ready 5.0.0.pre8 → 5.0.0.pre9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -542
- data/Gemfile.lock +16 -78
- data/IMPLEMENTATION.md +93 -0
- data/README.md +35 -6
- data/Rakefile +0 -8
- data/app/assets/javascripts/cable_ready.js +959 -0
- data/app/assets/javascripts/cable_ready.min.js +2 -0
- data/app/assets/javascripts/cable_ready.min.js.map +1 -0
- data/app/assets/javascripts/cable_ready.umd.js +910 -0
- data/app/assets/javascripts/cable_ready.umd.min.js +2 -0
- data/app/assets/javascripts/cable_ready.umd.min.js.map +1 -0
- data/app/helpers/cable_ready_helper.rb +2 -1
- data/app/models/concerns/cable_ready/updatable/model_updatable_callbacks.rb +3 -3
- data/app/models/concerns/cable_ready/updatable.rb +55 -10
- data/cable_ready.gemspec +42 -0
- data/lib/cable_ready/engine.rb +40 -0
- data/lib/cable_ready/importmap.rb +2 -0
- data/lib/cable_ready/version.rb +1 -1
- data/lib/cable_ready.rb +1 -18
- data/package.json +51 -0
- data/rollup.config.js +75 -0
- data/test/dummy/app/models/dugong.rb +4 -0
- data/test/dummy/db/migrate/20220329222959_create_dugongs.rb +8 -0
- data/test/dummy/db/migrate/20220329230221_create_active_storage_tables.active_storage.rb +36 -0
- data/test/dummy/db/schema.rb +36 -1
- data/test/dummy/test/models/dugong_test.rb +7 -0
- data/test/lib/cable_ready/updatable_test.rb +23 -0
- data/yarn.lock +2817 -0
- metadata +145 -54
data/Gemfile.lock
CHANGED
@@ -2,7 +2,12 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
cable_ready (5.0.0.pre8)
|
5
|
-
|
5
|
+
actioncable (>= 5.2)
|
6
|
+
actionpack (>= 5.2)
|
7
|
+
actionview (>= 5.2)
|
8
|
+
activerecord (>= 5.2)
|
9
|
+
activesupport (>= 5.2)
|
10
|
+
railties (>= 5.2)
|
6
11
|
thread-local (>= 1.1.0)
|
7
12
|
|
8
13
|
GEM
|
@@ -67,70 +72,17 @@ GEM
|
|
67
72
|
minitest (>= 5.1)
|
68
73
|
tzinfo (~> 2.0)
|
69
74
|
zeitwerk (~> 2.3)
|
70
|
-
addressable (2.8.0)
|
71
|
-
public_suffix (>= 2.0.2, < 5.0)
|
72
75
|
ast (2.4.2)
|
73
|
-
async (1.30.1)
|
74
|
-
console (~> 1.10)
|
75
|
-
nio4r (~> 2.3)
|
76
|
-
timers (~> 4.1)
|
77
|
-
async-http (0.56.5)
|
78
|
-
async (>= 1.25)
|
79
|
-
async-io (>= 1.28)
|
80
|
-
async-pool (>= 0.2)
|
81
|
-
protocol-http (~> 0.22.0)
|
82
|
-
protocol-http1 (~> 0.14.0)
|
83
|
-
protocol-http2 (~> 0.14.0)
|
84
|
-
async-http-faraday (0.11.0)
|
85
|
-
async-http (~> 0.42)
|
86
|
-
faraday
|
87
|
-
async-io (1.32.2)
|
88
|
-
async
|
89
|
-
async-pool (0.3.9)
|
90
|
-
async (>= 1.25)
|
91
76
|
builder (3.2.4)
|
92
77
|
coderay (1.1.3)
|
93
78
|
concurrent-ruby (1.1.9)
|
94
|
-
console (1.13.1)
|
95
|
-
fiber-local
|
96
79
|
crass (1.0.6)
|
97
80
|
erubi (1.10.0)
|
98
|
-
|
99
|
-
faraday-em_http (~> 1.0)
|
100
|
-
faraday-em_synchrony (~> 1.0)
|
101
|
-
faraday-excon (~> 1.1)
|
102
|
-
faraday-httpclient (~> 1.0.1)
|
103
|
-
faraday-net_http (~> 1.0)
|
104
|
-
faraday-net_http_persistent (~> 1.1)
|
105
|
-
faraday-patron (~> 1.0)
|
106
|
-
faraday-rack (~> 1.0)
|
107
|
-
multipart-post (>= 1.2, < 3)
|
108
|
-
ruby2_keywords (>= 0.0.4)
|
109
|
-
faraday-em_http (1.0.0)
|
110
|
-
faraday-em_synchrony (1.0.0)
|
111
|
-
faraday-excon (1.1.0)
|
112
|
-
faraday-http-cache (2.2.0)
|
113
|
-
faraday (>= 0.8)
|
114
|
-
faraday-httpclient (1.0.1)
|
115
|
-
faraday-net_http (1.0.1)
|
116
|
-
faraday-net_http_persistent (1.2.0)
|
117
|
-
faraday-patron (1.0.0)
|
118
|
-
faraday-rack (1.0.0)
|
119
|
-
fiber-local (1.0.0)
|
120
|
-
github_changelog_generator (1.16.4)
|
121
|
-
activesupport
|
122
|
-
async (>= 1.25.0)
|
123
|
-
async-http-faraday
|
124
|
-
faraday-http-cache
|
125
|
-
multi_json
|
126
|
-
octokit (~> 4.6)
|
127
|
-
rainbow (>= 2.2.1)
|
128
|
-
rake (>= 10.0)
|
129
|
-
globalid (0.5.2)
|
81
|
+
globalid (1.0.0)
|
130
82
|
activesupport (>= 5.0)
|
131
83
|
i18n (1.8.11)
|
132
84
|
concurrent-ruby (~> 1.0)
|
133
|
-
loofah (2.
|
85
|
+
loofah (2.13.0)
|
134
86
|
crass (~> 1.0.2)
|
135
87
|
nokogiri (>= 1.5.9)
|
136
88
|
magic_frozen_string_literal (1.2.0)
|
@@ -141,30 +93,19 @@ GEM
|
|
141
93
|
mini_mime (1.1.2)
|
142
94
|
minitest (5.14.4)
|
143
95
|
mocha (1.13.0)
|
144
|
-
multi_json (1.15.0)
|
145
|
-
multipart-post (2.1.1)
|
146
96
|
nio4r (2.5.8)
|
147
|
-
nokogiri (1.
|
97
|
+
nokogiri (1.13.3-x86_64-darwin)
|
98
|
+
racc (~> 1.4)
|
99
|
+
nokogiri (1.13.3-x86_64-linux)
|
148
100
|
racc (~> 1.4)
|
149
|
-
octokit (4.21.0)
|
150
|
-
faraday (>= 0.9)
|
151
|
-
sawyer (~> 0.8.0, >= 0.5.3)
|
152
101
|
parallel (1.21.0)
|
153
102
|
parser (3.0.2.0)
|
154
103
|
ast (~> 2.4.1)
|
155
|
-
protocol-hpack (1.4.2)
|
156
|
-
protocol-http (0.22.5)
|
157
|
-
protocol-http1 (0.14.2)
|
158
|
-
protocol-http (~> 0.22)
|
159
|
-
protocol-http2 (0.14.2)
|
160
|
-
protocol-hpack (~> 1.4)
|
161
|
-
protocol-http (~> 0.18)
|
162
104
|
pry (0.14.1)
|
163
105
|
coderay (~> 1.1)
|
164
106
|
method_source (~> 1.0)
|
165
107
|
pry-nav (1.0.0)
|
166
108
|
pry (>= 0.9.10, < 0.15)
|
167
|
-
public_suffix (4.0.6)
|
168
109
|
racc (1.6.0)
|
169
110
|
rack (2.2.3)
|
170
111
|
rack-test (1.1.0)
|
@@ -214,14 +155,10 @@ GEM
|
|
214
155
|
rubocop (>= 1.7.0, < 2.0)
|
215
156
|
rubocop-ast (>= 0.4.0)
|
216
157
|
ruby-progressbar (1.11.0)
|
217
|
-
ruby2_keywords (0.0.5)
|
218
|
-
sawyer (0.8.2)
|
219
|
-
addressable (>= 2.3.5)
|
220
|
-
faraday (> 0.8, < 2.0)
|
221
158
|
sprockets (4.0.2)
|
222
159
|
concurrent-ruby (~> 1.0)
|
223
160
|
rack (> 1, < 3)
|
224
|
-
sprockets-rails (3.4.
|
161
|
+
sprockets-rails (3.4.2)
|
225
162
|
actionpack (>= 5.2)
|
226
163
|
activesupport (>= 5.2)
|
227
164
|
sprockets (>= 3.0.0)
|
@@ -233,7 +170,6 @@ GEM
|
|
233
170
|
standard
|
234
171
|
thor (1.1.0)
|
235
172
|
thread-local (1.1.0)
|
236
|
-
timers (4.3.3)
|
237
173
|
tzinfo (2.0.4)
|
238
174
|
concurrent-ruby (~> 1.0)
|
239
175
|
unicode-display_width (2.1.0)
|
@@ -243,18 +179,20 @@ GEM
|
|
243
179
|
zeitwerk (2.5.1)
|
244
180
|
|
245
181
|
PLATFORMS
|
182
|
+
x86_64-darwin-18
|
183
|
+
x86_64-darwin-19
|
246
184
|
x86_64-linux
|
247
185
|
|
248
186
|
DEPENDENCIES
|
249
187
|
cable_ready!
|
250
|
-
github_changelog_generator
|
251
188
|
magic_frozen_string_literal
|
252
189
|
mocha
|
253
190
|
pry
|
254
191
|
pry-nav
|
192
|
+
rails (>= 5.2)
|
255
193
|
rake
|
256
194
|
sqlite3
|
257
195
|
standardrb
|
258
196
|
|
259
197
|
BUNDLED WITH
|
260
|
-
2.2.
|
198
|
+
2.2.33
|
data/IMPLEMENTATION.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# CableReady Language Implementation Project
|
2
|
+
|
3
|
+
We believe that CableReady can become the universal standard tool for developers to dynamically control client browsers from the server. While the project has roots in the Ruby on Rails community, the JS client is unopinionated about how the simple JSON structure that it consumes was created.
|
4
|
+
|
5
|
+
We would like to announce support for Python, Go, C#, Java, PHP and NodeJS server libraries in early 2022. While there's a broad set of features a server library could implement, there's a baseline that we'd like to make sure all implementations can offer.
|
6
|
+
|
7
|
+
## Background
|
8
|
+
|
9
|
+
CableReady was started in 2017 by Nate Hopkins. It predates LiveView and the HTML-on-the-wire trend by 18 months. It sees roughly 15,000 downloads per week and offers 36 different [operations](https://cableready.stimulusreflex.com/v/v5/reference/operations).
|
10
|
+
|
11
|
+
CableReady is currently a client-side JS module and a server-side Ruby module.
|
12
|
+
|
13
|
+
## Key concepts
|
14
|
+
|
15
|
+
- available everywhere
|
16
|
+
- multiple operations per payload
|
17
|
+
- schemaless
|
18
|
+
- simple JSON wire format
|
19
|
+
- method chaining
|
20
|
+
- transport agnostic
|
21
|
+
- extensible via custom operations
|
22
|
+
|
23
|
+
### Available everywhere
|
24
|
+
|
25
|
+
Rails developers can access a `cable_ready` singleton from just about anywhere in their application, and we believe it's a big part of the secret sauce. While every language and framework has their own idioms, we encourage implementors to remove barriers and make it easy to call CableReady anywhere it could be useful.
|
26
|
+
|
27
|
+
https://cableready.stimulusreflex.com/v/v5/cableready-everywhere
|
28
|
+
|
29
|
+
### Operations and their options
|
30
|
+
|
31
|
+
Operations are the basic atomic unit of activity in CableReady. Each operation typically has a very specific focus and often mimics the DOM JS spec for the activity in question. Operations have options passed to them which specify their exact behavior.
|
32
|
+
|
33
|
+
Multiple operations can be prepared together. They will be executed in the order that they were created. Different operation types can be mixed together in one payload.
|
34
|
+
|
35
|
+
The Ruby implementation offers two interfaces; the (original) primary mechanism delivers the operations to a WebSocket channel in what we refer to as a "broadcast". The other - known as "cable car" - returns a JSON string that can be sent, persisted or displayed for any purpose.
|
36
|
+
|
37
|
+
### Schemaless
|
38
|
+
|
39
|
+
CableReady operations each have their own mandatory and optional options, along with options that are provided to every operation by the library. However, arbitrary additional options can be passed to an operation and they will be passed to the client. This makes it easy for CableReady to form the basis of much larger projects, such as StimulusReflex.
|
40
|
+
|
41
|
+
### JSON wire format
|
42
|
+
|
43
|
+
As of v5.0, the CableReady JSON wire format is an array of objects, where each object represents one operation. It's intentionally very simple.
|
44
|
+
|
45
|
+
```json
|
46
|
+
[{\"message\":\"Hello!\",\"operation\":\"consoleLog\"}]
|
47
|
+
```
|
48
|
+
|
49
|
+
Each operation has **camelCased** key/value pairs that convey options. Every operation must have an `operation` value, or the client will raise an exception.
|
50
|
+
|
51
|
+
### Method chaining
|
52
|
+
|
53
|
+
Developer experience is a high priority. We take pride in the readability and expressiveness offered by our server API. The basic pseudocode structure we provide looks like:
|
54
|
+
|
55
|
+
```rb
|
56
|
+
cable_ready[:foo].operation(options).broadcast
|
57
|
+
```
|
58
|
+
|
59
|
+
In other words, the first method `cable_ready` starts a method chain by returning `self`, and then each operation is a method that also returns the chain started by the initial method. In this way, you can chain together as many operations as you like. Finally, we have a `broadcast` method which takes the current chain and broadcasts it via WebSockets to the `:foo` channel.
|
60
|
+
|
61
|
+
We also have our "cable car" interface which emits JSON when `to_json` is called. This makes it perfect for responding to Ajax fetch requests:
|
62
|
+
|
63
|
+
```rb
|
64
|
+
cable_car.operation(options).to_json
|
65
|
+
```
|
66
|
+
|
67
|
+
The `cable_car` might be assembled in steps, perhaps via a control loop:
|
68
|
+
|
69
|
+
```rb
|
70
|
+
inspiration = cable_car.console_log(message: "Hello there!").dispatch_event(name: "fred", detail: {inspiring: true})
|
71
|
+
3.times do |i|
|
72
|
+
inspiration.console_log(message: "Still here: #{i}")
|
73
|
+
end
|
74
|
+
inspiration.to_json
|
75
|
+
```
|
76
|
+
|
77
|
+
The main expectation that should hold between languages is that you will start the chain with a command, add one or many operation methods, and then execute the chain.
|
78
|
+
|
79
|
+
### Transport agnostic
|
80
|
+
|
81
|
+
CableReady started its life as a WebSocket library, but the neutral JSON format has potential far beyond just WebSocket usage. We now frequently return CableReady JSON payloads via Ajax as well. There's nothing stopping you from embedding payloads into a DOM element attribute, for example.
|
82
|
+
|
83
|
+
We believe that a minimally viable CableReady server library must be able to produce compatible JSON. There's no hard requirement that it interface with WebSockets, although we do find this to be a major sweet spot and will do our best to provide support.
|
84
|
+
|
85
|
+
### Custom operations
|
86
|
+
|
87
|
+
While CableReady ships with an impressive number of operations out of the box, users should be able to add their own operations. Admittedly, the method used to dynamically create all of the methods for each operation is the [most sophisticated](https://github.com/stimulusreflex/cable_ready/blob/master/lib/cable_ready/operation_builder.rb) one in our framework, but again, we're here to help.
|
88
|
+
|
89
|
+
https://cableready.stimulusreflex.com/v/v5/customization#custom-operations
|
90
|
+
|
91
|
+
# Get involved!
|
92
|
+
|
93
|
+
We have a wonderful community with over 1600 folks on our Discord server, helping people get started. Come join https://discord.gg/stimulus-reflex and drop by the #cable_ready channel with any questions.
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<p align="center">
|
2
|
-
<img src="https://
|
2
|
+
<img src="https://raw.githubusercontent.com/stimulusreflex/cable_ready/master/assets/cable-ready-logo-with-copy.svg" width="360" />
|
3
3
|
<h1 align="center">Welcome to CableReady 👋</h1>
|
4
4
|
<p align="center">
|
5
5
|
<a href="https://rubygems.org/gems/cable_ready">
|
@@ -60,12 +60,41 @@ to learn more about ActionCable before proceeding.
|
|
60
60
|
|
61
61
|
## 🚀 Install
|
62
62
|
|
63
|
+
### Rubygem
|
64
|
+
|
63
65
|
```sh
|
64
|
-
bundle add cable_ready
|
66
|
+
bundle add cable_ready
|
65
67
|
```
|
66
68
|
|
67
|
-
|
69
|
+
### JavaScript
|
70
|
+
|
71
|
+
There are a few ways to install the CableReady JavaScript client, depending on your application setup.
|
72
|
+
|
73
|
+
#### ESBuild / Webpacker
|
74
|
+
|
75
|
+
```sh
|
76
|
+
yarn add cable_ready
|
77
|
+
```
|
78
|
+
|
79
|
+
#### Import maps:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# config/importmap.rb
|
68
83
|
|
84
|
+
# ...
|
85
|
+
|
86
|
+
pin 'cable_ready', to: 'cable_ready.min.js', preload: true
|
87
|
+
```
|
88
|
+
|
89
|
+
#### Rails Asset pipeline (Sprockets):
|
90
|
+
|
91
|
+
```html+erb
|
92
|
+
<!-- app/views/layouts/application.html.erb -->
|
93
|
+
|
94
|
+
<%= javascript_include_tag "cable_ready.umd.min.js", "data-turbo-track": "reload" %>
|
95
|
+
```
|
96
|
+
|
97
|
+
Checkout the [documentation](https://cableready.stimulusreflex.com) to continue!
|
69
98
|
|
70
99
|
## 🙏 Contributing
|
71
100
|
|
@@ -84,13 +113,13 @@ Please run `./bin/standardize` prior submitting pull requests.
|
|
84
113
|
|
85
114
|
1. Make sure that you run `yarn` and `bundle` to pick up the latest.
|
86
115
|
1. Bump version number at `lib/cable_ready/version.rb`. Pre-release versions use `.preN`
|
87
|
-
1. Run `rake build`
|
116
|
+
1. Run `rake build` and `yarn build`
|
88
117
|
1. Commit and push changes to github
|
89
118
|
1. Run `rake release`
|
90
119
|
1. Run `yarn publish --no-git-tag-version`
|
91
120
|
1. Yarn will prompt you for the new version. Pre-release versions use `-preN`
|
92
|
-
1.
|
93
|
-
1.
|
121
|
+
1. Commit and push changes to GitHub
|
122
|
+
1. Create a new release on GitHub ([here](https://github.com/stimulusreflex/stimulus_reflex/releases)) and generate the changelog for the stable release for it
|
94
123
|
|
95
124
|
## 📝 License
|
96
125
|
|
data/Rakefile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
-
require "github_changelog_generator/task"
|
5
4
|
require "rake/testtask"
|
6
5
|
require "pry"
|
7
6
|
|
@@ -14,10 +13,3 @@ Rake::TestTask.new(:test) do |t|
|
|
14
13
|
t.verbose = true
|
15
14
|
t.warning = false
|
16
15
|
end
|
17
|
-
|
18
|
-
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
19
|
-
config.user = "stimulusreflex"
|
20
|
-
config.project = "cable_ready"
|
21
|
-
config.exclude_labels = %w[duplicate question invalid wontfix nodoc]
|
22
|
-
config.token = ENV["GITHUB_CHANGELOG_GENERATOR_TOKEN"]
|
23
|
-
end
|