turbo_power 0.4.0 → 0.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: 169485f07b14d287277676057c5fbc40f0d2a3f99ea935ac68205e19005dca7a
4
- data.tar.gz: ece7bbaabd4b88f0c4eafe98bd1f9e107f593369c121de4e3b153208fea7bff9
3
+ metadata.gz: 678db176d816e2a22ddf77a35a42447fef3f823c956a69e5f107186c632dde36
4
+ data.tar.gz: c91240c7d009cf7ed54195d77de945c6a2cd013745673d47393a8a83305952fa
5
5
  SHA512:
6
- metadata.gz: 0c6f701b207610e647f4c820ce3a2d0b4abd02e3ca41f152d62782f37122a034645a59e9ca0571d621d610730206ae0b231a63b4af10753458f01d313bb4fa04
7
- data.tar.gz: c9fa746cfb4337ac4ee7786dad0caeb67f5e42283d77b8fc05345d2165224a8bc1ed549aec00edf8c450a575aa8d1d4bb48a33e7ef6e74e9fe204e728a4b7ae5
6
+ metadata.gz: e24d81bd1d2ef91938458dc7c2c2e1a109d9ff2d29336010b97e835d7a905f9ddf4163ac7d14887712c62d109751ca0b601cee24c9ae14f0cde376a6f3a75f30
7
+ data.tar.gz: cdf838e14aa5e3f7c9a9b9285ec0c5b58e96464bcf36b8826709b79551437814c0e074bcfa7343b4f7ee954ba8a565a43a932b4d4955744edf9b2cd022f661ae
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- turbo_power (0.4.0)
4
+ turbo_power (0.5.0)
5
5
  turbo-rails (~> 1.3)
6
6
 
7
7
  GEM
@@ -0,0 +1,9 @@
1
+ # The job that powers all the <tt>custom_broadcast_$action_later</tt> broadcasts available in <tt>TurboPower::Broadcasts</tt>.
2
+
3
+ class TurboPower::Streams::ActionBroadcastJob < ActiveJob::Base
4
+ discard_on ActiveJob::DeserializationError
5
+
6
+ def perform(stream, action:, **attributes)
7
+ Turbo::StreamsChannel.custom_broadcast_action_to stream, action: action, **attributes
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TurboPower
4
+ module Broadcastable
5
+ ACTIONS = TurboPower::StreamHelper.instance_methods.sort
6
+
7
+ ACTIONS.each do |action|
8
+ action_name = "broadcast_#{action}"
9
+ action_name_to = "broadcast_#{action}_to"
10
+ action_name_later = "broadcast_#{action}_later"
11
+ action_name_later_to = "broadcast_#{action}_later_to"
12
+
13
+ define_method(action_name) do |**attributes|
14
+ Turbo::StreamsChannel.send(action_name_to, self, action: action, **attributes)
15
+ end
16
+
17
+ define_method(action_name_to) do |*streamables, **attributes|
18
+ Turbo::StreamsChannel.send(action_name_to, *streamables, action: action, **attributes)
19
+ end
20
+
21
+ define_method(action_name_later) do |**attributes|
22
+ Turbo::StreamsChannel.send(action_name_later_to, self, action: action, **attributes)
23
+ end
24
+
25
+ define_method(action_name_later_to) do |*streamables, **attributes|
26
+ Turbo::StreamsChannel.send(action_name_later_to, *streamables, action: action, **attributes)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TurboPower
4
+ module Broadcasts
5
+ ACTIONS = TurboPower::StreamHelper.instance_methods.sort
6
+
7
+ ACTIONS.each do |action|
8
+ define_method("broadcast_#{action}_to") do |*streamables, **attributes|
9
+ custom_broadcast_action_to(*streamables, action: action, **attributes)
10
+ end
11
+
12
+ define_method("broadcast_#{action}_later_to") do |*streamables, **attributes|
13
+ custom_broadcast_action_later_to(*streamables, action: action, **attributes)
14
+ end
15
+ end
16
+
17
+ def custom_broadcast_action_to(*streamables, action:, **attributes)
18
+ broadcast_stream_to(
19
+ *streamables,
20
+ content: turbo_stream_action_tag(action, **attributes)
21
+ )
22
+ end
23
+
24
+ def custom_broadcast_action_later_to(*streamables, action:, **attributes)
25
+ TurboPower::Streams::ActionBroadcastJob.perform_later(
26
+ stream_name_from(streamables),
27
+ action: action,
28
+ **attributes
29
+ )
30
+ end
31
+ end
32
+ end
@@ -4,8 +4,16 @@ require "rails/engine"
4
4
 
5
5
  module TurboPower
6
6
  class Engine < Rails::Engine
7
- initializer "turbo_power.helpers", after: :initialize do
7
+ initializer "turbo_power.stream_helpers", after: :initialize do
8
8
  Turbo::Streams::TagBuilder.include(TurboPower::StreamHelper)
9
9
  end
10
+
11
+ initializer "turbo_power.broadcasts", after: :initialize do
12
+ Turbo::Streams::Broadcasts.include(TurboPower::Broadcasts)
13
+ end
14
+
15
+ initializer "turbo_power.broadcastable", after: :initialize do
16
+ Turbo::Broadcastable.include(TurboPower::Broadcastable)
17
+ end
10
18
  end
11
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TurboPower
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/turbo_power.rb CHANGED
@@ -6,6 +6,8 @@ require_relative "turbo_power/version"
6
6
  require_relative "turbo_power/engine"
7
7
  require_relative "turbo_power/attribute_transformations"
8
8
  require_relative "turbo_power/stream_helper"
9
+ require_relative "turbo_power/broadcasts"
10
+ require_relative "turbo_power/broadcastable"
9
11
 
10
12
  module TurboPower
11
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_power
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-15 00:00:00.000000000 Z
11
+ date: 2023-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: turbo-rails
@@ -31,17 +31,19 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - CHANGELOG.md
35
34
  - CODE_OF_CONDUCT.md
36
35
  - Gemfile
37
36
  - Gemfile.lock
38
37
  - LICENSE.txt
39
38
  - README.md
40
39
  - Rakefile
40
+ - app/jobs/turbo_power/streams/action_broadcast_job.rb
41
41
  - bin/console
42
42
  - bin/setup
43
43
  - lib/turbo_power.rb
44
44
  - lib/turbo_power/attribute_transformations.rb
45
+ - lib/turbo_power/broadcastable.rb
46
+ - lib/turbo_power/broadcasts.rb
45
47
  - lib/turbo_power/engine.rb
46
48
  - lib/turbo_power/stream_helper.rb
47
49
  - lib/turbo_power/version.rb
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2022-08-24
4
-
5
- - Initial release