cable_ready 4.1.0 → 4.3.0.pre1

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: c596a55f701b85307b9c755f6e13ceda7a627fd19d5c51ff3e610edc4bf75716
4
- data.tar.gz: ebe888f5e89ddf8fe268d45974f2c6bccdfa3177897960c6e259ae0dd1271433
3
+ metadata.gz: b124067d935e758b9acabc55a7c2a3a49d23ecde28fd40d28e721a99ee80fbe1
4
+ data.tar.gz: 014b1832272d66cab366100879d94079bcf42ad6c9bf0ea7789206283b531d7f
5
5
  SHA512:
6
- metadata.gz: cee7d5732e034adf6fcf352588a4fa01a9ba2799e93cb3802524d1083626efd38d53e0bed727aaa076a50e100be9887f5257ed6a2bca02f93970f75514191497
7
- data.tar.gz: 31279379786d81358f24cfcb6624c578eede1c2ef2ea1228e8c35e909fee82b5da512923be02c94387ba9584b0660754f311d70f37269da7e7e44f2de34928a8
6
+ metadata.gz: bddca7aec4c1d17ac77fd9e959ef02269f4bccc937d5024b0d9677cded6792a3c64fcf29efe0897ee3dfef3bc9d4c230808747a3158bd8ff9bb4e55eec015f04
7
+ data.tar.gz: 3c285ac7c59835d57377ee64d565eefc32e5a802046f470fad2af7f9cbb6dc7338e3f0269fb5629bb1658cb10a3774937c8082b4c568c7f3a0a161335e0a2fcd
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in cable_ready.gemspec
@@ -1,79 +1,78 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cable_ready (4.1.0)
4
+ cable_ready (4.3.0.pre1)
5
5
  rails (>= 5.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (6.0.2.2)
11
- actionpack (= 6.0.2.2)
10
+ actioncable (6.0.3.1)
11
+ actionpack (= 6.0.3.1)
12
12
  nio4r (~> 2.0)
13
13
  websocket-driver (>= 0.6.1)
14
- actionmailbox (6.0.2.2)
15
- actionpack (= 6.0.2.2)
16
- activejob (= 6.0.2.2)
17
- activerecord (= 6.0.2.2)
18
- activestorage (= 6.0.2.2)
19
- activesupport (= 6.0.2.2)
14
+ actionmailbox (6.0.3.1)
15
+ actionpack (= 6.0.3.1)
16
+ activejob (= 6.0.3.1)
17
+ activerecord (= 6.0.3.1)
18
+ activestorage (= 6.0.3.1)
19
+ activesupport (= 6.0.3.1)
20
20
  mail (>= 2.7.1)
21
- actionmailer (6.0.2.2)
22
- actionpack (= 6.0.2.2)
23
- actionview (= 6.0.2.2)
24
- activejob (= 6.0.2.2)
21
+ actionmailer (6.0.3.1)
22
+ actionpack (= 6.0.3.1)
23
+ actionview (= 6.0.3.1)
24
+ activejob (= 6.0.3.1)
25
25
  mail (~> 2.5, >= 2.5.4)
26
26
  rails-dom-testing (~> 2.0)
27
- actionpack (6.0.2.2)
28
- actionview (= 6.0.2.2)
29
- activesupport (= 6.0.2.2)
27
+ actionpack (6.0.3.1)
28
+ actionview (= 6.0.3.1)
29
+ activesupport (= 6.0.3.1)
30
30
  rack (~> 2.0, >= 2.0.8)
31
31
  rack-test (>= 0.6.3)
32
32
  rails-dom-testing (~> 2.0)
33
33
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
- actiontext (6.0.2.2)
35
- actionpack (= 6.0.2.2)
36
- activerecord (= 6.0.2.2)
37
- activestorage (= 6.0.2.2)
38
- activesupport (= 6.0.2.2)
34
+ actiontext (6.0.3.1)
35
+ actionpack (= 6.0.3.1)
36
+ activerecord (= 6.0.3.1)
37
+ activestorage (= 6.0.3.1)
38
+ activesupport (= 6.0.3.1)
39
39
  nokogiri (>= 1.8.5)
40
- actionview (6.0.2.2)
41
- activesupport (= 6.0.2.2)
40
+ actionview (6.0.3.1)
41
+ activesupport (= 6.0.3.1)
42
42
  builder (~> 3.1)
43
43
  erubi (~> 1.4)
44
44
  rails-dom-testing (~> 2.0)
45
45
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
- activejob (6.0.2.2)
47
- activesupport (= 6.0.2.2)
46
+ activejob (6.0.3.1)
47
+ activesupport (= 6.0.3.1)
48
48
  globalid (>= 0.3.6)
49
- activemodel (6.0.2.2)
50
- activesupport (= 6.0.2.2)
51
- activerecord (6.0.2.2)
52
- activemodel (= 6.0.2.2)
53
- activesupport (= 6.0.2.2)
54
- activestorage (6.0.2.2)
55
- actionpack (= 6.0.2.2)
56
- activejob (= 6.0.2.2)
57
- activerecord (= 6.0.2.2)
49
+ activemodel (6.0.3.1)
50
+ activesupport (= 6.0.3.1)
51
+ activerecord (6.0.3.1)
52
+ activemodel (= 6.0.3.1)
53
+ activesupport (= 6.0.3.1)
54
+ activestorage (6.0.3.1)
55
+ actionpack (= 6.0.3.1)
56
+ activejob (= 6.0.3.1)
57
+ activerecord (= 6.0.3.1)
58
58
  marcel (~> 0.3.1)
59
- activesupport (6.0.2.2)
59
+ activesupport (6.0.3.1)
60
60
  concurrent-ruby (~> 1.0, >= 1.0.2)
61
61
  i18n (>= 0.7, < 2)
62
62
  minitest (~> 5.1)
63
63
  tzinfo (~> 1.1)
64
- zeitwerk (~> 2.2)
65
- ast (2.4.0)
64
+ zeitwerk (~> 2.2, >= 2.2.2)
65
+ ast (2.4.1)
66
66
  builder (3.2.4)
67
- coderay (1.1.2)
67
+ coderay (1.1.3)
68
68
  concurrent-ruby (1.1.6)
69
69
  crass (1.0.6)
70
70
  erubi (1.9.0)
71
71
  globalid (0.4.2)
72
72
  activesupport (>= 4.2.0)
73
- i18n (1.8.2)
73
+ i18n (1.8.3)
74
74
  concurrent-ruby (~> 1.0)
75
- jaro_winkler (1.5.4)
76
- loofah (2.4.0)
75
+ loofah (2.5.0)
77
76
  crass (~> 1.0.2)
78
77
  nokogiri (>= 1.5.9)
79
78
  mail (2.7.1)
@@ -81,15 +80,15 @@ GEM
81
80
  marcel (0.3.3)
82
81
  mimemagic (~> 0.3.2)
83
82
  method_source (0.9.2)
84
- mimemagic (0.3.4)
83
+ mimemagic (0.3.5)
85
84
  mini_mime (1.0.2)
86
85
  mini_portile2 (2.4.0)
87
- minitest (5.14.0)
86
+ minitest (5.14.1)
88
87
  nio4r (2.5.2)
89
88
  nokogiri (1.10.9)
90
89
  mini_portile2 (~> 2.4.0)
91
90
  parallel (1.19.1)
92
- parser (2.7.1.0)
91
+ parser (2.7.1.3)
93
92
  ast (~> 2.4.0)
94
93
  pry (0.12.2)
95
94
  coderay (~> 1.1.0)
@@ -99,66 +98,70 @@ GEM
99
98
  rack (2.2.2)
100
99
  rack-test (1.1.0)
101
100
  rack (>= 1.0, < 3)
102
- rails (6.0.2.2)
103
- actioncable (= 6.0.2.2)
104
- actionmailbox (= 6.0.2.2)
105
- actionmailer (= 6.0.2.2)
106
- actionpack (= 6.0.2.2)
107
- actiontext (= 6.0.2.2)
108
- actionview (= 6.0.2.2)
109
- activejob (= 6.0.2.2)
110
- activemodel (= 6.0.2.2)
111
- activerecord (= 6.0.2.2)
112
- activestorage (= 6.0.2.2)
113
- activesupport (= 6.0.2.2)
101
+ rails (6.0.3.1)
102
+ actioncable (= 6.0.3.1)
103
+ actionmailbox (= 6.0.3.1)
104
+ actionmailer (= 6.0.3.1)
105
+ actionpack (= 6.0.3.1)
106
+ actiontext (= 6.0.3.1)
107
+ actionview (= 6.0.3.1)
108
+ activejob (= 6.0.3.1)
109
+ activemodel (= 6.0.3.1)
110
+ activerecord (= 6.0.3.1)
111
+ activestorage (= 6.0.3.1)
112
+ activesupport (= 6.0.3.1)
114
113
  bundler (>= 1.3.0)
115
- railties (= 6.0.2.2)
114
+ railties (= 6.0.3.1)
116
115
  sprockets-rails (>= 2.0.0)
117
116
  rails-dom-testing (2.0.3)
118
117
  activesupport (>= 4.2.0)
119
118
  nokogiri (>= 1.6)
120
119
  rails-html-sanitizer (1.3.0)
121
120
  loofah (~> 2.3)
122
- railties (6.0.2.2)
123
- actionpack (= 6.0.2.2)
124
- activesupport (= 6.0.2.2)
121
+ railties (6.0.3.1)
122
+ actionpack (= 6.0.3.1)
123
+ activesupport (= 6.0.3.1)
125
124
  method_source
126
125
  rake (>= 0.8.7)
127
126
  thor (>= 0.20.3, < 2.0)
128
127
  rainbow (3.0.0)
129
128
  rake (13.0.1)
129
+ regexp_parser (1.7.1)
130
130
  rexml (3.2.4)
131
- rubocop (0.80.1)
132
- jaro_winkler (~> 1.5.1)
131
+ rubocop (0.85.1)
133
132
  parallel (~> 1.10)
134
133
  parser (>= 2.7.0.1)
135
134
  rainbow (>= 2.2.2, < 4.0)
135
+ regexp_parser (>= 1.7)
136
136
  rexml
137
+ rubocop-ast (>= 0.0.3)
137
138
  ruby-progressbar (~> 1.7)
138
- unicode-display_width (>= 1.4.0, < 1.7)
139
- rubocop-performance (1.5.2)
139
+ unicode-display_width (>= 1.4.0, < 2.0)
140
+ rubocop-ast (0.0.3)
141
+ parser (>= 2.7.0.1)
142
+ rubocop-performance (1.6.1)
140
143
  rubocop (>= 0.71.0)
141
144
  ruby-progressbar (1.10.1)
142
- sprockets (4.0.0)
145
+ sprockets (4.0.2)
143
146
  concurrent-ruby (~> 1.0)
144
147
  rack (> 1, < 3)
145
148
  sprockets-rails (3.2.1)
146
149
  actionpack (>= 4.0)
147
150
  activesupport (>= 4.0)
148
151
  sprockets (>= 3.0.0)
149
- standard (0.2.3)
150
- rubocop (~> 0.80.1)
151
- rubocop-performance (~> 1.5.2)
152
+ standard (0.4.7)
153
+ rubocop (~> 0.85.0)
154
+ rubocop-performance (~> 1.6.0)
152
155
  standardrb (1.0.0)
153
156
  standard
154
157
  thor (1.0.1)
155
158
  thread_safe (0.3.6)
156
159
  tzinfo (1.2.7)
157
160
  thread_safe (~> 0.1)
158
- unicode-display_width (1.6.1)
159
- websocket-driver (0.7.1)
161
+ unicode-display_width (1.7.0)
162
+ websocket-driver (0.7.2)
160
163
  websocket-extensions (>= 0.1.0)
161
- websocket-extensions (0.1.4)
164
+ websocket-extensions (0.1.5)
162
165
  zeitwerk (2.3.0)
163
166
 
164
167
  PLATFORMS
@@ -172,4 +175,4 @@ DEPENDENCIES
172
175
  standardrb
173
176
 
174
177
  BUNDLED WITH
175
- 1.17.3
178
+ 2.1.4
data/README.md CHANGED
@@ -1,21 +1,69 @@
1
- [![Lines of Code](http://img.shields.io/badge/lines_of_code-267-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
2
- [![Maintainability](https://api.codeclimate.com/v1/badges/83ddf1fee4af7e51a681/maintainability)](https://codeclimate.com/github/hopsoft/cable_ready/maintainability)
3
- ![Prettier-Standard](https://github.com/hopsoft/cable_ready/workflows/Prettier-Standard/badge.svg)
4
- ![StandardRB](https://github.com/hopsoft/cable_ready/workflows/StandardRB/badge.svg)
1
+ <p align="center">
2
+ <img src="assets/cable-ready-logo-with-copy.svg" width="360" />
3
+ <h1 align="center">Welcome to CableReady 👋</h1>
4
+ <p align="center">
5
+ <img src="https://img.shields.io/gem/v/cable_ready.svg?color=red" />
6
+ <img src="https://img.shields.io/npm/v/cable_ready.svg?color=blue" />
7
+ <a href="https://www.npmjs.com/package/cable_ready">
8
+ <img alt="downloads" src="https://img.shields.io/npm/dm/cable_ready.svg?color=blue" target="_blank" />
9
+ </a>
10
+ <a href="https://github.com/hopsoft/cable_ready/blob/master/LICENSE">
11
+ <img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-brightgreen.svg" target="_blank" />
12
+ </a>
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-344-brightgreen.svg?style=flat" />
15
+ </a>
16
+ <a href="https://cableready.stimulusreflex.com" target="_blank">
17
+ <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
18
+ </a>
19
+ <br />
20
+ <a href="#badge">
21
+ <img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
22
+ </a>
23
+ <a href="https://github.com/testdouble/standard" target="_blank">
24
+ <img alt="Ruby Code Style" src="https://img.shields.io/badge/Ruby_Code_Style-standard-brightgreen.svg" />
25
+ </a>
26
+ <a href="https://github.com/sheerun/prettier-standard" target="_blank">
27
+ <img alt="JavaScript Code Style" src="https://img.shields.io/badge/JavaScript_Code_Style-prettier_standard-ff69b4.svg" />
28
+ </a>
29
+ <br />
30
+ <a href="https://codeclimate.com/github/hopsoft/cable_ready/maintainability" target="_blank">
31
+ <img alt="Maintainability" src="https://api.codeclimate.com/v1/badges/83ddf1fee4af7e51a681/maintainability" />
32
+ </a>
33
+ <a target="_blank" rel="noopener noreferrer" href="https://github.com/hopsoft/cable_ready/workflows/Prettier-Standard/badge.svg">
34
+ <img src="https://github.com/hopsoft/cable_ready/workflows/Prettier-Standard/badge.svg" alt="Prettier-Standard" style="max-width:100%;">
35
+ </a>
36
+ <a target="_blank" rel="noopener noreferrer" href="https://github.com/hopsoft/cable_ready/workflows/StandardRB/badge.svg">
37
+ <img src="https://github.com/hopsoft/cable_ready/workflows/StandardRB/badge.svg" alt="StandardRB" style="max-width:100%;">
38
+ </a>
39
+ </p>
40
+ </p>
41
+ <br />
5
42
 
6
- # CableReady
7
-
8
- CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby. It establishes a standard for interacting with the client via ActionCable web sockets. No need for custom JavaScript.
43
+ CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby. It establishes a standard for interacting with the client via ActionCable web sockets. No need for custom JavaScript.
9
44
 
10
45
  Please read the official [ActionCable docs](http://guides.rubyonrails.org/action_cable_overview.html)
11
46
  to learn more about ActionCable before proceeding.
12
47
 
13
- ## Docs
48
+ ## 📚 Docs
14
49
 
15
50
  - [Official Documentation](https://cableready.stimulusreflex.com)
16
51
  - [Documentation Source Code](https://github.com/hopsoft/cable_ready/tree/master/docs)
17
52
 
18
- ## Contributing
53
+ ## 💙 Community
54
+
55
+ - [Discord](https://discord.gg/XveN625) - chat root
56
+
57
+ ## 🚀 Install
58
+
59
+ ```sh
60
+ bundle add cable_ready && yarn add cable_ready
61
+ ```
62
+
63
+ Checkout the [documentation](https://cableready.stimulusreflex.com) to continue!
64
+
65
+
66
+ ## 🙏 Contributing
19
67
 
20
68
  ### Code of Conduct
21
69
 
@@ -28,7 +76,7 @@ and [prettier-standard](https://github.com/sheerun/prettier-standard) to minimiz
28
76
 
29
77
  Please run `./bin/standardize` prior submitting pull requests.
30
78
 
31
- ### Releasing
79
+ ### 📦 Releasing
32
80
 
33
81
  1. Bump version number at `lib/cable_ready/version.rb`
34
82
  1. Run `rake build`
@@ -36,6 +84,6 @@ Please run `./bin/standardize` prior submitting pull requests.
36
84
  1. Change directories `cd ./javascript`
37
85
  1. Run `yarn publish` - NOTE: this will throw a fatal error because the tag already exists but the package will still publish
38
86
 
39
- ## License
87
+ ## 📝 License
40
88
 
41
89
  CableReady is released under the [MIT License](LICENSE.txt).
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
3
5
  task default: [:test]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/engine"
2
4
  require "active_support/all"
3
5
  require "cable_ready/version"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "channels"
2
4
 
3
5
  module CableReady
@@ -5,7 +7,11 @@ module CableReady
5
7
  extend ::ActiveSupport::Concern
6
8
 
7
9
  def cable_ready
8
- @cable_ready_channels ||= CableReady::Channels.new
10
+ CableReady::Channels.instance
11
+ end
12
+
13
+ def dom_id(record, prefix = nil)
14
+ "##{ActionView::RecordIdentifier.dom_id(record, prefix)}"
9
15
  end
10
16
  end
11
17
  end
@@ -1,209 +1,40 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CableReady
2
4
  class Channel
3
- attr_reader :name, :operations
4
-
5
- # Example Operations Payload:
6
- #
7
- # {
8
- # # Cookies .....................................................................................................
9
- #
10
- # set_cookie: [
11
- # {cookie: "example=value; path=/; expires=Sat, 07 Mar 2020 16:19:19 GMT"},
12
- # ...
13
- # ]
14
- #
15
- # # DOM Events ..................................................................................................
16
- #
17
- # dispatch_event: [{
18
- # name: "string",
19
- # detail: "object",
20
- # selector: "string",
21
- # }, ...],
22
- #
23
- # # Element Mutations ...........................................................................................
24
- #
25
- # morph: [{
26
- # selector: "string",
27
- # html: "string"
28
- # children_only: true|false,
29
- # permanent_attribute_name: "string",
30
- # focus_selector: "string",
31
- # }, ...],
32
- #
33
- # inner_html: [{
34
- # selector: "string",
35
- # focus_selector: "string",
36
- # html: "string"
37
- # }, ...],
38
- #
39
- # outer_html: [{
40
- # selector: "string",
41
- # focus_selector: "string",
42
- # html: "string"
43
- # }, ...],
44
- #
45
- # text_content: [{
46
- # selector: "string",
47
- # text: "string"
48
- # }, ...]
49
- #
50
- # insert_adjacent_html: [{
51
- # selector: "string",
52
- # focus_selector: "string",
53
- # position: "string",
54
- # html: "string"
55
- # }, ...],
56
- #
57
- # insert_adjacent_text: [{
58
- # selector: "string",
59
- # position: "string",
60
- # text: "string"
61
- # }, ...],
62
- #
63
- # remove: [{
64
- # selector: "string",
65
- # focus_selector: "string,
66
- # }, ...],
67
- #
68
- # set_value: [{
69
- # selector: "string",
70
- # value: "string"
71
- # }, ...],
72
- #
73
- # # Attribute Mutations .........................................................................................
74
- #
75
- # set_attribute: [{
76
- # selector: "string",
77
- # name: "string",
78
- # value: "string"
79
- # }, ...],
80
- #
81
- # remove_attribute: [{
82
- # selector: "string",
83
- # name: "string"
84
- # }, ...],
85
- #
86
- # # CSS Class Mutations .........................................................................................
87
- #
88
- # add_css_class: [{
89
- # selector: "string",
90
- # name: "string"
91
- # }, ...],
92
- #
93
- # remove_css_class: [{
94
- # selector: "string",
95
- # name: "string"
96
- # }, ...],
97
- #
98
- # # Dataset Mutations ...........................................................................................
99
- #
100
- # set_dataset_property: [{
101
- # selector: "string",
102
- # name: "string",
103
- # value: "string"
104
- # }, ...],
105
- # }
106
- def initialize(name)
107
- @name = name
108
- @operations = stub
109
- end
5
+ attr_reader :identifier, :operations, :available_operations
110
6
 
111
- def clear
112
- @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
113
14
  end
114
15
 
115
- def broadcast
16
+ def broadcast(clear)
116
17
  operations.select! { |_, list| list.present? }
117
18
  operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
118
- ActionCable.server.broadcast name, "cableReady" => true, "operations" => operations
119
- clear
120
- end
121
-
122
- def set_cookie(value)
123
- add_operation(:set_cookie, {cookie: value})
124
- end
125
-
126
- def dispatch_event(options = {})
127
- add_operation(:dispatch_event, options)
128
- end
129
-
130
- def morph(options = {})
131
- add_operation(:morph, options)
132
- end
133
-
134
- def inner_html(options = {})
135
- add_operation(:inner_html, options)
136
- end
137
-
138
- def outer_html(options = {})
139
- add_operation(:outer_html, options)
140
- end
141
-
142
- def text_content(options = {})
143
- add_operation(:text_content, options)
144
- end
145
-
146
- def insert_adjacent_html(options = {})
147
- add_operation(:insert_adjacent_html, options)
19
+ ActionCable.server.broadcast identifier, "cableReady" => true, "operations" => operations
20
+ reset if clear
148
21
  end
149
22
 
150
- def insert_adjacent_text(options = {})
151
- add_operation(:insert_adjacent_text, options)
152
- end
153
-
154
- def remove(options = {})
155
- add_operation(:remove, options)
156
- end
157
-
158
- def set_value(options = {})
159
- add_operation(:set_value, options)
160
- end
161
-
162
- def set_attribute(options = {})
163
- add_operation(:set_attribute, options)
164
- end
165
-
166
- def remove_attribute(options = {})
167
- add_operation(:remove_attribute, options)
168
- end
169
-
170
- def add_css_class(options = {})
171
- add_operation(:add_css_class, options)
172
- end
173
-
174
- def remove_css_class(options = {})
175
- add_operation(:remove_css_class, options)
176
- end
177
-
178
- def set_dataset_property(options = {})
179
- 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
180
28
  end
181
29
 
182
30
  private
183
31
 
184
32
  def add_operation(key, options)
185
- operations[key] ||= []
186
33
  operations[key] << options
187
34
  end
188
35
 
189
- def stub
190
- {
191
- add_css_class: [],
192
- dispatch_event: [],
193
- inner_html: [],
194
- insert_adjacent_html: [],
195
- insert_adjacent_text: [],
196
- morph: [],
197
- outer_html: [],
198
- remove: [],
199
- remove_attribute: [],
200
- remove_css_class: [],
201
- set_attribute: [],
202
- set_cookie: [],
203
- set_dataset_property: [],
204
- set_value: [],
205
- text_content: []
206
- }
36
+ def reset
37
+ @operations = Hash.new { |hash, operation| hash[operation] = [] }
207
38
  end
208
39
  end
209
40
  end
@@ -1,22 +1,69 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "channel"
2
4
 
3
5
  module CableReady
4
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
+
5
14
  def initialize
6
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
+ text_content
36
+ ].each do |operation|
37
+ add_operation operation
38
+ end
7
39
  end
8
40
 
9
- def [](channel_name)
10
- @channels[channel_name] ||= CableReady::Channel.new(channel_name)
41
+ def add_operation(operation, &implementation)
42
+ @operations[operation] = implementation || ->(options = {}) { add_operation(operation, options) }
11
43
  end
12
44
 
13
- def clear
14
- @channels = {}
45
+ def [](identifier)
46
+ @channels[identifier] ||= CableReady::Channel.new(identifier, operations)
47
+ end
48
+
49
+ def broadcast(*identifiers, clear: true)
50
+ @channels.values
51
+ .reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
52
+ .select { |channel| channel.identifier.is_a?(String) }
53
+ .tap do |channels|
54
+ channels.each { |channel| @channels[channel.identifier].broadcast(clear) }
55
+ channels.each { |channel| @channels.except!(channel.identifier) if clear }
56
+ end
15
57
  end
16
58
 
17
- def broadcast
18
- @channels.values.map(&:broadcast)
19
- clear
59
+ def broadcast_to(model, *identifiers, clear: true)
60
+ @channels.values
61
+ .reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
62
+ .reject { |channel| channel.identifier.is_a?(String) }
63
+ .tap do |channels|
64
+ channels.each { |channel| @channels[channel.identifier].broadcast_to(model, clear) }
65
+ channels.each { |channel| @channels.except!(channel.identifier) if clear }
66
+ end
20
67
  end
21
68
  end
22
69
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CableReady
2
- VERSION = "4.1.0"
4
+ VERSION = "4.3.0.pre1"
3
5
  end
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.1.0
4
+ version: 4.3.0.pre1
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-04-05 00:00:00.000000000 Z
11
+ date: 2020-06-15 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: '0'
125
+ version: 1.3.1
126
126
  requirements: []
127
127
  rubygems_version: 3.0.3
128
128
  signing_key: