anycable-rails-core 1.5.4 → 1.6.0.rc.1
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/CHANGELOG.md +6 -0
- data/README.md +10 -71
- data/lib/anycable/rails/channel/presence.rb +36 -0
- data/lib/anycable/rails/channel.rb +9 -0
- data/lib/anycable/rails/compatibility/rubocop.rb +2 -25
- data/lib/anycable/rails/connections/serializable_identification.rb +14 -0
- data/lib/anycable/rails/railtie.rb +3 -2
- data/lib/anycable/rails/{compatibility/rubocop → rubocop}/cops/anycable/instance_vars.rb +1 -1
- data/lib/anycable/rails/{compatibility/rubocop → rubocop}/cops/anycable/periodical_timers.rb +1 -1
- data/lib/anycable/rails/{compatibility/rubocop → rubocop}/cops/anycable/stream_from.rb +3 -5
- data/lib/anycable/rails/rubocop.rb +27 -0
- data/lib/anycable/rails/version.rb +1 -1
- data/lib/anycable/rails.rb +2 -1
- data/lib/generators/anycable/setup/templates/config/anycable.yml.tt +1 -1
- metadata +21 -12
- /data/lib/anycable/rails/{compatibility/rubocop → rubocop}/config/default.yml +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 395f76c02adbd3f4878b55bb21bf4bd00969e4394e824fb7a23f086d8b221b1c
|
4
|
+
data.tar.gz: b300f5b2ab64aa893d462a22045587f65531bbaea8dce3a920c1fb1df67b211e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0a2f228649539c86b8e3f1a96f0c456b6ed0f933552fb93c90ef2d4a5c49261fdbdf9f3e7b650cd69b00ca38bddcf202bb6f1d730aa92ad07ec3f8504128904
|
7
|
+
data.tar.gz: dfce4029440d91a5a7f07abccca089b6b0bb759d152aa2fadad9ccb12ca0533a5d10cba6e200f398ce58c54c76c5b0fa5903c48aeacba2354dc8b5f9ad37d10f
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## master
|
4
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
|
+
|
5
11
|
## 1.5.4 (2024-10-08)
|
6
12
|
|
7
13
|
- Add [actioncable-next](https://github.com/anycable/actioncable-next) support. ([@palkan][])
|
data/README.md
CHANGED
@@ -1,30 +1,18 @@
|
|
1
|
-
[](https://rubygems.org/gems/anycable)
|
2
2
|
[](https://github.com/anycable/anycable-rails/actions)
|
3
3
|
[](https://docs.anycable.io/rails/getting_started)
|
4
4
|
|
5
|
-
# AnyCable Rails
|
5
|
+
# AnyCable SDK for Ruby on Rails
|
6
6
|
|
7
|
-
|
7
|
+
<img align="right" height="150" width="129"
|
8
|
+
title="AnyCable logo" src="https://docs.anycable.io/assets/images/logo.svg">
|
8
9
|
|
9
|
-
|
10
|
+
[AnyCable](https://github.com/anycable/anycable) is an open-source language-agnostic realtime server for reliable two-way communication over WebSockets and SSE.
|
11
|
+
This repository contains code for AnyCable Rails SKD that allows you to use AnyCable as a drop-in replacement for Action Cable.
|
10
12
|
|
11
|
-
💾 [Example Application](https://github.com/anycable/anycable_rails_demo)
|
13
|
+
🌐 [Website](https://anycable.io) · 📚 [Documentation](https://docs.anycable.io/rails/getting_started) · 💾 [Example Rails Application](https://github.com/anycable/anycable_rails_demo)
|
12
14
|
|
13
|
-
|
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
|
15
|
+
## Quick Start
|
28
16
|
|
29
17
|
Add `anycable-rails` gem to your Gemfile:
|
30
18
|
|
@@ -32,62 +20,13 @@ Add `anycable-rails` gem to your Gemfile:
|
|
32
20
|
gem "anycable-rails"
|
33
21
|
```
|
34
22
|
|
35
|
-
|
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:
|
23
|
+
Then run our interactive setup command:
|
38
24
|
|
39
25
|
```sh
|
40
26
|
bundle exec rails g anycable:setup
|
41
27
|
```
|
42
28
|
|
43
|
-
|
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).
|
29
|
+
Learn more [here](https://docs.anycable.io/rails/getting_started).
|
91
30
|
|
92
31
|
## Contributing
|
93
32
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnyCable
|
4
|
+
module Rails
|
5
|
+
module Channel
|
6
|
+
# Presence API for Action Cable channels (backed by AnyCable)
|
7
|
+
module Presence
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
def join_presence(stream = nil, id: user_presence_id, info: user_presence_info)
|
11
|
+
return unless anycabled?
|
12
|
+
|
13
|
+
stream ||= connection.anycable_socket.streams[:start].first || raise(ArgumentError, "Provide a stream name for presence updates")
|
14
|
+
|
15
|
+
connection.anycable_socket.presence_join(stream, id, info)
|
16
|
+
end
|
17
|
+
|
18
|
+
def leave_presence(id = user_presence_id)
|
19
|
+
return unless anycabled?
|
20
|
+
|
21
|
+
connection.anycable_socket.presence_leave(id)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def user_presence_id
|
27
|
+
connection.connection_identifier
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_presence_info
|
31
|
+
# nothing
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,27 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
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!
|
3
|
+
# For backwards compatibility
|
4
|
+
require_relative "../rubocop"
|
@@ -6,6 +6,20 @@ module AnyCable
|
|
6
6
|
module SerializableIdentification
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
|
+
module ConnectionGID
|
10
|
+
def connection_identifier
|
11
|
+
unless defined? @connection_identifier
|
12
|
+
@connection_identifier = connection_gid identifiers.filter_map { |id| instance_variable_get(:"@#{id}") || __send__(id) }
|
13
|
+
end
|
14
|
+
|
15
|
+
@connection_identifier
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
included do
|
20
|
+
prepend ConnectionGID
|
21
|
+
end
|
22
|
+
|
9
23
|
class_methods do
|
10
24
|
def identified_by(*identifiers)
|
11
25
|
super
|
@@ -123,11 +123,12 @@ module AnyCable
|
|
123
123
|
|
124
124
|
initializer "anycable.verify_pool_sizes" do
|
125
125
|
next if AnyCable.config.disable_rpc_pool_size_warning?
|
126
|
-
# Skip if non-gRPC server is used
|
127
|
-
next unless AnyCable.config.respond_to?(:rpc_pool_size)
|
128
126
|
|
129
127
|
# Log current db vs. gRPC pool sizes
|
130
128
|
AnyCable.configure_server do
|
129
|
+
# Skip if non-gRPC server is used
|
130
|
+
next unless AnyCable.config.respond_to?(:rpc_pool_size)
|
131
|
+
|
131
132
|
ActiveSupport.on_load(:active_record) do
|
132
133
|
db_pool_size = ::ActiveRecord::Base.connection_pool.size
|
133
134
|
rpc_pool_size = AnyCable.config.rpc_pool_size
|
data/lib/anycable/rails/{compatibility/rubocop → rubocop}/cops/anycable/periodical_timers.rb
RENAMED
@@ -13,7 +13,7 @@ module RuboCop
|
|
13
13
|
# periodically(:do_something, every: 2.seconds)
|
14
14
|
# end
|
15
15
|
#
|
16
|
-
class PeriodicalTimers < RuboCop::Cop::
|
16
|
+
class PeriodicalTimers < RuboCop::Cop::Base
|
17
17
|
MSG = "Periodical Timers are not supported in AnyCable"
|
18
18
|
|
19
19
|
def_node_matcher :calls_periodically?, <<-PATTERN
|
@@ -34,7 +34,7 @@ module RuboCop
|
|
34
34
|
# end
|
35
35
|
# end
|
36
36
|
#
|
37
|
-
class StreamFrom < RuboCop::Cop::
|
37
|
+
class StreamFrom < RuboCop::Cop::Base
|
38
38
|
def_node_matcher :stream_from_with_block?, <<-PATTERN
|
39
39
|
(block {(send _ :stream_from ...) (send _ :stream_for ...)} ...)
|
40
40
|
PATTERN
|
@@ -81,16 +81,14 @@ module RuboCop
|
|
81
81
|
|
82
82
|
def add_callback_offense(node)
|
83
83
|
add_offense(
|
84
|
-
node,
|
85
|
-
location: :expression,
|
84
|
+
node.loc.expression,
|
86
85
|
message: "Custom stream callbacks are not supported in AnyCable"
|
87
86
|
)
|
88
87
|
end
|
89
88
|
|
90
89
|
def add_custom_coder_offense(node)
|
91
90
|
add_offense(
|
92
|
-
node,
|
93
|
-
location: :expression,
|
91
|
+
node.loc.expression,
|
94
92
|
message: "Custom coders are not supported in AnyCable"
|
95
93
|
)
|
96
94
|
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!
|
data/lib/anycable/rails.rb
CHANGED
@@ -9,6 +9,7 @@ require "globalid"
|
|
9
9
|
require "active_support/core_ext/module/attribute_accessors_per_thread"
|
10
10
|
|
11
11
|
require "anycable/rails/ext"
|
12
|
+
require "anycable/rails/channel"
|
12
13
|
|
13
14
|
module AnyCable
|
14
15
|
# Rails handler for AnyCable
|
@@ -84,7 +85,7 @@ end
|
|
84
85
|
|
85
86
|
# Warn if application has been already initialized.
|
86
87
|
# AnyCable should be loaded before initialization in order to work correctly.
|
87
|
-
if defined?(::Rails) && ::Rails.application
|
88
|
+
if defined?(::Rails) && ::Rails.application&.initialized?
|
88
89
|
puts("\n**************************************************")
|
89
90
|
puts(
|
90
91
|
"⛔️ WARNING: AnyCable loaded after application initialization. Might not work correctly.\n" \
|
@@ -23,7 +23,7 @@ default: &default
|
|
23
23
|
<%- else -%>
|
24
24
|
# Use HTTP broadcaster
|
25
25
|
broadcast_adapter: http
|
26
|
-
http_broadcast_url: "http://localhost:8090/
|
26
|
+
http_broadcast_url: "http://localhost:8090/_broadcast"
|
27
27
|
<%- end -%>
|
28
28
|
<%- if redis? -%>
|
29
29
|
# You can use REDIS_URL env var to configure Redis URL.
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anycable-rails-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- palkan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anycable-core
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.0.rc.1
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
22
|
+
version: 1.7.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
29
|
+
version: 1.6.0.rc.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.7.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: actioncable
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,13 +83,11 @@ files:
|
|
77
83
|
- lib/anycable/rails/action_cable_ext/channel.rb
|
78
84
|
- lib/anycable/rails/action_cable_ext/connection.rb
|
79
85
|
- lib/anycable/rails/action_cable_ext/remote_connections.rb
|
86
|
+
- lib/anycable/rails/channel.rb
|
87
|
+
- lib/anycable/rails/channel/presence.rb
|
80
88
|
- lib/anycable/rails/channel_state.rb
|
81
89
|
- lib/anycable/rails/compatibility.rb
|
82
90
|
- lib/anycable/rails/compatibility/rubocop.rb
|
83
|
-
- lib/anycable/rails/compatibility/rubocop/config/default.yml
|
84
|
-
- lib/anycable/rails/compatibility/rubocop/cops/anycable/instance_vars.rb
|
85
|
-
- lib/anycable/rails/compatibility/rubocop/cops/anycable/periodical_timers.rb
|
86
|
-
- lib/anycable/rails/compatibility/rubocop/cops/anycable/stream_from.rb
|
87
91
|
- lib/anycable/rails/config.rb
|
88
92
|
- lib/anycable/rails/connection.rb
|
89
93
|
- lib/anycable/rails/connection_factory.rb
|
@@ -105,6 +109,11 @@ files:
|
|
105
109
|
- lib/anycable/rails/pubsub_channel.rb
|
106
110
|
- lib/anycable/rails/rack.rb
|
107
111
|
- lib/anycable/rails/railtie.rb
|
112
|
+
- lib/anycable/rails/rubocop.rb
|
113
|
+
- lib/anycable/rails/rubocop/config/default.yml
|
114
|
+
- lib/anycable/rails/rubocop/cops/anycable/instance_vars.rb
|
115
|
+
- lib/anycable/rails/rubocop/cops/anycable/periodical_timers.rb
|
116
|
+
- lib/anycable/rails/rubocop/cops/anycable/stream_from.rb
|
108
117
|
- lib/anycable/rails/socket_id_tracking.rb
|
109
118
|
- lib/anycable/rails/version.rb
|
110
119
|
- lib/generators/anycable/bin/USAGE
|
@@ -141,9 +150,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
150
|
version: '2.7'
|
142
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
152
|
requirements:
|
144
|
-
- - "
|
153
|
+
- - ">"
|
145
154
|
- !ruby/object:Gem::Version
|
146
|
-
version:
|
155
|
+
version: 1.3.1
|
147
156
|
requirements: []
|
148
157
|
rubygems_version: 3.4.19
|
149
158
|
signing_key:
|
File without changes
|