rubocop-anycable-rails 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +290 -0
- data/MIT-LICENSE +20 -0
- data/README.md +102 -0
- data/lib/anycable/rails/compatibility/rubocop.rb +4 -0
- data/lib/anycable/rails/rubocop/config/default.yml +14 -0
- data/lib/anycable/rails/rubocop/cops/anycable/instance_vars.rb +50 -0
- data/lib/anycable/rails/rubocop/cops/anycable/periodical_timers.rb +29 -0
- data/lib/anycable/rails/rubocop/cops/anycable/stream_from.rb +98 -0
- data/lib/anycable/rails/rubocop.rb +27 -0
- data/lib/anycable/rails/version.rb +7 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6ddfd12d96d389d6088337f9d048945530f03e2e20777e9c98caa94d98da7da0
|
4
|
+
data.tar.gz: 26a5d8cad741e9c52c0844ddb5e2ed3974cb2767d476aeb0f875bc306c223438
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: efbc9d2aa537754c2aba273edf7f95c1e2053f962bf137525d6ecc8a2a0dac45e840f005b2910f2d0208ebec4405c68a9071af146a4425c01e52048b6c3b7472
|
7
|
+
data.tar.gz: f602460e769acd54bc49e321481fb4c4e57bd074fa965193c43f1e9995b2518e08cb3e47c1a7e302ce6c472a51effa5e1c206a2be4c23783854b93a3adcb7104
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,290 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
## master
|
4
|
+
|
5
|
+
## 1.5.5 (2024-12-12)
|
6
|
+
|
7
|
+
- Publish RuboCop cops as a separate gem (`rubocop-anycable-rails`). ([@palkan][])
|
8
|
+
|
9
|
+
- Upgrade RuboCop cops. ([@palkan][])
|
10
|
+
|
11
|
+
## 1.5.4 (2024-10-08)
|
12
|
+
|
13
|
+
- Add [actioncable-next](https://github.com/anycable/actioncable-next) support. ([@palkan][])
|
14
|
+
|
15
|
+
- Generate `anycable.toml` in `anycable:setup` generator. ([@palkan][])
|
16
|
+
|
17
|
+
## 1.5.3 (2024-09-12)
|
18
|
+
|
19
|
+
- Set upper limit on supported Rails versions. ([@palkan][])
|
20
|
+
|
21
|
+
The current release series is unlikely to not work with Rails 8. Let's prevent using them together.
|
22
|
+
|
23
|
+
## 1.5.2 (2024-07-01)
|
24
|
+
|
25
|
+
- Automatically add `Warden::Manager` to the AnyCable middleware stack when Devise is present. ([@lHydra][])
|
26
|
+
|
27
|
+
## 1.5.1 (2024-04-05)
|
28
|
+
|
29
|
+
- Add `anycable-rails-core.rb` to avoid adding `require: ["anycable-rails"]` to Gemfiles manually. ([@palkan][])
|
30
|
+
|
31
|
+
- Mount HTTP RPC independently of the current Action Cable adapter. ([@palkan][])
|
32
|
+
|
33
|
+
This makes it possible to use it in tests without manually adding the middleware.
|
34
|
+
|
35
|
+
## 1.5.0 (2024-04-01)
|
36
|
+
|
37
|
+
- Allow specifying the _whispering_ stream via `#stream_from(..., whisper: true)`. ([@palkan][])
|
38
|
+
|
39
|
+
You can use specify the stream to use for _whispering_ (client-initiated broadcasts) by adding `whisper: true` to the `#stream_from` (or `#stream_for`) method call.
|
40
|
+
|
41
|
+
NOTE: This feature is only supported when using AnyCable server and ignored otherwise.
|
42
|
+
|
43
|
+
- Support passing objects to `ActionCable.server.broadcast`. ([@palkan][])
|
44
|
+
|
45
|
+
Make it possible to call `ActionCable.server.broadcast(user, data)` or `ActionCable.server.broadcast([user, :context], data)`. This is a companion functionality for `#signed_stream_name`.
|
46
|
+
|
47
|
+
- Added `websocket_url` configuration option to specify the URL of AnyCable server. ([@palkan][])
|
48
|
+
|
49
|
+
It's used to configure `config.action_cable.url` if AnyCable is activated. No need to set up it manually.
|
50
|
+
|
51
|
+
- Added `rails g anycable:bin` to create a binstub to run AnyCable server. ([@palkan][])
|
52
|
+
|
53
|
+
- Added signed streams helpers. ([@palkan][])
|
54
|
+
|
55
|
+
You can use `#signed_stream_name(streamable)` to generate a signed stream name.
|
56
|
+
|
57
|
+
- Added JWT authentication helpers. ([@palkan][])
|
58
|
+
|
59
|
+
No more need in a separate `anycable-rails-jwt` gem.
|
60
|
+
|
61
|
+
## 1.4.5
|
62
|
+
|
63
|
+
- Restrict `anycable` gem version.
|
64
|
+
|
65
|
+
## 1.4.4 (2024-03-08) 🌷
|
66
|
+
|
67
|
+
- Minor fixes
|
68
|
+
|
69
|
+
## 1.4.3 (2023-12-13)
|
70
|
+
|
71
|
+
- Fix console logging in Rails 7.1 when the app's logger has no broadcast support. ([@palkan][])
|
72
|
+
|
73
|
+
## 1.4.2 (2023-10-15)
|
74
|
+
|
75
|
+
- Print warning if the database pool size is less than RPC pool size. ([@palkan][])
|
76
|
+
|
77
|
+
- Add support for broadcast options (e.g., `exclude_socket`) and `broadcast ..., to_others: true`. ([@palkan][])
|
78
|
+
|
79
|
+
- Add `batch_broadcasts` option to automatically batch broadcasts for code wrapped in Rails executor. ([@palkan][])
|
80
|
+
|
81
|
+
- Fix broadcast logging in Rails 7.1. ([@iuri-gg][])
|
82
|
+
|
83
|
+
## 1.4.1 (2023-09-27)
|
84
|
+
|
85
|
+
- Fix compatibility with Rails 7.1. ([@palkan][])
|
86
|
+
|
87
|
+
- Upgrade `anycable:setup` generator to support v1.4 features. ([@palkan][])
|
88
|
+
|
89
|
+
Add `bin/anycable-go` to use `anycable-go` locally. Add `--rpc=http` to configure for using AnyCable with HTTP RPC.
|
90
|
+
|
91
|
+
## 1.4.0 (2023-07-07)
|
92
|
+
|
93
|
+
- Add HTTP RPC integration. ([@palkan][])
|
94
|
+
|
95
|
+
Specify `http_rpc_mounth_path` in your `anycable.yml` to enable HTTP RPC.
|
96
|
+
|
97
|
+
- Fix `anycable:download` command. ([@palkan][])
|
98
|
+
|
99
|
+
Detect MacOS arm64, create target bin path if it doesn't exist.
|
100
|
+
|
101
|
+
## 1.3.7 (2023-02-28)
|
102
|
+
|
103
|
+
- Fix `anycable` gem dependency constraints.
|
104
|
+
|
105
|
+
- Require Ruby 2.7+.
|
106
|
+
|
107
|
+
## 1.3.6 (2023-02-28)
|
108
|
+
|
109
|
+
- Handle `nil` streams gracefully. ([@palkan][])
|
110
|
+
|
111
|
+
- Report exceptions via the `Rails.error.report` interface. ([@palkan][])
|
112
|
+
|
113
|
+
## 1.3.5 (2023-01-04)
|
114
|
+
|
115
|
+
- Make misconfiguration error more informative. ([@palkan][])
|
116
|
+
|
117
|
+
## 1.3.4 (2022-06-28)
|
118
|
+
|
119
|
+
- Add support and backport for Connection command callbacks. ([@palkan][])
|
120
|
+
|
121
|
+
## 1.3.3 (2022-04-20)
|
122
|
+
|
123
|
+
- Added `sid` (unique connection identifier) field to the `welcome` message if present. ([@palkan][])
|
124
|
+
|
125
|
+
- Fixed handling Ruby Logger incompatible loggers. ([@palkan][])
|
126
|
+
|
127
|
+
## 1.3.2 (2022-03-04)
|
128
|
+
|
129
|
+
- Allow Ruby 2.6.
|
130
|
+
|
131
|
+
## 1.3.1 (2022-02-28)
|
132
|
+
|
133
|
+
- Fix Action Cable Channel patch to not change methods signatures. ([@palkan][])
|
134
|
+
|
135
|
+
Otherwise it could lead to conflicts with other patches.
|
136
|
+
|
137
|
+
## 1.3.0 (2022-02-21)
|
138
|
+
|
139
|
+
- Introduce `AnyCable::Rails.extend_adapter!` to make any pubsub adapter AnyCable-compatible. ([@palkan][])
|
140
|
+
|
141
|
+
- Refactored Action Cable patching to preserve original functionality and avoid monkey-patching collisions. ([@palkan][])
|
142
|
+
|
143
|
+
## 1.2.1 (2022-01-31)
|
144
|
+
|
145
|
+
- Add a temporary fix to be compatible with `sentry-rails`. ([@palkan][])
|
146
|
+
|
147
|
+
See [#165](https://github.com/anycable/anycable-rails/issues/165).
|
148
|
+
|
149
|
+
- Run embedded RPC server only if `any_cable` adapter is used for Action Cable. ([@palkan][])
|
150
|
+
|
151
|
+
## 1.2.0 (2021-12-21) 🎄
|
152
|
+
|
153
|
+
- Drop Rails 5 support.
|
154
|
+
|
155
|
+
- Drop Ruby 2.6 support.
|
156
|
+
|
157
|
+
## 1.1.4 (2021-11-11)
|
158
|
+
|
159
|
+
- Added `Connection#state_attr_accessor`. ([@palkan][])
|
160
|
+
|
161
|
+
## 1.1.3 (2021-10-11)
|
162
|
+
|
163
|
+
- Relax Action Cable dependency. ([@palkan][])
|
164
|
+
|
165
|
+
Action Cable 5.1 is allowed (though not recommended).
|
166
|
+
|
167
|
+
## 1.1.2 (2021-06-23)
|
168
|
+
|
169
|
+
- Bring back dependency on `anycable` (instead of `anycable-core`). ([@palkan][])
|
170
|
+
|
171
|
+
Make it easier to get started by adding just a single gem.
|
172
|
+
|
173
|
+
## 1.1.1 (2021-06-08)
|
174
|
+
|
175
|
+
- Updated documentation links in the generator. ([@palkan][])
|
176
|
+
|
177
|
+
## 1.1.0 🚸 (2021-06-01)
|
178
|
+
|
179
|
+
- No changes since 1.1.0.rc1.1.
|
180
|
+
|
181
|
+
## 1.1.0.rc1.1 (2021-05-12)
|
182
|
+
|
183
|
+
- Fixed config loading regression introduced in 1.1.0.rc1.
|
184
|
+
|
185
|
+
## 1.1.0.rc1 (2021-05-12)
|
186
|
+
|
187
|
+
- Adding `anycable` or `grpc` gem as an explicit dependency is required.
|
188
|
+
|
189
|
+
Now, `anycable-rails` depends on `anycable-core`, which doesn't include gRPC server implementation.
|
190
|
+
You should either add `anycable` or `grpc` (>= 1.37) gem as an explicit dependency.
|
191
|
+
|
192
|
+
- Add option to embed AnyCable RPC into a Rails server process. ([@palkan][])
|
193
|
+
|
194
|
+
Set `embedded: true` in the configuration to launch RPC along with `rails s` (only for Rails 6.1+).
|
195
|
+
|
196
|
+
- **Ruby >= 2.6** is required.
|
197
|
+
- **Rails >= 6.0** is required.
|
198
|
+
|
199
|
+
## 1.0.7 (2021-03-05)
|
200
|
+
|
201
|
+
- Ruby 3 compatibility. ([@palkan][])
|
202
|
+
|
203
|
+
## 1.0.6 (2021-02-25)
|
204
|
+
|
205
|
+
- Keep an explicit list of instance vars to ignore in compatibility checks. ([@palkan][])
|
206
|
+
|
207
|
+
You can ignore custom vars by adding them to the list: `AnyCable::Compatibility::IGNORE_INSTANCE_VARS << :@my_var`.
|
208
|
+
|
209
|
+
## 1.0.5 (2021-02-24)
|
210
|
+
|
211
|
+
- Fixed bug with compatibility false negatives in development. ([@palkan][])
|
212
|
+
|
213
|
+
See [#151](https://github.com/anycable/anycable-rails/issues/151).
|
214
|
+
|
215
|
+
## 1.0.4 (2020-10-02)
|
216
|
+
|
217
|
+
- Relax Rails dependencies. ([@palkan][])
|
218
|
+
|
219
|
+
Only add `actioncable` and `globalid` as runtime dependencies, not the whole `rails`.
|
220
|
+
|
221
|
+
## 1.0.3 (2020-09-16)
|
222
|
+
|
223
|
+
- Fixed bug with building a request object when session store is absent. ([@palkan][])
|
224
|
+
|
225
|
+
## 1.0.2 (2020-09-08)
|
226
|
+
|
227
|
+
- Added missing channel state support to `#unsubscribed` callbacks. ([@palkan][])
|
228
|
+
|
229
|
+
## 1.0.1 (2020-07-07)
|
230
|
+
|
231
|
+
- Fixed patching Action Cable testing classes. ([@palkan][])
|
232
|
+
|
233
|
+
## 1.0.0 (2020-07-01)
|
234
|
+
|
235
|
+
- Support `rescue_from` in connections (Rails 6.1). ([@palkan][])
|
236
|
+
|
237
|
+
- Make AnyCable patches compatible with Action Cable testing. ([@palkan][])
|
238
|
+
|
239
|
+
- Do not add localhost `redis_url` to `anycable.yml` when Docker development method is chosen in `anycable:setup`. ([@palkan][])
|
240
|
+
|
241
|
+
- Fix connection identifiers deserialization regression. ([@palkan][])
|
242
|
+
|
243
|
+
Using non-strings or non-GlobalId-encoded objects was broken.
|
244
|
+
|
245
|
+
- Improve `anycable:setup` generator. ([@palkan][])
|
246
|
+
|
247
|
+
Update Docker snippet, do not enable persistent sessions automatically,
|
248
|
+
fix setting `config.action_cable.url` in environment configuration.
|
249
|
+
|
250
|
+
- Add `state_attr_accessor` for channels. ([@palkan][])
|
251
|
+
|
252
|
+
Just like `attr_accessor` but "persists" the state between RPC calls.
|
253
|
+
|
254
|
+
- Add `Channel#stop_stream_from` support. ([@palkan][])
|
255
|
+
|
256
|
+
- Add `RemoteConnections` support. ([@palkan][])
|
257
|
+
|
258
|
+
- Add `AnyCable::Rails.enabled?` method which returns true if Action Cable uses AnyCable adapter. ([@palkan][])
|
259
|
+
|
260
|
+
- Add `anycable:download` generator to download `anycable-go` binary. ([@palkan][])
|
261
|
+
|
262
|
+
- **Ruby 2.5+ is required**. ([@palkan][])
|
263
|
+
|
264
|
+
- Support `disconnect` messages. ([@palkan][])
|
265
|
+
|
266
|
+
Added in Rails 6 (see [PR#34194](https://github.com/rails/rails/pull/34194)).
|
267
|
+
|
268
|
+
- Add ability to persist _dirty_ `request.session` between RPC calls. ([@palkan][])
|
269
|
+
|
270
|
+
This feature emulates the Action Cable behaviour where it's possible to use `request.session` as a shared Hash-like store.
|
271
|
+
This could be used by some applications (e.g., [StimulusReflex](https://github.com/hopsoft/stimulus_reflex)-based).
|
272
|
+
|
273
|
+
You must turn this feature on by setting `persistent_session_enabled: true` in the AnyCable configuration.
|
274
|
+
|
275
|
+
- Add ability to use Rack middlewares when build a request for a connection. ([@bibendi][])
|
276
|
+
|
277
|
+
- Add set up generator to configure a Rails application by running `bin/rails g anycable:setup`. ([@bibendi][])
|
278
|
+
|
279
|
+
- Require a minimum version of Ruby when installing the gem. ([@bibendi][])
|
280
|
+
|
281
|
+
- Add ability to develop the gem with Docker. ([@bibendi][])
|
282
|
+
|
283
|
+
See [Changelog](https://github.com/anycable/anycable-rails/blob/0-6-stable/CHANGELOG.md) for versions <1.0.0.
|
284
|
+
|
285
|
+
[@palkan]: https://github.com/palkan
|
286
|
+
[@alekseyl]: https://github.com/alekseyl
|
287
|
+
[@DmitryTsepelev]: https://github.com/DmitryTsepelev
|
288
|
+
[@sponomarev]: https://github.com/sponomarev
|
289
|
+
[@bibendi]: https://github.com/bibendi
|
290
|
+
[@lHydra]: http://github.com/lHydra
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017-2023 palkan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/anycable-rails.svg)](https://rubygems.org/gems/anycable-rails)
|
2
|
+
[![Build](https://github.com/anycable/anycable-rails/workflows/Build/badge.svg)](https://github.com/anycable/anycable-rails/actions)
|
3
|
+
[![Documentation](https://img.shields.io/badge/docs-link-brightgreen.svg)](https://docs.anycable.io/rails/getting_started)
|
4
|
+
|
5
|
+
# AnyCable Rails
|
6
|
+
|
7
|
+
AnyCable allows you to use any WebSocket server (written in any language) as a replacement for built-in Rails Action Cable server.
|
8
|
+
|
9
|
+
With AnyCable you can use channels, client-side JS, broadcasting - (almost) all that you can do with Action Cable.
|
10
|
+
|
11
|
+
💾 [Example Application](https://github.com/anycable/anycable_rails_demo)
|
12
|
+
|
13
|
+
📑 [Documentation](https://docs.anycable.io/rails/getting_started).
|
14
|
+
|
15
|
+
> [AnyCable Pro](https://docs.anycable.io/pro) has been launched 🚀
|
16
|
+
|
17
|
+
<a href="https://evilmartians.com/">
|
18
|
+
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
|
19
|
+
|
20
|
+
## Requirements
|
21
|
+
|
22
|
+
- Ruby >= 3.1
|
23
|
+
- Rails >= 6.0\*
|
24
|
+
|
25
|
+
\* Recent `anycable-rails` versions only work with Rails 8+; older versions compatible with Rails 6 and Rails 7 still receive fixes and minor updates (patch releases).
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Add `anycable-rails` gem to your Gemfile:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem "anycable-rails"
|
33
|
+
```
|
34
|
+
|
35
|
+
### Interactive set up
|
36
|
+
|
37
|
+
After the gem was installed, you can run an interactive wizard to configure your Rails application for using with AnyCable by running a generator:
|
38
|
+
|
39
|
+
```sh
|
40
|
+
bundle exec rails g anycable:setup
|
41
|
+
```
|
42
|
+
|
43
|
+
### Manual set up
|
44
|
+
|
45
|
+
Specify AnyCable subscription adapter for Action Cable:
|
46
|
+
|
47
|
+
```yml
|
48
|
+
# config/cable.yml
|
49
|
+
development:
|
50
|
+
adapter: any_cable # or anycable
|
51
|
+
|
52
|
+
production:
|
53
|
+
adapter: any_cable
|
54
|
+
```
|
55
|
+
|
56
|
+
and specify AnyCable WebSocket server URL:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
# For development it's likely the localhost
|
60
|
+
|
61
|
+
# config/environments/development.rb
|
62
|
+
config.action_cable.url = "ws://localhost:8080/cable"
|
63
|
+
|
64
|
+
# For production it's likely to have a sub-domain and secure connection
|
65
|
+
|
66
|
+
# config/environments/production.rb
|
67
|
+
config.action_cable.url = "wss://ws.example.com/cable"
|
68
|
+
```
|
69
|
+
|
70
|
+
Then, run AnyCable RPC server:
|
71
|
+
|
72
|
+
```sh
|
73
|
+
$ bundle exec anycable
|
74
|
+
|
75
|
+
# don't forget to provide Rails env
|
76
|
+
|
77
|
+
$ RAILS_ENV=production bundle exec anycable
|
78
|
+
```
|
79
|
+
|
80
|
+
And, finally, run AnyCable WebSocket server, e.g. [anycable-go](https://docs.anycable.io/anycable-go/getting_started):
|
81
|
+
|
82
|
+
```sh
|
83
|
+
anycable-go --host=localhost --port=8080
|
84
|
+
```
|
85
|
+
|
86
|
+
See [documentation](https://docs.anycable.io/rails/getting_started) for more information on AnyCable + Rails usage.
|
87
|
+
|
88
|
+
## Action Cable Compatibility
|
89
|
+
|
90
|
+
See [documentation](https://docs.anycable.io/rails/compatibility).
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/anycable/anycable-rails](https://github.com/anycable/anycable-rails).
|
95
|
+
|
96
|
+
## License
|
97
|
+
|
98
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
99
|
+
|
100
|
+
## Security Contact
|
101
|
+
|
102
|
+
To report a security vulnerability, please contact us at `anycable@evilmartians.com`. We will coordinate the fix and disclosure.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module AnyCable
|
8
|
+
# Checks for instance variable usage inside subscriptions.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# class MyChannel < ApplicationCable::Channel
|
13
|
+
# def subscribed
|
14
|
+
# @post = Post.find(params[:id])
|
15
|
+
# stream_from @post
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# class MyChannel < ApplicationCable::Channel
|
21
|
+
# def subscribed
|
22
|
+
# post = Post.find(params[:id])
|
23
|
+
# stream_from post
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
class InstanceVars < RuboCop::Cop::Base
|
28
|
+
MSG = "Channel instance variables are not supported in AnyCable. Use `state_attr_accessor` instead"
|
29
|
+
|
30
|
+
def on_class(node)
|
31
|
+
find_nested_ivars(node) do |nested_ivar|
|
32
|
+
add_offense(nested_ivar)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def find_nested_ivars(node, &block)
|
39
|
+
node.each_child_node do |child|
|
40
|
+
if child.ivasgn_type? || child.ivar_type?
|
41
|
+
yield(child)
|
42
|
+
elsif child.children.any?
|
43
|
+
find_nested_ivars(child, &block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module AnyCable
|
8
|
+
# Checks for periodical timers usage.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# class MyChannel < ApplicationCable::Channel
|
13
|
+
# periodically(:do_something, every: 2.seconds)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
class PeriodicalTimers < RuboCop::Cop::Base
|
17
|
+
MSG = "Periodical Timers are not supported in AnyCable"
|
18
|
+
|
19
|
+
def_node_matcher :calls_periodically?, <<-PATTERN
|
20
|
+
(send _ :periodically ...)
|
21
|
+
PATTERN
|
22
|
+
|
23
|
+
def on_send(node)
|
24
|
+
add_offense(node) if calls_periodically?(node)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module AnyCable
|
8
|
+
# Checks for #stream_from calls with custom callbacks or coders.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# class MyChannel < ApplicationCable::Channel
|
13
|
+
# def follow
|
14
|
+
# stream_for(room) {}
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# class MyChannel < ApplicationCable::Channel
|
19
|
+
# def follow
|
20
|
+
# stream_from("all", -> {})
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# class MyChannel < ApplicationCable::Channel
|
25
|
+
# def follow
|
26
|
+
# stream_from("all", coder: SomeCoder)
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# class MyChannel < ApplicationCable::Channel
|
32
|
+
# def follow
|
33
|
+
# stream_from "all"
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
class StreamFrom < RuboCop::Cop::Base
|
38
|
+
def_node_matcher :stream_from_with_block?, <<-PATTERN
|
39
|
+
(block {(send _ :stream_from ...) (send _ :stream_for ...)} ...)
|
40
|
+
PATTERN
|
41
|
+
|
42
|
+
def_node_matcher :stream_from_with_callback?, <<-PATTERN
|
43
|
+
{(send _ :stream_from str_type? (block (send nil? :lambda) ...)) (send _ :stream_for ... (block (send nil? :lambda) ...))}
|
44
|
+
PATTERN
|
45
|
+
|
46
|
+
def_node_matcher :args_of_stream_from, <<-PATTERN
|
47
|
+
{(send _ :stream_from str_type? $...) (send _ :stream_for $...)}
|
48
|
+
PATTERN
|
49
|
+
|
50
|
+
def_node_matcher :coder_symbol?, "(pair (sym :coder) ...)"
|
51
|
+
|
52
|
+
def_node_matcher :active_support_json?, <<-PATTERN
|
53
|
+
(pair _ (const (const nil? :ActiveSupport) :JSON))
|
54
|
+
PATTERN
|
55
|
+
|
56
|
+
def on_block(node)
|
57
|
+
add_callback_offense(node) if stream_from_with_block?(node)
|
58
|
+
end
|
59
|
+
|
60
|
+
def on_send(node)
|
61
|
+
if stream_from_with_callback?(node)
|
62
|
+
add_callback_offense(node)
|
63
|
+
return
|
64
|
+
end
|
65
|
+
|
66
|
+
args = args_of_stream_from(node)
|
67
|
+
find_coders(args) { |coder| add_custom_coder_offense(coder) }
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def find_coders(args)
|
73
|
+
return if args.nil?
|
74
|
+
|
75
|
+
args.select(&:hash_type?).each do |arg|
|
76
|
+
arg.each_child_node do |pair|
|
77
|
+
yield(pair) if coder_symbol?(pair) && !active_support_json?(pair)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_callback_offense(node)
|
83
|
+
add_offense(
|
84
|
+
node.loc.expression,
|
85
|
+
message: "Custom stream callbacks are not supported in AnyCable"
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_custom_coder_offense(node)
|
90
|
+
add_offense(
|
91
|
+
node.loc.expression,
|
92
|
+
message: "Custom coders are not supported in AnyCable"
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
require "pathname"
|
5
|
+
|
6
|
+
require_relative "rubocop/cops/anycable/stream_from"
|
7
|
+
require_relative "rubocop/cops/anycable/periodical_timers"
|
8
|
+
require_relative "rubocop/cops/anycable/instance_vars"
|
9
|
+
|
10
|
+
module RuboCop
|
11
|
+
module AnyCable # :nodoc:
|
12
|
+
CONFIG_DEFAULT = Pathname.new(__dir__).join("rubocop", "config", "default.yml").freeze
|
13
|
+
|
14
|
+
# Merge anycable config into default configuration
|
15
|
+
# See https://github.com/backus/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
|
16
|
+
def self.inject!
|
17
|
+
path = CONFIG_DEFAULT.to_s
|
18
|
+
puts "configuration from #{path}" if ConfigLoader.debug?
|
19
|
+
hash = ConfigLoader.send(:load_yaml_configuration, path)
|
20
|
+
config = Config.new(hash, path)
|
21
|
+
config = ConfigLoader.merge_with_default(config, path)
|
22
|
+
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RuboCop::AnyCable.inject!
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-anycable-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- palkan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: RuboCop rules for AnyCable Rails
|
28
|
+
email:
|
29
|
+
- dementiev.vm@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.md
|
37
|
+
- lib/anycable/rails/compatibility/rubocop.rb
|
38
|
+
- lib/anycable/rails/rubocop.rb
|
39
|
+
- lib/anycable/rails/rubocop/config/default.yml
|
40
|
+
- lib/anycable/rails/rubocop/cops/anycable/instance_vars.rb
|
41
|
+
- lib/anycable/rails/rubocop/cops/anycable/periodical_timers.rb
|
42
|
+
- lib/anycable/rails/rubocop/cops/anycable/stream_from.rb
|
43
|
+
- lib/anycable/rails/version.rb
|
44
|
+
homepage: http://github.com/anycable/anycable-rails
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata:
|
48
|
+
bug_tracker_uri: http://github.com/anycable/anycable-rails/issues
|
49
|
+
changelog_uri: https://github.com/anycable/anycable-rails/blob/master/CHANGELOG.md
|
50
|
+
documentation_uri: https://docs.anycable.io/#/using_with_rails
|
51
|
+
homepage_uri: https://anycable.io/
|
52
|
+
source_code_uri: http://github.com/anycable/anycable-rails
|
53
|
+
funding_uri: https://github.com/sponsors/anycable
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.7'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.5.23
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: RuboCop rules for AnyCable Rails
|
73
|
+
test_files: []
|