cable_ready 4.2.0 → 4.3.0.pre0
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 +4 -4
- data/Gemfile.lock +15 -10
- data/lib/cable_ready/broadcaster.rb +5 -1
- data/lib/cable_ready/channel.rb +18 -213
- data/lib/cable_ready/channels.rb +51 -7
- data/lib/cable_ready/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97d1c34cd35126aebacd48f7aca392baa47991f89677ea1f22fc7c6c7cdc3ff8
|
4
|
+
data.tar.gz: ea3aac6324f788063497cd88100200e5168cebb5b6e74b9a5ce8b5c32c65df6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d625cb0b81b01dfd7a4dfa6bf452fdb5b56ea1e231bb56441801818ff1d31b78a58b032c0af0d33be8e447660b419c1693b291fea6eb5aa10b094611fbc19b89
|
7
|
+
data.tar.gz: f39ea747112802ee20f11557820e65894596e940adb146fca7bbc6d21aeb92380393144188826f943111ca28f4a06ace7fa6999d258b38af7df2ff1cc5ff0f4e
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cable_ready (4.
|
4
|
+
cable_ready (4.3.0.pre0)
|
5
5
|
rails (>= 5.2)
|
6
6
|
|
7
7
|
GEM
|
@@ -62,7 +62,7 @@ GEM
|
|
62
62
|
minitest (~> 5.1)
|
63
63
|
tzinfo (~> 1.1)
|
64
64
|
zeitwerk (~> 2.2, >= 2.2.2)
|
65
|
-
ast (2.4.
|
65
|
+
ast (2.4.1)
|
66
66
|
builder (3.2.4)
|
67
67
|
coderay (1.1.3)
|
68
68
|
concurrent-ruby (1.1.6)
|
@@ -70,7 +70,7 @@ GEM
|
|
70
70
|
erubi (1.9.0)
|
71
71
|
globalid (0.4.2)
|
72
72
|
activesupport (>= 4.2.0)
|
73
|
-
i18n (1.8.
|
73
|
+
i18n (1.8.3)
|
74
74
|
concurrent-ruby (~> 1.0)
|
75
75
|
loofah (2.5.0)
|
76
76
|
crass (~> 1.0.2)
|
@@ -126,27 +126,32 @@ GEM
|
|
126
126
|
thor (>= 0.20.3, < 2.0)
|
127
127
|
rainbow (3.0.0)
|
128
128
|
rake (13.0.1)
|
129
|
+
regexp_parser (1.7.1)
|
129
130
|
rexml (3.2.4)
|
130
|
-
rubocop (0.
|
131
|
+
rubocop (0.85.1)
|
131
132
|
parallel (~> 1.10)
|
132
133
|
parser (>= 2.7.0.1)
|
133
134
|
rainbow (>= 2.2.2, < 4.0)
|
135
|
+
regexp_parser (>= 1.7)
|
134
136
|
rexml
|
137
|
+
rubocop-ast (>= 0.0.3)
|
135
138
|
ruby-progressbar (~> 1.7)
|
136
139
|
unicode-display_width (>= 1.4.0, < 2.0)
|
137
|
-
rubocop-
|
140
|
+
rubocop-ast (0.0.3)
|
141
|
+
parser (>= 2.7.0.1)
|
142
|
+
rubocop-performance (1.6.1)
|
138
143
|
rubocop (>= 0.71.0)
|
139
144
|
ruby-progressbar (1.10.1)
|
140
|
-
sprockets (4.0.
|
145
|
+
sprockets (4.0.2)
|
141
146
|
concurrent-ruby (~> 1.0)
|
142
147
|
rack (> 1, < 3)
|
143
148
|
sprockets-rails (3.2.1)
|
144
149
|
actionpack (>= 4.0)
|
145
150
|
activesupport (>= 4.0)
|
146
151
|
sprockets (>= 3.0.0)
|
147
|
-
standard (0.4.
|
148
|
-
rubocop (~> 0.
|
149
|
-
rubocop-performance (~> 1.
|
152
|
+
standard (0.4.7)
|
153
|
+
rubocop (~> 0.85.0)
|
154
|
+
rubocop-performance (~> 1.6.0)
|
150
155
|
standardrb (1.0.0)
|
151
156
|
standard
|
152
157
|
thor (1.0.1)
|
@@ -156,7 +161,7 @@ GEM
|
|
156
161
|
unicode-display_width (1.7.0)
|
157
162
|
websocket-driver (0.7.2)
|
158
163
|
websocket-extensions (>= 0.1.0)
|
159
|
-
websocket-extensions (0.1.
|
164
|
+
websocket-extensions (0.1.5)
|
160
165
|
zeitwerk (2.3.0)
|
161
166
|
|
162
167
|
PLATFORMS
|
@@ -7,7 +7,11 @@ module CableReady
|
|
7
7
|
extend ::ActiveSupport::Concern
|
8
8
|
|
9
9
|
def cable_ready
|
10
|
-
|
10
|
+
CableReady::Channels.instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def dom_id(record, prefix = nil)
|
14
|
+
"##{ActionView::RecordIdentifier.dom_id(record, prefix)}"
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
data/lib/cable_ready/channel.rb
CHANGED
@@ -2,234 +2,39 @@
|
|
2
2
|
|
3
3
|
module CableReady
|
4
4
|
class Channel
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :identifier, :operations, :available_operations
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# ...
|
15
|
-
# ]
|
16
|
-
#
|
17
|
-
# # DOM Events ..................................................................................................
|
18
|
-
#
|
19
|
-
# dispatch_event: [{
|
20
|
-
# name: "string",
|
21
|
-
# detail: "object",
|
22
|
-
# selector: "string",
|
23
|
-
# }, ...],
|
24
|
-
#
|
25
|
-
# # Element Mutations ...........................................................................................
|
26
|
-
#
|
27
|
-
# morph: [{
|
28
|
-
# selector: "string",
|
29
|
-
# html: "string"
|
30
|
-
# children_only: true|false,
|
31
|
-
# permanent_attribute_name: "string",
|
32
|
-
# focus_selector: "string",
|
33
|
-
# }, ...],
|
34
|
-
#
|
35
|
-
# inner_html: [{
|
36
|
-
# selector: "string",
|
37
|
-
# focus_selector: "string",
|
38
|
-
# html: "string"
|
39
|
-
# }, ...],
|
40
|
-
#
|
41
|
-
# outer_html: [{
|
42
|
-
# selector: "string",
|
43
|
-
# focus_selector: "string",
|
44
|
-
# html: "string"
|
45
|
-
# }, ...],
|
46
|
-
#
|
47
|
-
# text_content: [{
|
48
|
-
# selector: "string",
|
49
|
-
# text: "string"
|
50
|
-
# }, ...]
|
51
|
-
#
|
52
|
-
# insert_adjacent_html: [{
|
53
|
-
# selector: "string",
|
54
|
-
# focus_selector: "string",
|
55
|
-
# position: "string",
|
56
|
-
# html: "string"
|
57
|
-
# }, ...],
|
58
|
-
#
|
59
|
-
# insert_adjacent_text: [{
|
60
|
-
# selector: "string",
|
61
|
-
# position: "string",
|
62
|
-
# text: "string"
|
63
|
-
# }, ...],
|
64
|
-
#
|
65
|
-
# remove: [{
|
66
|
-
# selector: "string",
|
67
|
-
# focus_selector: "string,
|
68
|
-
# }, ...],
|
69
|
-
#
|
70
|
-
# set_property: [{
|
71
|
-
# name: "string",
|
72
|
-
# selector: "string",
|
73
|
-
# value: "string"
|
74
|
-
# }, ...],
|
75
|
-
#
|
76
|
-
# set_value: [{
|
77
|
-
# selector: "string",
|
78
|
-
# value: "string"
|
79
|
-
# }, ...],
|
80
|
-
#
|
81
|
-
# # Attribute Mutations .........................................................................................
|
82
|
-
#
|
83
|
-
# set_attribute: [{
|
84
|
-
# selector: "string",
|
85
|
-
# name: "string",
|
86
|
-
# value: "string"
|
87
|
-
# }, ...],
|
88
|
-
#
|
89
|
-
# remove_attribute: [{
|
90
|
-
# selector: "string",
|
91
|
-
# name: "string"
|
92
|
-
# }, ...],
|
93
|
-
#
|
94
|
-
# # CSS Class Mutations .........................................................................................
|
95
|
-
#
|
96
|
-
# add_css_class: [{
|
97
|
-
# selector: "string",
|
98
|
-
# name: "string"
|
99
|
-
# }, ...],
|
100
|
-
#
|
101
|
-
# remove_css_class: [{
|
102
|
-
# selector: "string",
|
103
|
-
# name: "string"
|
104
|
-
# }, ...],
|
105
|
-
#
|
106
|
-
# # Style Mutations ...........................................................................................
|
107
|
-
#
|
108
|
-
# set_style: [{
|
109
|
-
# selector: "string",
|
110
|
-
# name: "string",
|
111
|
-
# value: "string"
|
112
|
-
# }, ...],
|
113
|
-
#
|
114
|
-
# # Dataset Mutations ...........................................................................................
|
115
|
-
#
|
116
|
-
# set_dataset_property: [{
|
117
|
-
# selector: "string",
|
118
|
-
# name: "string",
|
119
|
-
# value: "string"
|
120
|
-
# }, ...],
|
121
|
-
# }
|
122
|
-
def initialize(name)
|
123
|
-
@name = name
|
124
|
-
@operations = stub
|
7
|
+
def initialize(identifier, available_operations)
|
8
|
+
@identifier = identifier
|
9
|
+
@available_operations = available_operations
|
10
|
+
reset
|
11
|
+
available_operations.each do |available_operation, implementation|
|
12
|
+
define_singleton_method available_operation, &implementation
|
13
|
+
end
|
125
14
|
end
|
126
15
|
|
127
|
-
def clear
|
128
|
-
@operations = stub
|
129
|
-
end
|
130
|
-
|
131
|
-
def broadcast
|
16
|
+
def broadcast(clear)
|
132
17
|
operations.select! { |_, list| list.present? }
|
133
18
|
operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
|
134
|
-
ActionCable.server.broadcast
|
135
|
-
clear
|
136
|
-
end
|
137
|
-
|
138
|
-
def set_cookie(value)
|
139
|
-
add_operation(:set_cookie, {cookie: value})
|
140
|
-
end
|
141
|
-
|
142
|
-
def dispatch_event(options = {})
|
143
|
-
add_operation(:dispatch_event, options)
|
144
|
-
end
|
145
|
-
|
146
|
-
def morph(options = {})
|
147
|
-
add_operation(:morph, options)
|
148
|
-
end
|
149
|
-
|
150
|
-
def inner_html(options = {})
|
151
|
-
add_operation(:inner_html, options)
|
152
|
-
end
|
153
|
-
|
154
|
-
def outer_html(options = {})
|
155
|
-
add_operation(:outer_html, options)
|
156
|
-
end
|
157
|
-
|
158
|
-
def text_content(options = {})
|
159
|
-
add_operation(:text_content, options)
|
160
|
-
end
|
161
|
-
|
162
|
-
def insert_adjacent_html(options = {})
|
163
|
-
add_operation(:insert_adjacent_html, options)
|
164
|
-
end
|
165
|
-
|
166
|
-
def insert_adjacent_text(options = {})
|
167
|
-
add_operation(:insert_adjacent_text, options)
|
19
|
+
ActionCable.server.broadcast identifier, "cableReady" => true, "operations" => operations
|
20
|
+
reset if clear
|
168
21
|
end
|
169
22
|
|
170
|
-
def
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
add_operation(:set_property, options)
|
176
|
-
end
|
177
|
-
|
178
|
-
def set_value(options = {})
|
179
|
-
add_operation(:set_value, options)
|
180
|
-
end
|
181
|
-
|
182
|
-
def set_attribute(options = {})
|
183
|
-
add_operation(:set_attribute, options)
|
184
|
-
end
|
185
|
-
|
186
|
-
def remove_attribute(options = {})
|
187
|
-
add_operation(:remove_attribute, options)
|
188
|
-
end
|
189
|
-
|
190
|
-
def add_css_class(options = {})
|
191
|
-
add_operation(:add_css_class, options)
|
192
|
-
end
|
193
|
-
|
194
|
-
def remove_css_class(options = {})
|
195
|
-
add_operation(:remove_css_class, options)
|
196
|
-
end
|
197
|
-
|
198
|
-
def set_style(options = {})
|
199
|
-
add_operation(:set_style, options)
|
200
|
-
end
|
201
|
-
|
202
|
-
def set_dataset_property(options = {})
|
203
|
-
add_operation(:set_dataset_property, options)
|
23
|
+
def 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
|
27
|
+
reset if clear
|
204
28
|
end
|
205
29
|
|
206
30
|
private
|
207
31
|
|
208
32
|
def add_operation(key, options)
|
209
|
-
operations[key] ||= []
|
210
33
|
operations[key] << options
|
211
34
|
end
|
212
35
|
|
213
|
-
def
|
214
|
-
{
|
215
|
-
add_css_class: [],
|
216
|
-
dispatch_event: [],
|
217
|
-
inner_html: [],
|
218
|
-
insert_adjacent_html: [],
|
219
|
-
insert_adjacent_text: [],
|
220
|
-
morph: [],
|
221
|
-
outer_html: [],
|
222
|
-
remove: [],
|
223
|
-
remove_attribute: [],
|
224
|
-
remove_css_class: [],
|
225
|
-
set_attribute: [],
|
226
|
-
set_cookie: [],
|
227
|
-
set_dataset_property: [],
|
228
|
-
set_style: [],
|
229
|
-
set_property: [],
|
230
|
-
set_value: [],
|
231
|
-
text_content: []
|
232
|
-
}
|
36
|
+
def reset
|
37
|
+
@operations = Hash.new { |hash, operation| hash[operation] = [] }
|
233
38
|
end
|
234
39
|
end
|
235
40
|
end
|
data/lib/cable_ready/channels.rb
CHANGED
@@ -4,21 +4,65 @@ require_relative "channel"
|
|
4
4
|
|
5
5
|
module CableReady
|
6
6
|
class Channels
|
7
|
+
include Singleton
|
8
|
+
attr_accessor :operations
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield CableReady::Channels.instance if block_given?
|
12
|
+
end
|
13
|
+
|
7
14
|
def initialize
|
8
15
|
@channels = {}
|
16
|
+
@operations = {}
|
17
|
+
%i[
|
18
|
+
add_css_class
|
19
|
+
dispatch_event
|
20
|
+
inner_html
|
21
|
+
insert_adjacent_html
|
22
|
+
insert_adjacent_text
|
23
|
+
morph
|
24
|
+
outer_html
|
25
|
+
remove
|
26
|
+
remove_attribute
|
27
|
+
remove_css_class
|
28
|
+
set_attribute
|
29
|
+
set_cookie
|
30
|
+
set_dataset_property
|
31
|
+
set_property
|
32
|
+
set_style
|
33
|
+
set_styles
|
34
|
+
set_value
|
35
|
+
].each do |operation|
|
36
|
+
add_operation operation
|
37
|
+
end
|
9
38
|
end
|
10
39
|
|
11
|
-
def
|
12
|
-
@
|
40
|
+
def add_operation(operation, &implementation)
|
41
|
+
@operations[operation] = implementation || ->(options = {}) { add_operation(operation, options) }
|
13
42
|
end
|
14
43
|
|
15
|
-
def
|
16
|
-
@channels
|
44
|
+
def [](identifier)
|
45
|
+
@channels[identifier] ||= CableReady::Channel.new(identifier, operations)
|
46
|
+
end
|
47
|
+
|
48
|
+
def broadcast(*identifiers, clear: true)
|
49
|
+
@channels.values
|
50
|
+
.reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
|
51
|
+
.select { |channel| channel.identifier.is_a?(String) }
|
52
|
+
.tap do |channels|
|
53
|
+
channels.each { |channel| @channels[channel.identifier].broadcast(clear) }
|
54
|
+
channels.each { |channel| @channels.except!(channel.identifier) if clear }
|
55
|
+
end
|
17
56
|
end
|
18
57
|
|
19
|
-
def
|
20
|
-
@channels.values
|
21
|
-
|
58
|
+
def broadcast_to(model, *identifiers, clear: true)
|
59
|
+
@channels.values
|
60
|
+
.reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
|
61
|
+
.reject { |channel| channel.identifier.is_a?(String) }
|
62
|
+
.tap do |channels|
|
63
|
+
channels.each { |channel| @channels[channel.identifier].broadcast_to(model, clear) }
|
64
|
+
channels.each { |channel| @channels.except!(channel.identifier) if clear }
|
65
|
+
end
|
22
66
|
end
|
23
67
|
end
|
24
68
|
end
|
data/lib/cable_ready/version.rb
CHANGED
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
|
+
version: 4.3.0.pre0
|
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-06-
|
11
|
+
date: 2020-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -120,9 +120,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - "
|
123
|
+
- - ">"
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 1.3.1
|
126
126
|
requirements: []
|
127
127
|
rubygems_version: 3.0.3
|
128
128
|
signing_key:
|