anycable-rails 0.5.5 → 0.6.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/.github/ISSUE_TEMPLATE.md +29 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +31 -0
  4. data/.rubocop.yml +24 -34
  5. data/CHANGELOG.md +31 -1
  6. data/README.md +47 -92
  7. data/Rakefile +7 -2
  8. data/anycable-rails.gemspec +3 -3
  9. data/lib/action_cable/subscription_adapter/any_cable.rb +23 -0
  10. data/lib/anycable/rails.rb +4 -4
  11. data/lib/anycable/rails/actioncable/channel.rb +8 -4
  12. data/lib/anycable/rails/actioncable/connection.rb +57 -23
  13. data/lib/anycable/rails/compatibility.rb +57 -0
  14. data/lib/anycable/rails/compatibility/rubocop.rb +28 -0
  15. data/lib/anycable/rails/compatibility/rubocop/config/default.yml +12 -0
  16. data/lib/anycable/rails/compatibility/rubocop/cops/anycable/instance_vars.rb +50 -0
  17. data/lib/anycable/rails/compatibility/rubocop/cops/anycable/periodical_timers.rb +29 -0
  18. data/lib/anycable/rails/compatibility/rubocop/cops/anycable/remote_disconnect.rb +31 -0
  19. data/lib/anycable/rails/compatibility/rubocop/cops/anycable/stream_from.rb +100 -0
  20. data/lib/anycable/rails/config.rb +3 -2
  21. data/lib/anycable/rails/middlewares/executor.rb +21 -0
  22. data/lib/anycable/rails/middlewares/log_tagging.rb +21 -0
  23. data/lib/anycable/rails/railtie.rb +20 -27
  24. data/lib/anycable/rails/refinements/subscriptions.rb +1 -1
  25. data/lib/anycable/rails/version.rb +2 -2
  26. metadata +25 -19
  27. data/lib/anycable/rails/actioncable/server.rb +0 -14
  28. data/lib/anycable/rails/activerecord/release_connection.rb +0 -29
  29. data/lib/generators/anycable/USAGE +0 -7
  30. data/lib/generators/anycable/anycable_generator.rb +0 -16
  31. data/lib/generators/anycable/templates/anycable.yml +0 -41
  32. data/lib/generators/anycable/templates/script +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0589fdada6b17d8200e9f2c35b31a4303aa8f81110056a10bf0743914dd79aa7'
4
- data.tar.gz: a67888ee7bbc93e8d05c0d864bb5e561b89e145b232b411d8b9399870e33b61a
3
+ metadata.gz: 23c007d1a03872b62769d01916c37dc08e65b209f7f2c03dc82506142dd9deba
4
+ data.tar.gz: 852a706ac6f822674f4f8ded679dd369b1fed46adfebf4687ff917e04d6b5dce
5
5
  SHA512:
6
- metadata.gz: ac48f3cd8e58ced758e93f0d6e44f321b5bb4d7aca5e06541bad613b2a0d19c0f3b7be8b29fcc9253d454ac8435170b8fa6b45240a1d0e26a55857240dcd4824
7
- data.tar.gz: 157a400f6121f22d3426d3661af6e98b8932ec7a547d36d9c688f8498b7def72ecf86fd98ff80f2afb3fcd4906646a954ce82834753bffe262de5e328b87c93b
6
+ metadata.gz: d7d61c3f61e07ff50a5ab51598647befa8295345864afa913829cc4311aa178dc2841e1bc9ddce5cb5a2f822add9d2a0cc667ecef438cfed3e0c056d9c726497
7
+ data.tar.gz: 4d9233be76b119ca9b09dcdb010e9a9bc6fdfa1c883530b97455a2ec2d23331458991c442b40640006ee8aa07ec12f5e0df3bf6c6b3a705761184661761e40d5
@@ -0,0 +1,29 @@
1
+ <!--
2
+ First of all, thanks for your report/suggestion/whatever!
3
+
4
+ This template is for bug reports. If you are reporting a bug, please continue on. If you are here for another reason,
5
+ feel free to skip the rest of this template.
6
+ -->
7
+
8
+ ### Tell us about your environment
9
+
10
+ **Ruby version:**
11
+
12
+ **Rails version:**
13
+
14
+ **`anycable` gem version:**
15
+
16
+ **`anycable-rails` gem version:**
17
+
18
+ **`grpc` gem version:**
19
+
20
+ ### What did you do?
21
+
22
+ ### What did you expect to happen?
23
+
24
+ ### What actually happened?
25
+
26
+ <!--
27
+ Please, provide reproduction script (using this template (https://github.com/anycable/anycable/blob/master/etc/bug_report_template.rb)
28
+ when submitting bugs if possible.
29
+ -->
@@ -0,0 +1,31 @@
1
+ <!--
2
+ First of all, thanks for contributing!
3
+
4
+ If it's a typo fix or minor documentation update feel free to skip the rest of this template!
5
+ -->
6
+
7
+ <!--
8
+ If it's a bug fix, then link it to the issue, for example:
9
+
10
+ Fixes #xxx
11
+ -->
12
+
13
+
14
+ <!--
15
+ Otherwise, describe the changes:
16
+
17
+ ### What is the purpose of this pull request?
18
+
19
+ ### What changes did you make? (overview)
20
+
21
+ ### Is there anything you'd like reviewers to focus on?
22
+
23
+ -->
24
+
25
+ <!--
26
+ Please ensure your PR is ready:
27
+
28
+ - Include tests for this change
29
+ - Add Changelog entry
30
+ - Update documentation for this change (if appropriate)
31
+ -->
@@ -5,58 +5,45 @@ AllCops:
5
5
  - 'lib/**/*.rake'
6
6
  - 'spec/**/*.rb'
7
7
  Exclude:
8
- - '*.gemspec'
9
8
  - 'bin/**/*'
10
- - 'spec/dummy/**/*'
11
9
  - 'tmp/**/*'
12
- - 'bench/**/*'
10
+ - 'lib/anycable/rpc/**/*'
13
11
  - 'vendor/**/*'
14
12
  - 'gemfiles/**/*'
15
- - 'lib/anycable/rpc/**/*'
16
- - 'Rakefile'
17
13
  - 'Gemfile'
14
+ - 'Rakefile'
15
+ - '*.gemspec'
18
16
  DisplayCopNames: true
19
17
  StyleGuideCopsOnly: false
20
- TargetRubyVersion: 2.3
21
-
22
- Style/AccessorMethodName:
23
- Enabled: false
18
+ TargetRubyVersion: 2.4
24
19
 
25
- Style/TrivialAccessors:
20
+ Rails:
26
21
  Enabled: false
27
22
 
28
23
  Style/Documentation:
29
24
  Exclude:
30
25
  - 'spec/**/*.rb'
31
26
 
32
- Style/FormatString:
33
- Enabled: false
34
-
35
- Style/FormatStringToken:
36
- Enabled: false
27
+ Naming/FileName:
28
+ Exclude:
29
+ - 'lib/anycable-rails.rb'
37
30
 
38
31
  Style/StringLiterals:
39
- Enabled: false
32
+ EnforcedStyle: double_quotes
40
33
 
41
34
  Style/RegexpLiteral:
42
35
  Enabled: false
43
36
 
44
- Style/SpaceInsideStringInterpolation:
37
+ Style/FormatStringToken:
38
+ Enabled: false
39
+
40
+ Layout/SpaceInsideStringInterpolation:
45
41
  EnforcedStyle: no_space
46
42
 
47
43
  Style/BlockDelimiters:
48
44
  Exclude:
49
45
  - 'spec/**/*.rb'
50
46
 
51
- Style/PercentLiteralDelimeters:
52
- Enabled: false
53
-
54
- Lint/ScriptPermission:
55
- Enabled: false
56
-
57
- Lint/AmbiguousRegexpLiteral:
58
- Enabled: false
59
-
60
47
  Metrics/MethodLength:
61
48
  Exclude:
62
49
  - 'spec/**/*.rb'
@@ -66,18 +53,21 @@ Metrics/LineLength:
66
53
  Exclude:
67
54
  - 'spec/**/*.rb'
68
55
 
56
+ Metrics/AbcSize:
57
+ Exclude:
58
+ - 'spec/**/*.rb'
59
+
69
60
  Metrics/BlockLength:
70
61
  Exclude:
71
62
  - 'spec/**/*.rb'
72
63
 
73
- Naming/FileName:
64
+ Metrics/CyclomaticComplexity:
74
65
  Exclude:
75
- - 'README.md'
76
- - 'CHANGELOG.md'
77
- - 'lib/anycable-rails.rb'
66
+ - 'spec/**/*.rb'
78
67
 
79
- Rails/Date:
80
- Enabled: false
68
+ Metrics/PerceivedComplexity:
69
+ Exclude:
70
+ - 'spec/**/*.rb'
81
71
 
82
- Rails/TimeZone:
83
- Enabled: false
72
+ Lint/HandleExceptions:
73
+ Enabled: false
@@ -1,6 +1,35 @@
1
1
  # Change log
2
2
 
3
- ## master
3
+ ## 0.6.0-dev
4
+
5
+ - [PR #56](https://github.com/anycable/anycable-rails/pull/56) Request verification based on ActionCable config. ([@DmitryTsepelev][])
6
+
7
+ - Add WS server session ID to log tags if present. ([@palkan][])
8
+
9
+ - Support tagged logging. ([@palkan][])
10
+
11
+ - Action Cable monkey-patches are only loaded in the context of AnyCable CLI. ([@palkan][])
12
+
13
+ No need to think about `requie` and `group` for `anycable-rails`, just add it to Gemfile.
14
+
15
+ - Add `:any_cable` subscription adapter for Action Cable. ([@palkan][])
16
+
17
+ Use `:any_cable` adapter for Action Cable to broadcast data to AnyCable.
18
+
19
+ No more `pubsub` monkey-patches 🎉.
20
+
21
+ - Added Rails executor/reloader support. ([@palkan][])
22
+
23
+ - **[Breaking]** No more generators. ([@palkan][])
24
+
25
+ No need to generate AnyCable runner script since `anycable` gem ships with
26
+ the CLI.
27
+
28
+ - Add dynamic (`AnyCable::CompatibilityError`) compatibility checks. ([@DmitryTsepelev][])
29
+
30
+ - Added static (RuboCop) compatibility checks. ([@DmitryTsepelev][])
31
+
32
+ See https://github.com/anycable/anycable-rails/issues/52
4
33
 
5
34
  ## 0.5.4 (2018-06-13)
6
35
 
@@ -58,3 +87,4 @@ Ignore tagged logger features ('cause we do not have _persistent_ logger).
58
87
 
59
88
  [@palkan]: https://github.com/palkan
60
89
  [@alekseyl]: https://github.com/alekseyl
90
+ [@DmitryTsepelev]: https://github.com/DmitryTsepelev
data/README.md CHANGED
@@ -1,152 +1,107 @@
1
1
  [![GitPitch](https://gitpitch.com/assets/badge.svg)](https://gitpitch.com/anycable/anycable/master?grs=github) [![Gem Version](https://badge.fury.io/rb/anycable-rails.svg)](https://rubygems.org/gems/anycable-rails) [![Build Status](https://travis-ci.org/anycable/anycable-rails.svg?branch=master)](https://travis-ci.org/anycable/anycable-rails)
2
2
  [![Gitter](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg)](https://gitter.im/anycable/Lobby)
3
+ [![Documentation](https://img.shields.io/badge/docs-link-brightgreen.svg)](https://docs.anycable.io/#using_with_rails)
3
4
 
4
- # Anycable Rails
5
+ # AnyCable Rails
5
6
 
6
- AnyCable allows you to use any WebSocket server (written in any language) as a replacement for built-in Rails ActionCable server.
7
+ AnyCable allows you to use any WebSocket server (written in any language) as a replacement for built-in Rails Action Cable server.
7
8
 
8
- With AnyCable you can use channels, client-side JS, broadcasting - (almost) all that you can do with ActionCable.
9
+ With AnyCable you can use channels, client-side JS, broadcasting - (almost) all that you can do with Action Cable.
9
10
 
10
- You can even use ActionCable in development and not be afraid of compatibility issues.
11
+ You can even use Action Cable in development and not be afraid of [compatibility issues](#compatibility).
11
12
 
12
- [Example Application](https://github.com/anycable/anycable_demo)
13
+ 💾 [Example Application](https://github.com/anycable/anycable_demo)
14
+
15
+ 📑 [Documentation](https://docs.anycable.io).
13
16
 
14
- For usage outside Rails see [AnyCable repository](https://github.com/anycable/anycable).
15
17
 
16
18
  <a href="https://evilmartians.com/">
17
19
  <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
18
20
 
19
21
  ## Requirements
20
22
 
21
- - Ruby ~> 2.3;
23
+ - Ruby ~> 2.4;
22
24
  - Rails ~> 5.0;
23
- - Redis
25
+ - Redis (see [other options]() for broadcasting)
24
26
 
25
27
  ## How It Works?
26
28
 
27
29
  <img src="https://trello-attachments.s3.amazonaws.com/5781e0ed48e4679e302833d3/820x987/5b6a305417b04e20e75f49c5816e027c/Anycable_vs_ActionCable_copy.jpg" width="400" />
28
30
 
29
- ## Links
30
-
31
- - [GitPitch Slides](https://gitpitch.com/anycable/anycable/master?grs=github)
32
-
33
- - RailsClub Moscow 2016 [slides](https://speakerdeck.com/palkan/railsclub-moscow-2016-anycable) and [video](https://www.youtube.com/watch?v=-k7GQKuBevY&list=PLiWUIs1hSNeOXZhotgDX7Y7qBsr24cu7o&index=4) (RU)
34
-
35
-
36
- ## Compatible WebSocket servers
37
-
38
- - [Anycable Go](https://github.com/anycable/anycable-go)
39
- - [ErlyCable](https://github.com/anycable/erlycable)
40
-
31
+ ## Usage
41
32
 
42
- ## Installation
43
33
 
44
- Add Anycable to your application's Gemfile:
34
+ Add `anycable-rails` gem to your Gemfile:
45
35
 
46
36
  ```ruby
47
- gem 'anycable-rails'
37
+ gem "anycable-rails"
48
38
 
49
- # or if you want to use built-in Action Cable server
50
- # for test and development (which is possible and recommended)
51
- gem 'anycable-rails', group: :production
39
+ # when using Redis broadcast adapter
40
+ gem "redis", ">= 4.0"
52
41
  ```
53
42
 
54
- **NOTE**: if you want to require `anycable-rails` _manually_ (i.e. with `require: false` in your `Gemfile`)
55
- make sure that it's loaded prior to `Rails.application.initialize!` call (see `config/environment.rb`).
43
+ (and don't forget to run `bundle install`).
56
44
 
57
- And then run:
45
+ Next, specify AnyCable subscription adapter for Action Cable:
58
46
 
59
- ```shell
60
- rails generate anycable
47
+ ```yml
48
+ # config/cable.yml
49
+ production:
50
+ adapter: any_cable
61
51
  ```
62
52
 
63
- to create executable.
53
+ and specify AnyCable WebSocket server URL:
64
54
 
65
- ## Configuration
55
+ ```ruby
56
+ # For development it's likely the localhost
66
57
 
67
- Add `config/anycable.yml`if you want to override defaults (see below):
58
+ # config/environments/development.rb
59
+ config.action_cable.url = "ws://localhost:3334/cable"
68
60
 
69
- ```yml
70
- production:
71
- # gRPC server host
72
- rpc_host: "localhost:50051"
73
- # Redis URL (for broadcasting)
74
- redis_url: "redis://localhost:6379/2"
75
- # Redis channel name
76
- redis_channel: "anycable"
61
+ # For production it's likely to have a sub-domain and secure connection
77
62
 
63
+ # config/environments/production.rb
64
+ config.action_cable.url = "wss://ws.example.com/cable"
78
65
  ```
79
66
 
80
- Anycable uses [anyway_config](https://github.com/palkan/anyway_config), thus it is also possible to set configuration variables through `secrets.yml` or environment vars.
67
+ hen, run AnyCable RPC server:
81
68
 
82
- ## Usage
69
+ ```ruby
70
+ $ bundle exec anycable
83
71
 
84
- Run Anycable RPC server:
72
+ # don't forget to provide Rails env
85
73
 
86
- ```ruby
87
- RAILS_ENV=production ./bin/anycable
74
+ $ RAILS_ENV=production bundle exec anycable
88
75
  ```
89
76
 
90
- and also run AnyCable-compatible WebSocket server, e.g. [anycable-go](https://github.com/anycable/anycable-go):
77
+ And, finally, run AnyCable WebSocket server, e.g. [anycable-go](https://docs.anycable.io/#go_getting_started.md):
91
78
 
92
79
  ```sh
93
80
  anycable-go --host=localhost --port=3334
94
81
  ```
95
82
 
96
- Don't forget to set cable url in your environment:
83
+ See [documentation](https://docs.anycable.io/#using_with_rails) for more information on AnyCable + Rails usage.
97
84
 
98
- ```ruby
99
- # For development it's likely the localhost
85
+ ## Action Cable Compatibility
100
86
 
101
- # config/environments/development.rb
102
- config.action_cable.url = "ws://localhost:3334/cable"
87
+ See [documentation](https://docs.anycable.io/#compatibility).
103
88
 
104
- # For production it's likely to have a sub-domain and secure connection
105
-
106
- # config/environments/production.rb
107
- config.action_cable.url = "wss://ws.example.com/cable"
108
- ```
89
+ ## Links
109
90
 
110
- ### Logging
91
+ - [AnyCable: Action Cable on steroids!](https://evilmartians.com/chronicles/anycable-actioncable-on-steroids)
111
92
 
112
- Anycable uses `Rails.logger` as `Anycable.logger` by default, thus Anycable _debug_ mode (`ANYCABLE_DEBUG=1`) is not available, you should configure Rails logger instead, e.g.:
93
+ - [From Action to Any](https://medium.com/@leshchuk/from-action-to-any-1e8d863dd4cf) by [@alekseyl](https://github.com/alekseyl)
113
94
 
114
- ```ruby
115
- # in Rails configuration
116
- if Anycable.config.debug
117
- config.logger = Logger.new(STDOUT)
118
- config.log_level = :debug
119
- end
120
- ```
95
+ ## Talks
121
96
 
122
- You can also turn on access logging (`Started <request data>` / `Finished <request data>`):
97
+ - One cable to rule them all, RubyKaigi 2018, [slides](https://speakerdeck.com/palkan/rubykaigi-2018-anycable-one-cable-to-rule-them-all) and [video](https://www.youtube.com/watch?v=jXCPuNICT8s) (EN)
123
98
 
124
- ```ruby
125
- # in anycable.yml
126
- production:
127
- access_logs_disabled: false
128
- ```
99
+ - Wroc_Love.rb 2018 [slides](https://speakerdeck.com/palkan/wroc-love-dot-rb-2018-cables-cables-cables) and [video](https://www.youtube.com/watch?v=AUxFFOehiy0) (EN)
129
100
 
130
- ## ActionCable Compatibility
131
-
132
- This is the compatibility list for the AnyCable gem, not for AnyCable servers (which may not support some of the features yet).
133
-
134
- Feature | Status
135
- -------------------------|--------
136
- Connection Identifiers | +
137
- Connection Request (cookies, params) | +
138
- Disconnect Handling | +
139
- Subscribe to channels | +
140
- Parameterized subscriptions | +
141
- Unsubscribe from channels | +
142
- [Subscription Instance Variables](http://edgeapi.rubyonrails.org/classes/ActionCable/Channel/Streams.html) | -
143
- Performing Channel Actions | +
144
- Streaming | +
145
- [Custom stream callbacks](http://edgeapi.rubyonrails.org/classes/ActionCable/Channel/Streams.html) | -
146
- Broadcasting | +
147
- Periodical Timers | -
148
- Disconnect remote clients | -
101
+ ## Compatible WebSocket servers
149
102
 
103
+ - [AnyCable Go](https://github.com/anycable/anycable-go)
104
+ - [ErlyCable](https://github.com/anycable/erlycable)
150
105
 
151
106
  ## Contributing
152
107
 
data/Rakefile CHANGED
@@ -2,7 +2,12 @@ require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
  require "rubocop/rake_task"
4
4
 
5
- RSpec::Core::RakeTask.new(:spec)
6
5
  RuboCop::RakeTask.new
7
6
 
8
- task default: [:rubocop, :spec]
7
+ desc "Run compatibility specs"
8
+ RSpec::Core::RakeTask.new("spec:compatibility") do |task|
9
+ task.pattern = "spec/**/*_compatibility.rb"
10
+ task.verbose = false
11
+ end
12
+
13
+ task default: %w[rubocop spec:compatibility spec]
@@ -6,7 +6,7 @@ require 'anycable/rails/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "anycable-rails"
9
- spec.version = Anycable::Rails::VERSION
9
+ spec.version = AnyCable::Rails::VERSION
10
10
  spec.authors = ["palkan"]
11
11
  spec.email = ["dementiev.vm@gmail.com"]
12
12
 
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "rails", ">= 5"
22
- spec.add_dependency "anycable", "~> 0.5.0"
22
+ spec.add_dependency "anycable", "0.6.0.rc1"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", ">= 3.4"
27
- spec.add_development_dependency "ammeter", "~> 1.1"
27
+ spec.add_development_dependency "sqlite3"
28
28
  spec.add_development_dependency "simplecov", ">= 0.3.8"
29
29
  spec.add_development_dependency "rubocop", "~> 0.60.0"
30
30
  spec.add_development_dependency "pry-byebug"