anycable-rails 1.0.0.preview2 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -125
  3. data/README.md +14 -34
  4. data/lib/anycable/rails.rb +36 -2
  5. data/lib/anycable/rails/actioncable/channel.rb +4 -0
  6. data/lib/anycable/rails/actioncable/connection.rb +24 -35
  7. data/lib/anycable/rails/actioncable/connection/serializable_identification.rb +42 -0
  8. data/lib/anycable/rails/actioncable/remote_connections.rb +11 -0
  9. data/lib/anycable/rails/channel_state.rb +48 -0
  10. data/lib/anycable/rails/compatibility.rb +4 -7
  11. data/lib/anycable/rails/compatibility/rubocop.rb +0 -1
  12. data/lib/anycable/rails/compatibility/rubocop/config/default.yml +3 -0
  13. data/lib/anycable/rails/compatibility/rubocop/cops/anycable/instance_vars.rb +1 -1
  14. data/lib/anycable/rails/compatibility/rubocop/cops/anycable/stream_from.rb +4 -4
  15. data/lib/anycable/rails/railtie.rb +10 -10
  16. data/lib/anycable/rails/refinements/subscriptions.rb +5 -0
  17. data/lib/anycable/rails/session_proxy.rb +19 -2
  18. data/lib/anycable/rails/version.rb +1 -1
  19. data/lib/generators/anycable/download/USAGE +14 -0
  20. data/lib/generators/anycable/download/download_generator.rb +77 -0
  21. data/lib/generators/anycable/setup/USAGE +2 -0
  22. data/lib/{rails/generators → generators}/anycable/setup/setup_generator.rb +67 -89
  23. data/lib/{rails/generators → generators}/anycable/setup/templates/Procfile.dev +0 -0
  24. data/lib/{rails/generators → generators}/anycable/setup/templates/config/anycable.yml.tt +12 -1
  25. data/lib/generators/anycable/setup/templates/config/cable.yml.tt +11 -0
  26. data/lib/{rails/generators/anycable/setup/templates/config/initializers/anycable.rb → generators/anycable/setup/templates/config/initializers/anycable.rb.tt} +1 -1
  27. data/lib/generators/anycable/with_os_helpers.rb +55 -0
  28. metadata +23 -47
  29. data/lib/anycable/rails/compatibility/rubocop/cops/anycable/remote_disconnect.rb +0 -31
  30. data/lib/rails/generators/anycable/setup/templates/Procfile +0 -2
  31. data/lib/rails/generators/anycable/setup/templates/bin/heroku-web +0 -7
  32. data/lib/rails/generators/anycable/setup/templates/config/cable.yml.tt +0 -11
@@ -7,7 +7,7 @@
7
7
  # Note that AnyCable recognizes REDIS_URL env variable for Redis pub/sub adapter. If you want to
8
8
  # use another Redis instance for AnyCable, provide ANYCABLE_REDIS_URL variable.
9
9
  #
10
- # Read more about AnyCable configuration here: https://docs.anycable.io/#/ruby/configuration
10
+ # Read more about AnyCable configuration here: <%= DOCS_ROOT %>/ruby/configuration
11
11
  #
12
12
  default: &default
13
13
  # Turn on/off access logs ("Started..." and "Finished...")
@@ -20,6 +20,13 @@ default: &default
20
20
  rpc_host: "127.0.0.1:50051"
21
21
  # Whether to enable gRPC level logging or not
22
22
  log_grpc: false
23
+ <%- if redis? -%>
24
+ # Use Redis to broadcast messages to AnyCable server
25
+ broadcast_adapter: redis
26
+ <%- else -%>
27
+ # Use HTTP adapter for a quick start (since redis gem is not present in the project)
28
+ broadcast_adapter: http
29
+ <%- end -%>
23
30
  # Use the same channel name for WebSocket server, e.g.:
24
31
  # $ anycable-go --redis-channel="__anycable__"
25
32
  redis_channel: "__anycable__"
@@ -30,3 +37,7 @@ development:
30
37
 
31
38
  production:
32
39
  <<: *default
40
+ <%- if !redis? -%>
41
+ # Use Redis in production
42
+ broadcast_adapter: redis
43
+ <%- end -%>
@@ -0,0 +1,11 @@
1
+ # Make it possible to switch adapters by passing the ACTION_CABLE_ADAPTER env variable.
2
+ # For example, you can use it fallback to the standard Action Cable in staging/review
3
+ # environments (by setting `ACTION_CABLE_ADAPTER=redis`).
4
+ development:
5
+ adapter: <%%= ENV.fetch("ACTION_CABLE_ADAPTER", "any_cable") %>
6
+
7
+ test:
8
+ adapter: test
9
+
10
+ production:
11
+ adapter: <%%= ENV.fetch("ACTION_CABLE_ADAPTER", "any_cable") %>
@@ -3,7 +3,7 @@
3
3
  # Add Warden middkeware to AnyCable stack to allow accessing
4
4
  # Devise current user via `env["warden"].user`.
5
5
  #
6
- # See http://docs.anycable.io/#/ruby/authentication
6
+ # See <%= DOCS_ROOT %>/ruby/authentication
7
7
  AnyCable::Rails::Rack.middleware.use Warden::Manager do |config|
8
8
  Devise.warden_config = config
9
9
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnyCableRailsGenerators
4
+ module WithOSHelpers
5
+ OS_NAMES = %w[linux darwin freebsd win].freeze
6
+ CPU_NAMES = %w[amd64 arm64 386 arm].freeze
7
+ DEFAULT_BIN_PATH = "/usr/local/bin"
8
+
9
+ def self.included(base)
10
+ base.class_option :os,
11
+ type: :string,
12
+ desc: "Specify the OS for AnyCable-Go server binary (options: #{OS_NAMES.join(", ")})"
13
+ base.class_option :cpu,
14
+ type: :string,
15
+ desc: "Specify the CPU architecturefor AnyCable-Go server binary (options: #{CPU_NAMES.join(", ")})"
16
+
17
+ private :current_cpu, :supported_current_cpu, :supported_current_os
18
+ end
19
+
20
+ def current_cpu
21
+ case Gem::Platform.local.cpu
22
+ when "x86_64", "x64"
23
+ "amd64"
24
+ when "x86_32", "x86", "i386", "i486", "i686"
25
+ "i386"
26
+ when "aarch64", "aarch64_be", /armv8/
27
+ "arm64"
28
+ when "arm", /armv7/, /armv6/
29
+ "arm"
30
+ else
31
+ "unknown"
32
+ end
33
+ end
34
+
35
+ def os_name
36
+ options[:os] ||
37
+ supported_current_os ||
38
+ ask("What is your OS name?", limited_to: OS_NAMES)
39
+ end
40
+
41
+ def cpu_name
42
+ options[:cpu] ||
43
+ supported_current_cpu ||
44
+ ask("What is your CPU architecture?", limited_to: CPU_NAMES)
45
+ end
46
+
47
+ def supported_current_cpu
48
+ CPU_NAMES.find(&current_cpu.method(:==))
49
+ end
50
+
51
+ def supported_current_os
52
+ OS_NAMES.find(&Gem::Platform.local.os.method(:==))
53
+ end
54
+ end
55
+ end
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.0.preview2
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-09 00:00:00.000000000 Z
11
+ date: 2020-06-10 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.preview2
19
+ version: 1.0.0.rc1
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.preview2
26
+ version: 1.0.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '13.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '13.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -95,47 +95,19 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.4'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rubocop-md
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.3'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '0.3'
111
- - !ruby/object:Gem::Dependency
112
- name: simplecov
98
+ name: rubocop
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - ">="
116
102
  - !ruby/object:Gem::Version
117
- version: 0.3.8
103
+ version: '0.80'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - ">="
123
109
  - !ruby/object:Gem::Version
124
- version: 0.3.8
125
- - !ruby/object:Gem::Dependency
126
- name: standard
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: 0.1.7
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: 0.1.7
110
+ version: '0.80'
139
111
  - !ruby/object:Gem::Dependency
140
112
  name: warden
141
113
  requirement: !ruby/object:Gem::Requirement
@@ -167,12 +139,14 @@ files:
167
139
  - lib/anycable/rails/actioncable/channel.rb
168
140
  - lib/anycable/rails/actioncable/connection.rb
169
141
  - lib/anycable/rails/actioncable/connection/persistent_session.rb
142
+ - lib/anycable/rails/actioncable/connection/serializable_identification.rb
143
+ - lib/anycable/rails/actioncable/remote_connections.rb
144
+ - lib/anycable/rails/channel_state.rb
170
145
  - lib/anycable/rails/compatibility.rb
171
146
  - lib/anycable/rails/compatibility/rubocop.rb
172
147
  - lib/anycable/rails/compatibility/rubocop/config/default.yml
173
148
  - lib/anycable/rails/compatibility/rubocop/cops/anycable/instance_vars.rb
174
149
  - lib/anycable/rails/compatibility/rubocop/cops/anycable/periodical_timers.rb
175
- - lib/anycable/rails/compatibility/rubocop/cops/anycable/remote_disconnect.rb
176
150
  - lib/anycable/rails/compatibility/rubocop/cops/anycable/stream_from.rb
177
151
  - lib/anycable/rails/config.rb
178
152
  - lib/anycable/rails/middlewares/executor.rb
@@ -182,13 +156,15 @@ files:
182
156
  - lib/anycable/rails/refinements/subscriptions.rb
183
157
  - lib/anycable/rails/session_proxy.rb
184
158
  - lib/anycable/rails/version.rb
185
- - lib/rails/generators/anycable/setup/setup_generator.rb
186
- - lib/rails/generators/anycable/setup/templates/Procfile
187
- - lib/rails/generators/anycable/setup/templates/Procfile.dev
188
- - lib/rails/generators/anycable/setup/templates/bin/heroku-web
189
- - lib/rails/generators/anycable/setup/templates/config/anycable.yml.tt
190
- - lib/rails/generators/anycable/setup/templates/config/cable.yml.tt
191
- - lib/rails/generators/anycable/setup/templates/config/initializers/anycable.rb
159
+ - lib/generators/anycable/download/USAGE
160
+ - lib/generators/anycable/download/download_generator.rb
161
+ - lib/generators/anycable/setup/USAGE
162
+ - lib/generators/anycable/setup/setup_generator.rb
163
+ - lib/generators/anycable/setup/templates/Procfile.dev
164
+ - lib/generators/anycable/setup/templates/config/anycable.yml.tt
165
+ - lib/generators/anycable/setup/templates/config/cable.yml.tt
166
+ - lib/generators/anycable/setup/templates/config/initializers/anycable.rb.tt
167
+ - lib/generators/anycable/with_os_helpers.rb
192
168
  homepage: http://github.com/anycable/anycable-rails
193
169
  licenses:
194
170
  - MIT
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rubocop"
4
-
5
- module RuboCop
6
- module Cop
7
- module AnyCable
8
- # Checks for remote disconnect usage.
9
- #
10
- # @example
11
- # # bad
12
- # class MyServive
13
- # def call(user)
14
- # ActionCable.server.remote_connections.where(current_user: user).disconnect
15
- # end
16
- # end
17
- #
18
- class RemoteDisconnect < RuboCop::Cop::Cop
19
- MSG = "Disconnecting remote clients is not supported in AnyCable"
20
-
21
- def_node_matcher :has_remote_disconnect?, <<-PATTERN
22
- (send (send (send _ :remote_connections) ...) :disconnect)
23
- PATTERN
24
-
25
- def on_send(node)
26
- add_offense(node) if has_remote_disconnect?(node)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,2 +0,0 @@
1
- web: bin/heroku-web
2
- release: bundle exec rails db:migrate
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
-
3
- if [ "$ANYCABLE_DEPLOYMENT" == "true" ]; then
4
- bundle exec anycable --server-command="anycable-go"
5
- else
6
- bundle exec rails server -p $PORT -b 0.0.0.0
7
- fi
@@ -1,11 +0,0 @@
1
- # Make it possible to switch adapters by passing the CABLE_ADAPTER env variable.
2
- # For example, you can use it fallback to the standard Action Cable in staging/review
3
- # environments (by setting `CABLE_ADAPTER=redis`).
4
- development:
5
- adapter: <%%= ENV.fetch("CABLE_ADAPTER", "any_cable") %>
6
-
7
- test:
8
- adapter: test
9
-
10
- production:
11
- adapter: <%%= ENV.fetch("CABLE_ADAPTER", "any_cable") %>