anycable-rails 1.0.0.rc3 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -5
- data/README.md +6 -6
- data/lib/anycable/rails/actioncable/connection.rb +26 -4
- data/lib/anycable/rails/actioncable/connection/persistent_session.rb +2 -2
- data/lib/anycable/rails/channel_state.rb +9 -2
- data/lib/anycable/rails/compatibility.rb +1 -0
- data/lib/anycable/rails/rack.rb +5 -5
- data/lib/anycable/rails/railtie.rb +0 -8
- data/lib/anycable/rails/version.rb +1 -1
- data/lib/generators/anycable/setup/setup_generator.rb +19 -5
- data/lib/generators/anycable/setup/templates/Procfile.dev.tt +6 -0
- data/lib/generators/anycable/setup/templates/config/anycable.yml.tt +8 -1
- metadata +9 -9
- data/lib/generators/anycable/setup/templates/Procfile.dev +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f7915a5f8edaf8e0053df398cef7ad663ce71ec69456e7f6c3e8d539d8724a8
|
4
|
+
data.tar.gz: 1349a0b4d6bff65540b940e8963578af24733ffdf3b51ed73cc3b11e85483d4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4501650b155d991cdca302a1ba225ca6c09e00b637d6589f741512d3ef20b62589dd98f550be7599b75a05e3be0a6f8e7caa105c37d6b6923181f20730e5a21
|
7
|
+
data.tar.gz: f973cbb37b67a1abe9f4a4acfd73cd88f8dfad2673a9c919eda6720bc647242748311429ef46e00b1e5bc02f8bf892d52a72218cd1ac2f28c77323039f80a91d
|
data/CHANGELOG.md
CHANGED
@@ -2,14 +2,26 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
-
## 1.0.
|
5
|
+
## 1.0.3 (2020-09-16)
|
6
|
+
|
7
|
+
- Fixed bug with building a request object when session store is absent. ([@palkan][])
|
8
|
+
|
9
|
+
## 1.0.2 (2020-09-08)
|
10
|
+
|
11
|
+
- Added missing channel state support to `#unsubscribed` callbacks. ([@palkan][])
|
12
|
+
|
13
|
+
## 1.0.1 (2020-07-07)
|
14
|
+
|
15
|
+
- Fixed patching Action Cable testing classes. ([@palkan][])
|
16
|
+
|
17
|
+
## 1.0.0 (2020-07-01)
|
18
|
+
|
19
|
+
- Support `rescue_from` in connections (Rails 6.1). ([@palkan][])
|
6
20
|
|
7
21
|
- Make AnyCable patches compatible with Action Cable testing. ([@palkan][])
|
8
22
|
|
9
23
|
- Do not add localhost `redis_url` to `anycable.yml` when Docker development method is chosen in `anycable:setup`. ([@palkan][])
|
10
24
|
|
11
|
-
## 1.0.0.rc2 (2020-06-16)
|
12
|
-
|
13
25
|
- Fix connection identifiers deserialization regression. ([@palkan][])
|
14
26
|
|
15
27
|
Using non-strings or non-GlobalId-encoded objects was broken.
|
@@ -19,8 +31,6 @@ Using non-strings or non-GlobalId-encoded objects was broken.
|
|
19
31
|
Update Docker snippet, do not enable persistent sessions automatically,
|
20
32
|
fix setting `config.action_cable.url` in environment configuration.
|
21
33
|
|
22
|
-
## 1.0.0.rc1 (2020-06-10)
|
23
|
-
|
24
34
|
- Add `state_attr_accessor` for channels. ([@palkan][])
|
25
35
|
|
26
36
|
Just like `attr_accessor` but "persists" the state between RPC calls.
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/anycable-rails.svg)](https://rubygems.org/gems/anycable-rails)
|
3
3
|
[![Build](https://github.com/anycable/anycable-rails/workflows/Build/badge.svg)](https://github.com/anycable/anycable-rails/actions)
|
4
4
|
[![Gitter](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg)](https://gitter.im/anycable/Lobby)
|
5
|
-
[![Documentation](https://img.shields.io/badge/docs-link-brightgreen.svg)](https://docs.anycable.io
|
5
|
+
[![Documentation](https://img.shields.io/badge/docs-link-brightgreen.svg)](https://docs.anycable.io/#/rails/getting_started)
|
6
6
|
|
7
7
|
# AnyCable Rails
|
8
8
|
|
@@ -14,9 +14,9 @@ You can even use Action Cable in development and not be afraid of [compatibility
|
|
14
14
|
|
15
15
|
**Important** This is a readme for the upcoming v1.0 release. For v0.6.x see the readme from the [0-6-stable](https://github.com/anycable/anycable-rails/tree/0-6-stable) branch.
|
16
16
|
|
17
|
-
|
17
|
+
💾 [Example Application](https://github.com/anycable/anycable_rails_demo)
|
18
18
|
|
19
|
-
📑 [Documentation](https://docs.anycable.io
|
19
|
+
📑 [Documentation](https://docs.anycable.io/#/rails/getting_started).
|
20
20
|
|
21
21
|
<a href="https://evilmartians.com/">
|
22
22
|
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
|
@@ -83,17 +83,17 @@ $ bundle exec anycable
|
|
83
83
|
$ RAILS_ENV=production bundle exec anycable
|
84
84
|
```
|
85
85
|
|
86
|
-
And, finally, run AnyCable WebSocket server, e.g. [anycable-go](https://docs.anycable.io/
|
86
|
+
And, finally, run AnyCable WebSocket server, e.g. [anycable-go](https://docs.anycable.io/#/v1/anycable-go/getting_started):
|
87
87
|
|
88
88
|
```sh
|
89
89
|
anycable-go --host=localhost --port=3334
|
90
90
|
```
|
91
91
|
|
92
|
-
See [documentation](https://docs.anycable.io
|
92
|
+
See [documentation](https://docs.anycable.io/#/rails/getting_started) for more information on AnyCable + Rails usage.
|
93
93
|
|
94
94
|
## Action Cable Compatibility
|
95
95
|
|
96
|
-
See [documentation](https://docs.anycable.io
|
96
|
+
See [documentation](https://docs.anycable.io/#/rails/compatibility).
|
97
97
|
|
98
98
|
## Contributing
|
99
99
|
|
@@ -31,7 +31,7 @@ module ActionCable
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def initialize(socket, env, identifiers: "{}", subscriptions:
|
34
|
+
def initialize(socket, env, identifiers: "{}", subscriptions: nil)
|
35
35
|
if env
|
36
36
|
# If env is set, then somehow we're in the context of Action Cable
|
37
37
|
# Return and print a warning in #process
|
@@ -51,8 +51,15 @@ module ActionCable
|
|
51
51
|
@socket = socket
|
52
52
|
@subscriptions = ActionCable::Connection::Subscriptions.new(self)
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
return unless subscriptions
|
55
|
+
|
56
|
+
# Initialize channels (for disconnect)
|
57
|
+
subscriptions.each do |id|
|
58
|
+
channel = @subscriptions.fetch(id)
|
59
|
+
next unless socket.istate[id]
|
60
|
+
|
61
|
+
channel.__istate__ = ActiveSupport::JSON.decode(socket.istate[id])
|
62
|
+
end
|
56
63
|
end
|
57
64
|
|
58
65
|
def process
|
@@ -64,7 +71,7 @@ module ActionCable
|
|
64
71
|
|
65
72
|
def invalid_request_message
|
66
73
|
"You're trying to connect to Action Cable server while using AnyCable. " \
|
67
|
-
"See https://docs.anycable.io
|
74
|
+
"See https://docs.anycable.io/#/troubleshooting?id=server-raises-an-argumenterror-exception-when-client-tries-to-connect"
|
68
75
|
end
|
69
76
|
|
70
77
|
def handle_open
|
@@ -198,3 +205,18 @@ module ActionCable
|
|
198
205
|
# rubocop:enable Metrics/ClassLength
|
199
206
|
end
|
200
207
|
end
|
208
|
+
|
209
|
+
# Support rescue_from
|
210
|
+
# https://github.com/rails/rails/commit/d2571e560c62116f60429c933d0c41a0e249b58b
|
211
|
+
if ActionCable::Connection::Base.respond_to?(:rescue_from)
|
212
|
+
ActionCable::Connection::Base.prepend(Module.new do
|
213
|
+
def handle_channel_command(*)
|
214
|
+
super
|
215
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
216
|
+
rescue_with_handler(e) || raise
|
217
|
+
false
|
218
|
+
end
|
219
|
+
end)
|
220
|
+
end
|
221
|
+
|
222
|
+
require "anycable/rails/actioncable/testing" if ::Rails.env.test?
|
@@ -15,8 +15,8 @@ module ActionCable
|
|
15
15
|
return super unless socket.session
|
16
16
|
|
17
17
|
super.tap do |req|
|
18
|
-
req.env[Rack::RACK_SESSION] =
|
19
|
-
AnyCable::Rails::SessionProxy.new(req.env[Rack::RACK_SESSION], socket.session)
|
18
|
+
req.env[::Rack::RACK_SESSION] =
|
19
|
+
AnyCable::Rails::SessionProxy.new(req.env[::Rack::RACK_SESSION], socket.session)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -10,11 +10,11 @@ module AnyCable
|
|
10
10
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
11
11
|
def #{name}
|
12
12
|
return @#{name} if instance_variable_defined?(:@#{name})
|
13
|
-
@#{name} = AnyCable::Rails.deserialize(
|
13
|
+
@#{name} = AnyCable::Rails.deserialize(__istate__["#{name}"], json: true) if connection.anycable_socket
|
14
14
|
end
|
15
15
|
|
16
16
|
def #{name}=(val)
|
17
|
-
|
17
|
+
__istate__["#{name}"] = AnyCable::Rails.serialize(val, json: true) if connection.anycable_socket
|
18
18
|
instance_variable_set(:@#{name}, val)
|
19
19
|
end
|
20
20
|
RUBY
|
@@ -36,6 +36,13 @@ module AnyCable
|
|
36
36
|
def self.included(base)
|
37
37
|
base.extend ClassMethods
|
38
38
|
end
|
39
|
+
|
40
|
+
# Make it possible to provide istate explicitly for a channel instance
|
41
|
+
attr_writer :__istate__
|
42
|
+
|
43
|
+
def __istate__
|
44
|
+
@__istate__ ||= connection.socket.istate
|
45
|
+
end
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
data/lib/anycable/rails/rack.rb
CHANGED
@@ -38,16 +38,16 @@ module AnyCable
|
|
38
38
|
config = ::Rails.application.config
|
39
39
|
|
40
40
|
ActionDispatch::MiddlewareStack.new do |middleware|
|
41
|
-
middleware.use(config.session_store, config.session_options)
|
41
|
+
middleware.use(config.session_store, config.session_options) if config.session_store
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.app
|
46
46
|
@rack_app || app_build_lock.synchronize do
|
47
|
-
@rack_app ||=
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
@rack_app ||= default_middleware_stack.yield_self do |stack|
|
48
|
+
middleware.merge_into(stack)
|
49
|
+
end.yield_self do |stack|
|
50
|
+
stack.build { [-1, {}, []] }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -8,7 +8,7 @@ module AnyCableRailsGenerators
|
|
8
8
|
namespace "anycable:setup"
|
9
9
|
source_root File.expand_path("templates", __dir__)
|
10
10
|
|
11
|
-
DOCS_ROOT = "https://docs.anycable.io
|
11
|
+
DOCS_ROOT = "https://docs.anycable.io/#"
|
12
12
|
DEVELOPMENT_METHODS = %w[skip local docker].freeze
|
13
13
|
SERVER_SOURCES = %w[skip brew binary].freeze
|
14
14
|
|
@@ -118,7 +118,7 @@ module AnyCableRailsGenerators
|
|
118
118
|
def stimulus_reflex
|
119
119
|
return unless stimulus_reflex?
|
120
120
|
|
121
|
-
say_status :help, "⚠️ Please, check out the documentation on using AnyCable with Stimulus Reflex: https://docs.anycable.io
|
121
|
+
say_status :help, "⚠️ Please, check out the documentation on using AnyCable with Stimulus Reflex: https://docs.anycable.io/#/rails/stimulus_reflex"
|
122
122
|
end
|
123
123
|
|
124
124
|
def rubocop_compatibility
|
@@ -126,7 +126,7 @@ module AnyCableRailsGenerators
|
|
126
126
|
|
127
127
|
say_status :info, "🤖 Running static compatibility checks with RuboCop"
|
128
128
|
res = run "bundle exec rubocop -r 'anycable/rails/compatibility/rubocop' --only AnyCable/InstanceVars,AnyCable/PeriodicalTimers,AnyCable/InstanceVars"
|
129
|
-
say_status :help, "⚠️ Please, take a look at the icompatibilities above and fix them. See https://docs.anycable.io
|
129
|
+
say_status :help, "⚠️ Please, take a look at the icompatibilities above and fix them. See https://docs.anycable.io/#/rails/compatibility" unless res
|
130
130
|
end
|
131
131
|
|
132
132
|
def finish
|
@@ -143,6 +143,10 @@ module AnyCableRailsGenerators
|
|
143
143
|
!!gemfile_lock&.match?(/^\s+redis\b/)
|
144
144
|
end
|
145
145
|
|
146
|
+
def webpacker?
|
147
|
+
!!gemfile_lock&.match?(/^\s+webpacker\b/)
|
148
|
+
end
|
149
|
+
|
146
150
|
def rubocop?
|
147
151
|
!!gemfile_lock&.match?(/^\s+rubocop\b/)
|
148
152
|
end
|
@@ -224,8 +228,8 @@ module AnyCableRailsGenerators
|
|
224
228
|
def template_proc_files
|
225
229
|
file_name = "Procfile.dev"
|
226
230
|
|
227
|
-
if
|
228
|
-
append_file file_name,
|
231
|
+
if file_exists?(file_name)
|
232
|
+
append_file file_name, "anycable: bundle exec anycable\nws: anycable-go#{anycable_go_options}", force: true
|
229
233
|
else
|
230
234
|
say_status :help, "💡 We recommend using Hivemind to manage multiple processes in development 👉 https://github.com/DarthSim/hivemind", :yellow
|
231
235
|
|
@@ -262,5 +266,15 @@ module AnyCableRailsGenerators
|
|
262
266
|
args << "--version #{opts[:version]}" if opts[:version]
|
263
267
|
end.join(" ")
|
264
268
|
end
|
269
|
+
|
270
|
+
def anycable_go_options
|
271
|
+
redis? ? " --port=8080" : " --port=8080 --broadcast_adapter=http"
|
272
|
+
end
|
273
|
+
|
274
|
+
def file_exists?(name)
|
275
|
+
in_root do
|
276
|
+
return File.file?(name)
|
277
|
+
end
|
278
|
+
end
|
265
279
|
end
|
266
280
|
end
|
@@ -30,10 +30,17 @@ default: &default
|
|
30
30
|
# Use the same channel name for WebSocket server, e.g.:
|
31
31
|
# $ anycable-go --redis-channel="__anycable__"
|
32
32
|
redis_channel: "__anycable__"
|
33
|
+
<%- if redis? -%>
|
34
|
+
# You can use REDIS_URL env var to configure Redis URL.
|
35
|
+
# Localhost is used by default.
|
36
|
+
# redis_url: "redis://localhost:6379/1"
|
37
|
+
<%- end -%>
|
33
38
|
|
34
39
|
development:
|
35
40
|
<<: *default
|
36
|
-
|
41
|
+
|
42
|
+
test:
|
43
|
+
<<: *default
|
37
44
|
|
38
45
|
production:
|
39
46
|
<<: *default
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anycable-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- palkan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anycable
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.0
|
19
|
+
version: 1.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0.0
|
26
|
+
version: 1.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,7 +161,7 @@ files:
|
|
161
161
|
- lib/generators/anycable/download/download_generator.rb
|
162
162
|
- lib/generators/anycable/setup/USAGE
|
163
163
|
- lib/generators/anycable/setup/setup_generator.rb
|
164
|
-
- lib/generators/anycable/setup/templates/Procfile.dev
|
164
|
+
- lib/generators/anycable/setup/templates/Procfile.dev.tt
|
165
165
|
- lib/generators/anycable/setup/templates/config/anycable.yml.tt
|
166
166
|
- lib/generators/anycable/setup/templates/config/cable.yml.tt
|
167
167
|
- lib/generators/anycable/setup/templates/config/initializers/anycable.rb.tt
|
@@ -186,9 +186,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '2.5'
|
187
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
188
|
requirements:
|
189
|
-
- - "
|
189
|
+
- - ">="
|
190
190
|
- !ruby/object:Gem::Version
|
191
|
-
version:
|
191
|
+
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubygems_version: 3.0.6
|
194
194
|
signing_key:
|