cable_ready 4.4.0 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3abe83511c1ca40cd20ff9d24cdc3fd0fa6cd9581dba8bad69d65ee75531bd1
4
- data.tar.gz: 6a5c2830efa380cd4c611ba9f5997aca05ba03da6bc26e54f7055bdb7963cfbf
3
+ metadata.gz: b7306ba066c9ee64f5a46290d6f24e29e0dd55ed26869101db08f4556cd9d05d
4
+ data.tar.gz: e072e9feec793f2a64f9c4134ebf5bf31f92ac4d5075d288237f4587895bec1c
5
5
  SHA512:
6
- metadata.gz: 8cc8f86a38a0c4bd000c5ea8d80a80f8c1ae0350f1644545d25416d63240364e0a4b70dde273eee9a01eb6691895e1477f748ef7253e45370b3ed00f1d9c2949
7
- data.tar.gz: 6aa1554dd99a8131dd1de913b8675a735086121a7843f040bb820e57901fc12abb7b42d816ed90ac1ea4e8bf3c892c465964f288c4bd3d41687eac52c2b39575
6
+ metadata.gz: e3264fdb6d50c9e1d3309c8a6ff82f283546f41f47df2b5e929ab7b9180d0c4f7d6b0d25e9a88512f0c8851ccabd2a35f2b96bc4bf004fd7122b106aff9c9343
7
+ data.tar.gz: 443016a6d1020a3aae79d161e3b0dcce298ed203e8ddede5692635b49685b2a74b9b843c67593a3200c2da4a3b4cc1e756cbc616e8a6bc71622adf533ae7a995
@@ -1,5 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## [v4.4.5](https://github.com/hopsoft/cable_ready/tree/v4.4.5) (2020-12-13)
4
+
5
+ [Full Changelog](https://github.com/hopsoft/cable_ready/compare/v4.4.4...v4.4.5)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - changed storage method names, added clear flag [\#86](https://github.com/hopsoft/cable_ready/pull/86) ([leastbad](https://github.com/leastbad))
10
+
11
+ ## [v4.4.4](https://github.com/hopsoft/cable_ready/tree/v4.4.4) (2020-12-11)
12
+
13
+ [Full Changelog](https://github.com/hopsoft/cable_ready/compare/v4.4.3...v4.4.4)
14
+
15
+ **Merged pull requests:**
16
+
17
+ - Add support for sessionStorage and localStorage [\#83](https://github.com/hopsoft/cable_ready/pull/83) ([hopsoft](https://github.com/hopsoft))
18
+
19
+ ## [v4.4.3](https://github.com/hopsoft/cable_ready/tree/v4.4.3) (2020-12-01)
20
+
21
+ [Full Changelog](https://github.com/hopsoft/cable_ready/compare/v4.4.2...v4.4.3)
22
+
23
+ **Merged pull requests:**
24
+
25
+ - Fix bug related to channel calling broadcast on the singleton [\#82](https://github.com/hopsoft/cable_ready/pull/82) ([hopsoft](https://github.com/hopsoft))
26
+
27
+ ## [v4.4.2](https://github.com/hopsoft/cable_ready/tree/v4.4.2) (2020-11-30)
28
+
29
+ [Full Changelog](https://github.com/hopsoft/cable_ready/compare/v4.4.1...v4.4.2)
30
+
31
+ ## [v4.4.1](https://github.com/hopsoft/cable_ready/tree/v4.4.1) (2020-11-28)
32
+
33
+ [Full Changelog](https://github.com/hopsoft/cable_ready/compare/v4.4.0...v4.4.1)
34
+
35
+ **Merged pull requests:**
36
+
37
+ - Apply setFocus behavior to more element mutations [\#81](https://github.com/hopsoft/cable_ready/pull/81) ([hopsoft](https://github.com/hopsoft))
38
+
39
+ ## [v4.4.0](https://github.com/hopsoft/cable_ready/tree/v4.4.0) (2020-11-24)
40
+
41
+ [Full Changelog](https://github.com/hopsoft/cable_ready/compare/v4.4.0.pre4...v4.4.0)
42
+
3
43
  ## [v4.4.0.pre4](https://github.com/hopsoft/cable_ready/tree/v4.4.0.pre4) (2020-11-22)
4
44
 
5
45
  [Full Changelog](https://github.com/hopsoft/cable_ready/compare/v4.4.0.pre3...v4.4.0.pre4)
@@ -116,8 +156,6 @@
116
156
  - Support for multiple CSS classes. [\#49](https://github.com/hopsoft/cable_ready/pull/49) ([sarriagada](https://github.com/sarriagada))
117
157
  - Make morph emit after event [\#48](https://github.com/hopsoft/cable_ready/pull/48) ([julianrubisch](https://github.com/julianrubisch))
118
158
  - Customize operations via initializer [\#47](https://github.com/hopsoft/cable_ready/pull/47) ([leastbad](https://github.com/leastbad))
119
- - Correct method 'outerHtml' to 'outer\_html' in documentation [\#39](https://github.com/hopsoft/cable_ready/pull/39) ([pskarlas](https://github.com/pskarlas))
120
- - Add setStyles [\#37](https://github.com/hopsoft/cable_ready/pull/37) ([excid3](https://github.com/excid3))
121
159
  - Fix typo in method name outerHTML -\> outer\_html [\#35](https://github.com/hopsoft/cable_ready/pull/35) ([back2war](https://github.com/back2war))
122
160
 
123
161
  ## [v4.2.0](https://github.com/hopsoft/cable_ready/tree/v4.2.0) (2020-06-02)
@@ -132,6 +170,8 @@
132
170
 
133
171
  - after-outer-html emitted from new element [\#46](https://github.com/hopsoft/cable_ready/pull/46) ([leastbad](https://github.com/leastbad))
134
172
  - Fix `outer\_html` notation [\#45](https://github.com/hopsoft/cable_ready/pull/45) ([julianrubisch](https://github.com/julianrubisch))
173
+ - Correct method 'outerHtml' to 'outer\_html' in documentation [\#39](https://github.com/hopsoft/cable_ready/pull/39) ([pskarlas](https://github.com/pskarlas))
174
+ - Add setStyles [\#37](https://github.com/hopsoft/cable_ready/pull/37) ([excid3](https://github.com/excid3))
135
175
  - Print out the selector for easier debugging perform errors [\#36](https://github.com/hopsoft/cable_ready/pull/36) ([excid3](https://github.com/excid3))
136
176
  - add set\_property method to library [\#34](https://github.com/hopsoft/cable_ready/pull/34) ([leastbad](https://github.com/leastbad))
137
177
 
@@ -1,80 +1,87 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cable_ready (4.4.0)
4
+ cable_ready (4.5.0)
5
5
  rails (>= 5.2)
6
+ thread-local (>= 1.1.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- actioncable (6.0.3.4)
11
- actionpack (= 6.0.3.4)
11
+ actioncable (6.1.1)
12
+ actionpack (= 6.1.1)
13
+ activesupport (= 6.1.1)
12
14
  nio4r (~> 2.0)
13
15
  websocket-driver (>= 0.6.1)
14
- actionmailbox (6.0.3.4)
15
- actionpack (= 6.0.3.4)
16
- activejob (= 6.0.3.4)
17
- activerecord (= 6.0.3.4)
18
- activestorage (= 6.0.3.4)
19
- activesupport (= 6.0.3.4)
16
+ actionmailbox (6.1.1)
17
+ actionpack (= 6.1.1)
18
+ activejob (= 6.1.1)
19
+ activerecord (= 6.1.1)
20
+ activestorage (= 6.1.1)
21
+ activesupport (= 6.1.1)
20
22
  mail (>= 2.7.1)
21
- actionmailer (6.0.3.4)
22
- actionpack (= 6.0.3.4)
23
- actionview (= 6.0.3.4)
24
- activejob (= 6.0.3.4)
23
+ actionmailer (6.1.1)
24
+ actionpack (= 6.1.1)
25
+ actionview (= 6.1.1)
26
+ activejob (= 6.1.1)
27
+ activesupport (= 6.1.1)
25
28
  mail (~> 2.5, >= 2.5.4)
26
29
  rails-dom-testing (~> 2.0)
27
- actionpack (6.0.3.4)
28
- actionview (= 6.0.3.4)
29
- activesupport (= 6.0.3.4)
30
- rack (~> 2.0, >= 2.0.8)
30
+ actionpack (6.1.1)
31
+ actionview (= 6.1.1)
32
+ activesupport (= 6.1.1)
33
+ rack (~> 2.0, >= 2.0.9)
31
34
  rack-test (>= 0.6.3)
32
35
  rails-dom-testing (~> 2.0)
33
36
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
- actiontext (6.0.3.4)
35
- actionpack (= 6.0.3.4)
36
- activerecord (= 6.0.3.4)
37
- activestorage (= 6.0.3.4)
38
- activesupport (= 6.0.3.4)
37
+ actiontext (6.1.1)
38
+ actionpack (= 6.1.1)
39
+ activerecord (= 6.1.1)
40
+ activestorage (= 6.1.1)
41
+ activesupport (= 6.1.1)
39
42
  nokogiri (>= 1.8.5)
40
- actionview (6.0.3.4)
41
- activesupport (= 6.0.3.4)
43
+ actionview (6.1.1)
44
+ activesupport (= 6.1.1)
42
45
  builder (~> 3.1)
43
46
  erubi (~> 1.4)
44
47
  rails-dom-testing (~> 2.0)
45
48
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
- activejob (6.0.3.4)
47
- activesupport (= 6.0.3.4)
49
+ activejob (6.1.1)
50
+ activesupport (= 6.1.1)
48
51
  globalid (>= 0.3.6)
49
- activemodel (6.0.3.4)
50
- activesupport (= 6.0.3.4)
51
- activerecord (6.0.3.4)
52
- activemodel (= 6.0.3.4)
53
- activesupport (= 6.0.3.4)
54
- activestorage (6.0.3.4)
55
- actionpack (= 6.0.3.4)
56
- activejob (= 6.0.3.4)
57
- activerecord (= 6.0.3.4)
52
+ activemodel (6.1.1)
53
+ activesupport (= 6.1.1)
54
+ activerecord (6.1.1)
55
+ activemodel (= 6.1.1)
56
+ activesupport (= 6.1.1)
57
+ activestorage (6.1.1)
58
+ actionpack (= 6.1.1)
59
+ activejob (= 6.1.1)
60
+ activerecord (= 6.1.1)
61
+ activesupport (= 6.1.1)
58
62
  marcel (~> 0.3.1)
59
- activesupport (6.0.3.4)
63
+ mimemagic (~> 0.3.2)
64
+ activesupport (6.1.1)
60
65
  concurrent-ruby (~> 1.0, >= 1.0.2)
61
- i18n (>= 0.7, < 2)
62
- minitest (~> 5.1)
63
- tzinfo (~> 1.1)
64
- zeitwerk (~> 2.2, >= 2.2.2)
66
+ i18n (>= 1.6, < 2)
67
+ minitest (>= 5.1)
68
+ tzinfo (~> 2.0)
69
+ zeitwerk (~> 2.3)
65
70
  addressable (2.7.0)
66
71
  public_suffix (>= 2.0.2, < 5.0)
67
- ast (2.4.1)
72
+ ast (2.4.2)
68
73
  builder (3.2.4)
69
74
  coderay (1.1.3)
70
- concurrent-ruby (1.1.7)
75
+ concurrent-ruby (1.1.8)
71
76
  crass (1.0.6)
72
77
  erubi (1.10.0)
73
- faraday (1.1.0)
78
+ faraday (1.3.0)
79
+ faraday-net_http (~> 1.0)
74
80
  multipart-post (>= 1.2, < 3)
75
81
  ruby2_keywords
76
82
  faraday-http-cache (2.2.0)
77
83
  faraday (>= 0.8)
84
+ faraday-net_http (1.0.1)
78
85
  github_changelog_generator (1.15.2)
79
86
  activesupport
80
87
  faraday-http-cache
@@ -85,9 +92,9 @@ GEM
85
92
  retriable (~> 3.0)
86
93
  globalid (0.4.2)
87
94
  activesupport (>= 4.2.0)
88
- i18n (1.8.5)
95
+ i18n (1.8.7)
89
96
  concurrent-ruby (~> 1.0)
90
- loofah (2.7.0)
97
+ loofah (2.9.0)
91
98
  crass (~> 1.0.2)
92
99
  nokogiri (>= 1.5.9)
93
100
  magic_frozen_string_literal (1.2.0)
@@ -98,18 +105,17 @@ GEM
98
105
  method_source (0.9.2)
99
106
  mimemagic (0.3.5)
100
107
  mini_mime (1.0.2)
101
- mini_portile2 (2.4.0)
102
- minitest (5.14.2)
108
+ minitest (5.14.3)
103
109
  multi_json (1.15.0)
104
110
  multipart-post (2.1.1)
105
111
  nio4r (2.5.4)
106
- nokogiri (1.10.10)
107
- mini_portile2 (~> 2.4.0)
108
- octokit (4.19.0)
112
+ nokogiri (1.11.1-x86_64-darwin)
113
+ racc (~> 1.4)
114
+ octokit (4.20.0)
109
115
  faraday (>= 0.9)
110
116
  sawyer (~> 0.8.0, >= 0.5.3)
111
117
  parallel (1.20.1)
112
- parser (2.7.2.0)
118
+ parser (3.0.0.0)
113
119
  ast (~> 2.4.1)
114
120
  pry (0.12.2)
115
121
  coderay (~> 1.1.0)
@@ -117,56 +123,57 @@ GEM
117
123
  pry-nav (0.3.0)
118
124
  pry (>= 0.9.10, < 0.13.0)
119
125
  public_suffix (4.0.6)
126
+ racc (1.5.2)
120
127
  rack (2.2.3)
121
128
  rack-test (1.1.0)
122
129
  rack (>= 1.0, < 3)
123
- rails (6.0.3.4)
124
- actioncable (= 6.0.3.4)
125
- actionmailbox (= 6.0.3.4)
126
- actionmailer (= 6.0.3.4)
127
- actionpack (= 6.0.3.4)
128
- actiontext (= 6.0.3.4)
129
- actionview (= 6.0.3.4)
130
- activejob (= 6.0.3.4)
131
- activemodel (= 6.0.3.4)
132
- activerecord (= 6.0.3.4)
133
- activestorage (= 6.0.3.4)
134
- activesupport (= 6.0.3.4)
135
- bundler (>= 1.3.0)
136
- railties (= 6.0.3.4)
130
+ rails (6.1.1)
131
+ actioncable (= 6.1.1)
132
+ actionmailbox (= 6.1.1)
133
+ actionmailer (= 6.1.1)
134
+ actionpack (= 6.1.1)
135
+ actiontext (= 6.1.1)
136
+ actionview (= 6.1.1)
137
+ activejob (= 6.1.1)
138
+ activemodel (= 6.1.1)
139
+ activerecord (= 6.1.1)
140
+ activestorage (= 6.1.1)
141
+ activesupport (= 6.1.1)
142
+ bundler (>= 1.15.0)
143
+ railties (= 6.1.1)
137
144
  sprockets-rails (>= 2.0.0)
138
145
  rails-dom-testing (2.0.3)
139
146
  activesupport (>= 4.2.0)
140
147
  nokogiri (>= 1.6)
141
148
  rails-html-sanitizer (1.3.0)
142
149
  loofah (~> 2.3)
143
- railties (6.0.3.4)
144
- actionpack (= 6.0.3.4)
145
- activesupport (= 6.0.3.4)
150
+ railties (6.1.1)
151
+ actionpack (= 6.1.1)
152
+ activesupport (= 6.1.1)
146
153
  method_source
147
154
  rake (>= 0.8.7)
148
- thor (>= 0.20.3, < 2.0)
155
+ thor (~> 1.0)
149
156
  rainbow (3.0.0)
150
- rake (13.0.1)
151
- regexp_parser (1.8.2)
157
+ rake (13.0.3)
158
+ regexp_parser (2.0.3)
152
159
  retriable (3.1.2)
153
160
  rexml (3.2.4)
154
- rubocop (1.2.0)
161
+ rubocop (1.7.0)
155
162
  parallel (~> 1.10)
156
163
  parser (>= 2.7.1.5)
157
164
  rainbow (>= 2.2.2, < 4.0)
158
- regexp_parser (>= 1.8)
165
+ regexp_parser (>= 1.8, < 3.0)
159
166
  rexml
160
- rubocop-ast (>= 1.0.1)
167
+ rubocop-ast (>= 1.2.0, < 2.0)
161
168
  ruby-progressbar (~> 1.7)
162
169
  unicode-display_width (>= 1.4.0, < 2.0)
163
- rubocop-ast (1.1.1)
170
+ rubocop-ast (1.4.1)
164
171
  parser (>= 2.7.1.5)
165
- rubocop-performance (1.8.1)
166
- rubocop (>= 0.87.0)
172
+ rubocop-performance (1.9.2)
173
+ rubocop (>= 0.90.0, < 2.0)
167
174
  rubocop-ast (>= 0.4.0)
168
- ruby-progressbar (1.10.1)
169
- ruby2_keywords (0.0.2)
175
+ ruby-progressbar (1.11.0)
176
+ ruby2_keywords (0.0.4)
170
177
  sawyer (0.8.2)
171
178
  addressable (>= 2.3.5)
172
179
  faraday (> 0.8, < 2.0)
@@ -177,20 +184,20 @@ GEM
177
184
  actionpack (>= 4.0)
178
185
  activesupport (>= 4.0)
179
186
  sprockets (>= 3.0.0)
180
- standard (0.9.0)
181
- rubocop (= 1.2.0)
182
- rubocop-performance (= 1.8.1)
187
+ standard (0.11.0)
188
+ rubocop (= 1.7.0)
189
+ rubocop-performance (= 1.9.2)
183
190
  standardrb (1.0.0)
184
191
  standard
185
- thor (1.0.1)
186
- thread_safe (0.3.6)
187
- tzinfo (1.2.8)
188
- thread_safe (~> 0.1)
192
+ thor (1.1.0)
193
+ thread-local (1.1.0)
194
+ tzinfo (2.0.4)
195
+ concurrent-ruby (~> 1.0)
189
196
  unicode-display_width (1.7.0)
190
197
  websocket-driver (0.7.3)
191
198
  websocket-extensions (>= 0.1.0)
192
199
  websocket-extensions (0.1.5)
193
- zeitwerk (2.4.1)
200
+ zeitwerk (2.4.2)
194
201
 
195
202
  PLATFORMS
196
203
  ruby
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  <img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-brightgreen.svg" target="_blank" />
12
12
  </a>
13
13
  <a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/" target="_blank">
14
- <img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-422-brightgreen.svg?style=flat" />
14
+ <img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-663-brightgreen.svg?style=flat" />
15
15
  </a>
16
16
  <a href="https://cableready.stimulusreflex.com" target="_blank">
17
17
  <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
@@ -30,9 +30,6 @@
30
30
  <a href="https://www.codacy.com/manual/hopsoft/cable_ready/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=hopsoft/cable_ready&amp;utm_campaign=Badge_Grade" target="_blank">
31
31
  <img alt="Code Quality" src="https://app.codacy.com/project/badge/Grade/8e6971e3410347eaaa16be2555160b9c"/>
32
32
  </a>
33
- <a href="https://codeclimate.com/github/hopsoft/cable_ready/maintainability" target="_blank">
34
- <img alt="Maintainability" src="https://api.codeclimate.com/v1/badges/83ddf1fee4af7e51a681/maintainability" />
35
- </a>
36
33
  <a target="_blank" rel="noopener noreferrer" href="https://github.com/hopsoft/cable_ready/workflows/Prettier-Standard/badge.svg">
37
34
  <img src="https://github.com/hopsoft/cable_ready/workflows/Prettier-Standard/badge.svg" alt="Prettier-Standard" style="max-width:100%;">
38
35
  </a>
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.test_files = Dir["test/**/*.rb"]
16
16
 
17
17
  gem.add_dependency "rails", ">= 5.2"
18
+ gem.add_dependency "thread-local", ">= 1.1.0"
18
19
 
19
20
  gem.add_development_dependency "github_changelog_generator"
20
21
  gem.add_development_dependency "magic_frozen_string_literal"
@@ -3,9 +3,18 @@
3
3
  require "rails/engine"
4
4
  require "active_support/all"
5
5
  require "cable_ready/version"
6
+ require "cable_ready/config"
6
7
  require "cable_ready/broadcaster"
7
8
 
8
9
  module CableReady
9
10
  class Engine < Rails::Engine
10
11
  end
12
+
13
+ def self.config
14
+ CableReady::Config.instance
15
+ end
16
+
17
+ def self.configure
18
+ yield config
19
+ end
11
20
  end
@@ -2,48 +2,46 @@
2
2
 
3
3
  module CableReady
4
4
  class Channel
5
- attr_reader :identifier, :operations, :available_operations
5
+ attr_reader :identifier, :enqueued_operations
6
6
 
7
- def initialize(identifier, available_operations)
7
+ def initialize(identifier)
8
8
  @identifier = identifier
9
- @available_operations = available_operations
10
9
  reset
11
- available_operations.each do |available_operation, implementation|
12
- define_singleton_method available_operation, &implementation
13
- end
14
- end
10
+ CableReady.config.operation_names.each { |name| add_operation_method name }
15
11
 
16
- def channel_broadcast(clear)
17
- operations.select! { |_, list| list.present? }
18
- operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
19
- ActionCable.server.broadcast identifier, {"cableReady" => true, "operations" => operations}
20
- reset if clear
12
+ config_observer = self
13
+ CableReady.config.add_observer config_observer, :add_operation_method
14
+ ObjectSpace.define_finalizer self, -> { CableReady.config.delete_observer config_observer }
21
15
  end
22
16
 
23
- def channel_broadcast_to(model, clear)
24
- operations.select! { |_, list| list.present? }
25
- operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
26
- identifier.broadcast_to model, {"cableReady" => true, "operations" => operations}
17
+ def broadcast(clear: true)
18
+ ActionCable.server.broadcast identifier, {"cableReady" => true, "operations" => broadcastable_operations}
27
19
  reset if clear
28
20
  end
29
21
 
30
- def broadcast(clear = true)
31
- CableReady::Channels.instance.broadcast(identifier, clear)
22
+ def broadcast_to(model, clear: true)
23
+ identifier.broadcast_to model, {"cableReady" => true, "operations" => broadcastable_operations}
24
+ reset if clear
32
25
  end
33
26
 
34
- def broadcast_to(model, clear = true)
35
- CableReady::Channels.instance.broadcast_to(model, identifier, clear)
27
+ def add_operation_method(name)
28
+ return if respond_to?(name)
29
+ singleton_class.public_send :define_method, name, ->(options = {}) {
30
+ enqueued_operations[name.to_s] << options.stringify_keys
31
+ self # supports operation chaining
32
+ }
36
33
  end
37
34
 
38
35
  private
39
36
 
40
- def enqueue_operation(key, options)
41
- operations[key] << options
42
- self
37
+ def reset
38
+ @enqueued_operations = Hash.new { |hash, key| hash[key] = [] }
43
39
  end
44
40
 
45
- def reset
46
- @operations = Hash.new { |hash, operation| hash[operation] = [] }
41
+ def broadcastable_operations
42
+ enqueued_operations
43
+ .select { |_, list| list.present? }
44
+ .deep_transform_keys! { |key| key.to_s.camelize(:lower) }
47
45
  end
48
46
  end
49
47
  end
@@ -1,83 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "thread/local"
3
4
  require_relative "channel"
4
5
 
5
6
  module CableReady
7
+ # This class is a thread local singleton: CableReady::Channels.instance
8
+ # SEE: https://github.com/socketry/thread-local/tree/master/guides/getting-started
6
9
  class Channels
7
- include Singleton
8
- attr_accessor :operations
10
+ extend Thread::Local
9
11
 
10
- def self.configure
11
- yield CableReady::Channels.instance if block_given?
12
- end
12
+ attr_accessor :operations
13
13
 
14
14
  def initialize
15
15
  @channels = {}
16
16
  @operations = {}
17
- %i[
18
- add_css_class
19
- console_log
20
- dispatch_event
21
- inner_html
22
- insert_adjacent_html
23
- insert_adjacent_text
24
- morph
25
- notification
26
- outer_html
27
- push_state
28
- remove
29
- remove_attribute
30
- remove_css_class
31
- set_attribute
32
- set_cookie
33
- set_dataset_property
34
- set_focus
35
- set_property
36
- set_style
37
- set_styles
38
- set_value
39
- text_content
40
- ].each do |operation|
41
- add_operation operation
42
- end
43
- end
44
-
45
- def add_operation(operation, &implementation)
46
- @operations[operation] = implementation || ->(options = {}) { enqueue_operation(operation, options) }
47
17
  end
48
18
 
49
19
  def [](identifier)
50
- @channels[identifier] ||= CableReady::Channel.new(identifier, operations)
20
+ @channels[identifier] ||= CableReady::Channel.new(identifier)
51
21
  end
52
22
 
53
23
  def broadcast(*identifiers, clear: true)
54
- mutex.synchronize do
55
- @channels.values
56
- .reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
57
- .select { |channel| channel.identifier.is_a?(String) }
58
- .tap do |channels|
59
- channels.each { |channel| @channels[channel.identifier].channel_broadcast(clear) }
60
- channels.each { |channel| @channels.except!(channel.identifier) if clear }
61
- end
62
- end
24
+ @channels.values
25
+ .reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
26
+ .select { |channel| channel.identifier.is_a?(String) }
27
+ .tap do |channels|
28
+ channels.each { |channel| @channels[channel.identifier].broadcast(clear: clear) }
29
+ channels.each { |channel| @channels.except!(channel.identifier) if clear }
30
+ end
63
31
  end
64
32
 
65
33
  def broadcast_to(model, *identifiers, clear: true)
66
- mutex.synchronize do
67
- @channels.values
68
- .reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
69
- .reject { |channel| channel.identifier.is_a?(String) }
70
- .tap do |channels|
71
- channels.each { |channel| @channels[channel.identifier].channel_broadcast_to(model, clear) }
72
- channels.each { |channel| @channels.except!(channel.identifier) if clear }
73
- end
74
- end
75
- end
76
-
77
- private
78
-
79
- def mutex
80
- @mutex ||= Mutex.new
34
+ @channels.values
35
+ .reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
36
+ .reject { |channel| channel.identifier.is_a?(String) }
37
+ .tap do |channels|
38
+ channels.each { |channel| @channels[channel.identifier].broadcast_to(model, clear: clear) }
39
+ channels.each { |channel| @channels.except!(channel.identifier) if clear }
40
+ end
81
41
  end
82
42
  end
83
43
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "monitor"
4
+ require "observer"
5
+ require "singleton"
6
+
7
+ module CableReady
8
+ # This class is a process level singleton shared by all threads: CableReady::Config.instance
9
+ class Config
10
+ include MonitorMixin
11
+ include Observable
12
+ include Singleton
13
+
14
+ def initialize
15
+ super
16
+ @operation_names = Set.new(default_operation_names)
17
+ end
18
+
19
+ def operation_names
20
+ @operation_names.to_a
21
+ end
22
+
23
+ def add_operation_name(name)
24
+ synchronize do
25
+ @operation_names << name.to_sym
26
+ notify_observers name.to_sym
27
+ end
28
+ end
29
+
30
+ def default_operation_names
31
+ Set.new(%i[
32
+ add_css_class
33
+ append
34
+ clear_storage
35
+ console_log
36
+ dispatch_event
37
+ go
38
+ graft
39
+ inner_html
40
+ insert_adjacent_html
41
+ insert_adjacent_text
42
+ morph
43
+ notification
44
+ outer_html
45
+ play_sound
46
+ prepend
47
+ push_state
48
+ remove
49
+ remove_attribute
50
+ remove_css_class
51
+ remove_storage_item
52
+ replace
53
+ replace_state
54
+ scroll_into_view
55
+ set_attribute
56
+ set_cookie
57
+ set_dataset_property
58
+ set_focus
59
+ set_property
60
+ set_storage_item
61
+ set_style
62
+ set_styles
63
+ set_value
64
+ text_content
65
+ ]).freeze
66
+ end
67
+ end
68
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CableReady
4
- VERSION = "4.4.0"
4
+ VERSION = "4.5.0"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cable_ready",
3
- "version": "4.4.0-pre4",
3
+ "version": "4.4.6",
4
4
  "description": "CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby.",
5
5
  "keywords": [
6
6
  "ruby",
data/tags CHANGED
@@ -9,49 +9,54 @@ CableReady lib/cable_ready.rb /^module CableReady$/;" m
9
9
  CableReady lib/cable_ready/broadcaster.rb /^module CableReady$/;" m
10
10
  CableReady lib/cable_ready/channel.rb /^module CableReady$/;" m
11
11
  CableReady lib/cable_ready/channels.rb /^module CableReady$/;" m
12
+ CableReady lib/cable_ready/config.rb /^module CableReady$/;" m
12
13
  CableReady lib/cable_ready/version.rb /^module CableReady$/;" m
13
14
  Channel lib/cable_ready/channel.rb /^ class Channel$/;" c class:CableReady
14
15
  Channels lib/cable_ready/channels.rb /^ class Channels$/;" c class:CableReady
16
+ Config lib/cable_ready/config.rb /^ class Config$/;" c class:CableReady
15
17
  Engine lib/cable_ready.rb /^ class Engine < Rails::Engine$/;" c class:CableReady
16
18
  [] lib/cable_ready/channels.rb /^ def [](identifier)$/;" f class:CableReady.Channels
17
- add_operation lib/cable_ready/channels.rb /^ def add_operation(operation, &implementation)$/;" f class:CableReady.Channels
18
- broadcast lib/cable_ready/channel.rb /^ def broadcast(clear = true)$/;" f class:CableReady.Channel
19
+ add_operation_definition lib/cable_ready/config.rb /^ def add_operation_definition(name)$/;" f class:CableReady.Config
20
+ add_operation_method lib/cable_ready/channel.rb /^ def add_operation_method(name)$/;" f class:CableReady.Channel
21
+ broadcast lib/cable_ready/channel.rb /^ def broadcast(clear: true)$/;" f class:CableReady.Channel
19
22
  broadcast lib/cable_ready/channels.rb /^ def broadcast(*identifiers, clear: true)$/;" f class:CableReady.Channels
20
- broadcast_to lib/cable_ready/channel.rb /^ def broadcast_to(model, clear = true)$/;" f class:CableReady.Channel
23
+ broadcast_to lib/cable_ready/channel.rb /^ def broadcast_to(model, clear: true)$/;" f class:CableReady.Channel
21
24
  broadcast_to lib/cable_ready/channels.rb /^ def broadcast_to(model, *identifiers, clear: true)$/;" f class:CableReady.Channels
25
+ broadcastable_operations lib/cable_ready/channel.rb /^ def broadcastable_operations$/;" f class:CableReady.Channel
22
26
  cable_ready lib/cable_ready/broadcaster.rb /^ def cable_ready$/;" f class:CableReady.Broadcaster
23
- channel_broadcast lib/cable_ready/channel.rb /^ def channel_broadcast(clear)$/;" f class:CableReady.Channel
24
- channel_broadcast_to lib/cable_ready/channel.rb /^ def channel_broadcast_to(model, clear)$/;" f class:CableReady.Channel
25
- configure lib/cable_ready/channels.rb /^ def self.configure$/;" F class:CableReady.Channels
26
- const.bubbles javascript/cable_ready.js /^ const init = { bubbles: true, cancelable: true, detail: detail }$/;" p
27
- const.cancelable javascript/cable_ready.js /^ const init = { bubbles: true, cancelable: true, detail: detail }$/;" p
28
- const.color javascript/cable_ready.js /^ color: true,$/;" p
29
- const.date javascript/cable_ready.js /^ date: true,$/;" p
30
- const.datetime javascript/cable_ready.js /^ datetime: true,$/;" p
31
- const.datetime-local javascript/cable_ready.js /^ 'datetime-local': true,$/;" p
32
- const.detail javascript/cable_ready.js /^ const init = { bubbles: true, cancelable: true, detail: detail }$/;" p
33
- const.email javascript/cable_ready.js /^ email: true,$/;" p
34
- const.month javascript/cable_ready.js /^ month: true,$/;" p
35
- const.number javascript/cable_ready.js /^ number: true,$/;" p
36
- const.password javascript/cable_ready.js /^ password: true,$/;" p
27
+ config lib/cable_ready.rb /^ def self.config$/;" F class:CableReady
28
+ configure lib/cable_ready.rb /^ def self.configure$/;" F class:CableReady
29
+ const.bubbles javascript/utils.js /^ const init = { bubbles: true, cancelable: true, detail: detail }$/;" p
30
+ const.cancelable javascript/utils.js /^ const init = { bubbles: true, cancelable: true, detail: detail }$/;" p
31
+ const.detail javascript/utils.js /^ const init = { bubbles: true, cancelable: true, detail: detail }$/;" p
37
32
  const.pushState javascript/cable_ready.js /^ pushState: config => {$/;" p
38
- const.range javascript/cable_ready.js /^ range: true,$/;" p
39
- const.search javascript/cable_ready.js /^ search: true,$/;" p
40
- const.select-multiple javascript/cable_ready.js /^ 'select-multiple': true,$/;" p
41
- const.select-one javascript/cable_ready.js /^ 'select-one': true,$/;" p
42
- const.tel javascript/cable_ready.js /^ tel: true,$/;" p
43
- const.text javascript/cable_ready.js /^ text: true,$/;" p
44
- const.textarea javascript/cable_ready.js /^ textarea: true,$/;" p
45
- const.time javascript/cable_ready.js /^ time: true,$/;" p
46
- const.url javascript/cable_ready.js /^ url: true,$/;" p
47
- const.value javascript/cable_ready.js /^ const ignore = { value: true }$/;" p
48
- const.week javascript/cable_ready.js /^ week: true$/;" p
33
+ const.value javascript/callbacks.js /^ const ignore = { value: true }$/;" p
34
+ default_operation_names lib/cable_ready/config.rb /^ def default_operation_names$/;" f class:CableReady.Config
49
35
  dom_id lib/cable_ready/broadcaster.rb /^ def dom_id(record, prefix = nil)$/;" f class:CableReady.Broadcaster
50
- enqueue_operation lib/cable_ready/channel.rb /^ def enqueue_operation(key, options)$/;" f class:CableReady.Channel
51
- import.INPUT javascript/cable_ready.js /^ INPUT: true,$/;" p
52
- import.SELECT javascript/cable_ready.js /^ SELECT: true$/;" p
53
- import.TEXTAREA javascript/cable_ready.js /^ TEXTAREA: true,$/;" p
54
- initialize lib/cable_ready/channel.rb /^ def initialize(identifier, available_operations)$/;" f class:CableReady.Channel
36
+ export.INPUT javascript/enums.js /^ INPUT: true,$/;" p
37
+ export.OPTION javascript/enums.js /^ OPTION: true$/;" p
38
+ export.SELECT javascript/enums.js /^ SELECT: true$/;" p
39
+ export.TEXTAREA javascript/enums.js /^ TEXTAREA: true,$/;" p
40
+ export.color javascript/enums.js /^ color: true,$/;" p
41
+ export.date javascript/enums.js /^ date: true,$/;" p
42
+ export.datetime javascript/enums.js /^ datetime: true,$/;" p
43
+ export.datetime-local javascript/enums.js /^ 'datetime-local': true,$/;" p
44
+ export.email javascript/enums.js /^ email: true,$/;" p
45
+ export.month javascript/enums.js /^ month: true,$/;" p
46
+ export.number javascript/enums.js /^ number: true,$/;" p
47
+ export.password javascript/enums.js /^ password: true,$/;" p
48
+ export.range javascript/enums.js /^ range: true,$/;" p
49
+ export.search javascript/enums.js /^ search: true,$/;" p
50
+ export.select-multiple javascript/enums.js /^ 'select-multiple': true,$/;" p
51
+ export.select-one javascript/enums.js /^ 'select-one': true,$/;" p
52
+ export.tel javascript/enums.js /^ tel: true,$/;" p
53
+ export.text javascript/enums.js /^ text: true,$/;" p
54
+ export.textarea javascript/enums.js /^ textarea: true,$/;" p
55
+ export.time javascript/enums.js /^ time: true,$/;" p
56
+ export.url javascript/enums.js /^ url: true,$/;" p
57
+ export.week javascript/enums.js /^ week: true$/;" p
58
+ initialize lib/cable_ready/channel.rb /^ def initialize(identifier)$/;" f class:CableReady.Channel
55
59
  initialize lib/cable_ready/channels.rb /^ def initialize$/;" f class:CableReady.Channels
56
- mutex lib/cable_ready/channels.rb /^ def mutex$/;" f class:CableReady.Channels
60
+ initialize lib/cable_ready/config.rb /^ def initialize$/;" f class:CableReady.Config
61
+ operation_names lib/cable_ready/config.rb /^ def operation_names$/;" f class:CableReady.Config
57
62
  reset lib/cable_ready/channel.rb /^ def reset$/;" f class:CableReady.Channel
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cable_ready
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-24 00:00:00.000000000 Z
11
+ date: 2021-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thread-local
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: github_changelog_generator
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +145,7 @@ files:
131
145
  - lib/cable_ready/broadcaster.rb
132
146
  - lib/cable_ready/channel.rb
133
147
  - lib/cable_ready/channels.rb
148
+ - lib/cable_ready/config.rb
134
149
  - lib/cable_ready/version.rb
135
150
  - package.json
136
151
  - tags
@@ -154,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
169
  - !ruby/object:Gem::Version
155
170
  version: '0'
156
171
  requirements: []
157
- rubygems_version: 3.1.2
172
+ rubygems_version: 3.1.4
158
173
  signing_key:
159
174
  specification_version: 4
160
175
  summary: Out-of-Band Server Triggered DOM Operations