anycable-rails 1.1.3 → 1.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 382f9a246580ced6d4142cb584ac2da9dffd519c32eccc6f407294f95159eaee
4
- data.tar.gz: a3ee884685392322889613d19ea5625d68bfb7a4c16de849f43175ca0dace7ad
3
+ metadata.gz: 59a60ff31ba3907089d78beaedf01b69a66ff2e7da83175dcd8e19d78bd6e9aa
4
+ data.tar.gz: 1b9a709873bf7409502c2e114b9b90ae32ce94a724d5a3091d22ea8a7c86cd76
5
5
  SHA512:
6
- metadata.gz: 1de65d96f4496919d2da4761e43707493a851aeb75173693a85c9e38af1bfbd884ded0d9545c655dcd4d1d8b17d2dcc69711c1bd075d42d77f774e22507b36f1
7
- data.tar.gz: ee2584eaaa25cd406a57fe7c1df9336ebfbf4777c6c9ba806c9aa018a0c0e7bd2c0ffd3f484db4bc99138ad830e206777992b51adc70b04b907ef3af5fe1c332
6
+ metadata.gz: 80d3114d9eb008e7dce61d772a71608f87c0c24eb60dbed31f857abbdb7271d7a13a4a1103609910e6eef51d576a761e92f8a40cc134f3ab95b314f247e60551
7
+ data.tar.gz: cbd7a8c52da4ddd60023f536d99be251dee6158c0639744c0235b9876d4efcba9ab983ad9f06a0605cd187afaa34f2b2c1975c7b949a188e26d44860553cd88e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.1.4 (2021-11-11)
6
+
7
+ - Added `Connection#state_attr_accessor`. ([@palkan][])
8
+
5
9
  ## 1.1.3 (2021-10-11)
6
10
 
7
11
  - Relax Action Cable dependency. ([@palkan][])
@@ -9,7 +9,6 @@ require "anycable/rails/session_proxy"
9
9
 
10
10
  module ActionCable
11
11
  module Connection
12
- # rubocop: disable Metrics/ClassLength
13
12
  class Base # :nodoc:
14
13
  # We store logger tags in the connection state to be able
15
14
  # to re-use them in the subsequent calls
@@ -98,7 +97,6 @@ module ActionCable
98
97
  true
99
98
  end
100
99
 
101
- # rubocop:disable Metrics/MethodLength
102
100
  def handle_channel_command(identifier, command, data)
103
101
  channel = subscriptions.fetch(identifier)
104
102
  case command
@@ -5,7 +5,7 @@
5
5
  # Trigger autoload (if constant is defined)
6
6
  begin
7
7
  ActionCable::Channel::TestCase # rubocop:disable Lint/Void
8
- ActionCable::Connection::TestCase # rubocop:disable Lint/Void
8
+ ActionCable::Connection::TestCase
9
9
  rescue NameError
10
10
  return
11
11
  end
@@ -44,10 +44,54 @@ module AnyCable
44
44
  @__istate__ ||= connection.socket.istate
45
45
  end
46
46
  end
47
+
48
+ module ConnectionState
49
+ module ClassMethods
50
+ def state_attr_accessor(*names)
51
+ names.each do |name|
52
+ connection_state_attributes << name
53
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
54
+ def #{name}
55
+ return @#{name} if instance_variable_defined?(:@#{name})
56
+ @#{name} = AnyCable::Rails.deserialize(__cstate__["#{name}"], json: true) if anycable_socket
57
+ end
58
+
59
+ def #{name}=(val)
60
+ __cstate__["#{name}"] = AnyCable::Rails.serialize(val, json: true) if anycable_socket
61
+ instance_variable_set(:@#{name}, val)
62
+ end
63
+ RUBY
64
+ end
65
+ end
66
+
67
+ def connection_state_attributes
68
+ return @connection_state_attributes if instance_variable_defined?(:@connection_state_attributes)
69
+
70
+ @connection_state_attributes =
71
+ if superclass.respond_to?(:connection_state_attributes)
72
+ superclass.connection_state_attributes.dup
73
+ else
74
+ []
75
+ end
76
+ end
77
+ end
78
+
79
+ def self.included(base)
80
+ base.extend ClassMethods
81
+ end
82
+
83
+ # Make it possible to provide istate explicitly for a connection instance
84
+ attr_writer :__cstate__
85
+
86
+ def __cstate__
87
+ @__cstate__ ||= socket.cstate
88
+ end
89
+ end
47
90
  end
48
91
  end
49
92
 
50
93
  ActiveSupport.on_load(:action_cable) do
51
94
  # `state_attr_accessor` must be available in Action Cable
95
+ ::ActionCable::Connection::Base.include(AnyCable::Rails::ConnectionState)
52
96
  ::ActionCable::Channel::Base.include(AnyCable::Rails::ChannelState)
53
97
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module AnyCable
4
4
  module Rails
5
- VERSION = "1.1.3"
5
+ VERSION = "1.1.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anycable-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-11 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anycable