litecable 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +14 -2
  3. data/README.md +1 -3
  4. data/Rakefile +3 -1
  5. data/examples/sinatra/Gemfile +2 -2
  6. data/examples/sinatra/Procfile +1 -1
  7. data/examples/sinatra/README.md +2 -0
  8. data/examples/sinatra/anycable +2 -4
  9. data/examples/sinatra/app.rb +1 -0
  10. data/examples/sinatra/chat.rb +1 -0
  11. data/examples/sinatra/config.ru +1 -0
  12. data/lib/lite_cable.rb +1 -0
  13. data/lib/lite_cable/anycable.rb +9 -3
  14. data/lib/lite_cable/channel.rb +1 -0
  15. data/lib/lite_cable/channel/base.rb +1 -0
  16. data/lib/lite_cable/channel/registry.rb +1 -0
  17. data/lib/lite_cable/channel/streams.rb +1 -0
  18. data/lib/lite_cable/coders.rb +1 -0
  19. data/lib/lite_cable/coders/json.rb +1 -0
  20. data/lib/lite_cable/coders/raw.rb +1 -0
  21. data/lib/lite_cable/config.rb +1 -0
  22. data/lib/lite_cable/connection.rb +1 -0
  23. data/lib/lite_cable/connection/authorization.rb +1 -0
  24. data/lib/lite_cable/connection/base.rb +1 -0
  25. data/lib/lite_cable/connection/identification.rb +1 -0
  26. data/lib/lite_cable/connection/streams.rb +1 -0
  27. data/lib/lite_cable/connection/subscriptions.rb +1 -0
  28. data/lib/lite_cable/internal.rb +1 -0
  29. data/lib/lite_cable/logging.rb +1 -0
  30. data/lib/lite_cable/server.rb +1 -0
  31. data/lib/lite_cable/server/client_socket.rb +1 -0
  32. data/lib/lite_cable/server/client_socket/base.rb +4 -1
  33. data/lib/lite_cable/server/client_socket/subscriptions.rb +1 -0
  34. data/lib/lite_cable/server/heart_beat.rb +3 -0
  35. data/lib/lite_cable/server/middleware.rb +1 -0
  36. data/lib/lite_cable/server/subscribers_map.rb +1 -0
  37. data/lib/lite_cable/version.rb +2 -1
  38. data/lib/litecable.rb +1 -0
  39. data/litecable.gemspec +1 -1
  40. metadata +16 -3
  41. data/examples/sinatra/bin/anycable-go +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb4185917544c4f463632a1b1013df954e4e33cd
4
- data.tar.gz: 03a56b7e69b7e9b5b4bd6034106790f161ef1ab8
3
+ metadata.gz: f2dd18b7f6891c88a86835759ce61d719586e020
4
+ data.tar.gz: e1068fc004544f1b95f119c496b78978f18ca631
5
5
  SHA512:
6
- metadata.gz: cedbf509d8ed3b1498ce07de93604498f8f86cba3a1655624c65aa4d0b156e2f386a58e41bbfbc0346512ee58e27b78accf78163ef56d97a9f5f6fcdef1c99e6
7
- data.tar.gz: bb8b8afb66153923fbfe1a1109d6dbc63d6100dd99743e321066f1ee34a8b3809868d31a3a302bb9dd7afba775e4da03aba329dc6bdbdb1dab4ca459d3dd2a45
6
+ metadata.gz: b5a4d61b3a02f2ed4d9f708ee0fdf9882f33bead0a12dcc59a1e8256f8775094598771ae05c4e24b9533563545f3fad1a96856388c7cbac2276c0f245605af1d
7
+ data.tar.gz: 99fd11f00d738f3712c2359ef6085f24859c921afadc19fe23a88217ecbb8922e6ea97c81f279e3ed489af1e1b24d01e0b01871b886b4e27cb109d0300dcfdf4
@@ -10,11 +10,17 @@ AllCops:
10
10
  - 'tmp/**/*'
11
11
  - 'bench/**/*'
12
12
  - 'lib/anycable/rpc/**/*'
13
+ - 'vendor/**/*'
14
+ - 'gemfiles/**/*'
15
+ - 'Gemfile'
16
+ - 'Rakefile'
17
+ - 'examples/**/*'
18
+ - '*.gemspec'
13
19
  DisplayCopNames: true
14
20
  StyleGuideCopsOnly: false
15
21
  TargetRubyVersion: 2.3
16
22
 
17
- Style/AccessorMethodName:
23
+ Naming/AccessorMethodName:
18
24
  Enabled: false
19
25
 
20
26
  Style/TrivialAccessors:
@@ -30,13 +36,16 @@ Style/ParallelAssignment:
30
36
  Style/StringLiterals:
31
37
  Enabled: false
32
38
 
33
- Style/SpaceInsideStringInterpolation:
39
+ Layout/SpaceInsideStringInterpolation:
34
40
  EnforcedStyle: no_space
35
41
 
36
42
  Style/BlockDelimiters:
37
43
  Exclude:
38
44
  - 'spec/**/*.rb'
39
45
 
46
+ Style/NumericPredicate:
47
+ Enabled: false
48
+
40
49
  Lint/AmbiguousRegexpLiteral:
41
50
  Enabled: false
42
51
 
@@ -47,6 +56,9 @@ Metrics/MethodLength:
47
56
  Exclude:
48
57
  - 'spec/**/*.rb'
49
58
 
59
+ Metrics/AbcSize:
60
+ Max: 20
61
+
50
62
  Metrics/LineLength:
51
63
  Max: 100
52
64
  Exclude:
data/README.md CHANGED
@@ -96,9 +96,7 @@ require "anycable"
96
96
  # Turn AnyCable compatibility mode
97
97
  LiteCable.anycable!
98
98
 
99
- Anycable.configure do |config|
100
- config.connection_factory = MyApp::Connection
101
- end
99
+ Anycable.connection_factory = MyApp::Connection
102
100
 
103
101
  Anycable::Server.start
104
102
  ```
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
5
7
 
6
- task :default => :spec
8
+ task default: [:rubocop, :spec]
@@ -9,8 +9,8 @@ gem 'puma'
9
9
  gem 'pry-byebug'
10
10
 
11
11
  # litecable deps
12
- gem "anyway_config", "~> 0.5.0"
12
+ gem "anyway_config", "~> 1.0"
13
13
  gem "websocket", "~> 1.2.4"
14
14
 
15
15
  # anycable
16
- gem "anycable", "~> 0.4.2"
16
+ gem "anycable", "~> 0.5.0"
@@ -1,3 +1,3 @@
1
1
  web: ANYCABLE=1 bundle exec puma
2
2
  rpc: bundle exec ./anycable
3
- ws: sleep 2 && ./bin/anycable-go -log -addr=localhost:9293
3
+ ws: sleep 2 && anycable-go -log -addr=localhost:9293
@@ -26,6 +26,8 @@ Now you can chat with yourself!
26
26
 
27
27
  This example also can be used with [AnyCable](http://anycable.io).
28
28
 
29
+ You need [`anycable-go`](https://github.com/anycable/anycable-go) installed.
30
+
29
31
  Just run `Procfile` with your favourite tool ([hivemind](https://github.com/DarthSim/hivemind) or [Foreman](http://ddollar.github.io/foreman/)):
30
32
 
31
33
  ```sh
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  lib = File.expand_path("../../../lib", __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
 
@@ -10,9 +11,6 @@ require "anycable"
10
11
  # Turn AnyCable compatibility mode
11
12
  LiteCable.anycable!
12
13
 
13
- Anycable.configure do |config|
14
- config.connection_factory = Chat::Connection
15
- config.debug = true
16
- end
14
+ Anycable.connection_factory = Chat::Connection
17
15
 
18
16
  Anycable::Server.start
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "sinatra"
3
4
  require "sinatra/cookies"
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "litecable"
3
4
 
4
5
  # Sample chat application
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  lib = File.expand_path("../../../lib", __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "lite_cable/version"
3
4
  require "lite_cable/internal"
4
5
  require "lite_cable/logging"
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- module LiteCable
2
+
3
+ module LiteCable # :nodoc:
3
4
  # AnyCable extensions
4
5
  module AnyCable
5
6
  module Broadcasting # :nodoc:
@@ -14,10 +15,13 @@ module LiteCable
14
15
  base.prepend InstanceMethods
15
16
  end
16
17
 
17
- def create(socket, **options)
18
+ def call(socket, **options)
18
19
  new(socket, **options)
19
20
  end
20
21
 
22
+ # Backward compatibility with AnyCable <= 0.4
23
+ alias create call
24
+
21
25
  module InstanceMethods # :nodoc:
22
26
  def initialize(socket, subscriptions: nil, **hargs)
23
27
  super(socket, **hargs)
@@ -29,6 +33,7 @@ module LiteCable
29
33
  @request ||= Rack::Request.new(socket.env)
30
34
  end
31
35
 
36
+ # rubocop: disable Metrics/MethodLength
32
37
  def handle_channel_command(identifier, command, data)
33
38
  channel = subscriptions.add(identifier, false)
34
39
  case command
@@ -50,11 +55,12 @@ module LiteCable
50
55
  close
51
56
  false
52
57
  end
58
+ # rubocop: enable Metrics/MethodLength
53
59
  end
54
60
  end
55
61
  end
56
62
 
57
- # Patch Lite Cable with AnyCable functionality
63
+ # Patch Lite Cable with AnyCable functionality
58
64
  def self.anycable!
59
65
  LiteCable::Connection::Base.extend LiteCable::AnyCable::Connection
60
66
  LiteCable.singleton_class.prepend LiteCable::AnyCable::Broadcasting
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Channel # :nodoc:
4
5
  require "lite_cable/channel/registry"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  # rubocop:disable Metrics/LineLength
4
5
  module Channel
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Channel
4
5
  # Stores channels identifiers and corresponding classes.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  # rubocop:disable Metrics/LineLength
4
5
  module Channel
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Coders # :nodoc:
4
5
  require "lite_cable/coders/raw"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "json"
3
4
 
4
5
  module LiteCable
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Coders
4
5
  # No-op coder
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "anyway"
3
4
  require 'logger'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Connection # :nodoc:
4
5
  require "lite_cable/connection/authorization"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Connection
4
5
  class UnauthorizedError < StandardError; end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  # rubocop:disable Metrics/LineLength
4
5
  module Connection
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "set"
3
4
 
4
5
  module LiteCable
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Connection
4
5
  # Manage the connection streams
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Connection
4
5
  # Manage the connection channels and route messages
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  INTERNAL = {
4
5
  message_types: {
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'logger'
3
4
 
4
5
  module LiteCable
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  # Rack middleware to hijack sockets.
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Server
4
5
  module ClientSocket # :nodoc:
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Server
4
5
  module ClientSocket
@@ -61,6 +62,7 @@ module LiteCable
61
62
  @error_handlers << block
62
63
  end
63
64
 
65
+ # rubocop: disable Metrics/MethodLength
64
66
  def listen
65
67
  keepalive
66
68
  Thread.new do
@@ -71,7 +73,7 @@ module LiteCable
71
73
  @message_handlers.each do |h|
72
74
  begin
73
75
  h.call(data)
74
- rescue => e
76
+ rescue => e # rubocop: disable Lint/RescueWithoutErrorClass
75
77
  log(:error, "Socket receive failed: #{e}")
76
78
  @error_handlers.each { |eh| eh.call(e, data) }
77
79
  close if close_on_error
@@ -83,6 +85,7 @@ module LiteCable
83
85
  end
84
86
  end
85
87
  end
88
+ # rubocop: enable Metrics/MethodLength
86
89
 
87
90
  def close
88
91
  return unless @active
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Server
4
5
  module ClientSocket
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Server
4
5
  # Sends pings to sockets
@@ -22,6 +23,7 @@ module LiteCable
22
23
  @stopped = true
23
24
  end
24
25
 
26
+ # rubocop: disable Metrics/MethodLength
25
27
  def run
26
28
  Thread.new do
27
29
  Thread.current.abort_on_exception = true
@@ -39,6 +41,7 @@ module LiteCable
39
41
  end
40
42
  end
41
43
  end
44
+ # rubocop: enable Metrics/MethodLength
42
45
 
43
46
  private
44
47
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Server
4
5
  # Rack middleware to hijack the socket
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
4
  module Server
4
5
  # From https://github.com/rails/rails/blob/v5.0.1/actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module LiteCable
3
- VERSION = "0.4.2"
4
+ VERSION = "0.5.0"
4
5
  end
@@ -1,2 +1,3 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "lite_cable"
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'lite_cable/version'
@@ -29,5 +28,6 @@ Gem::Specification.new do |spec|
29
28
  spec.add_development_dependency "rake", ">= 10.0"
30
29
  spec.add_development_dependency "rspec", "~> 3.0"
31
30
  spec.add_development_dependency "simplecov", ">= 0.3.8"
31
+ spec.add_development_dependency "rubocop", ">= 0.50"
32
32
  spec.add_development_dependency "pry-byebug"
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: litecable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-06 00:00:00.000000000 Z
11
+ date: 2017-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anyway_config
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: 0.3.8
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0.50'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0.50'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: pry-byebug
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -193,7 +207,6 @@ files:
193
207
  - examples/sinatra/assets/app.css
194
208
  - examples/sinatra/assets/cable.js
195
209
  - examples/sinatra/assets/reset.css
196
- - examples/sinatra/bin/anycable-go
197
210
  - examples/sinatra/chat.rb
198
211
  - examples/sinatra/config.ru
199
212
  - examples/sinatra/views/index.slim