dexiecable 0.1.2 → 0.1.3

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: dc22d844e30147740e885b5959d13a6f42c47ff9551490f4b8e61701b1481676
4
- data.tar.gz: 5d82c9e2f8453aa038db8b7eb5997134e56431da93a62ecb30190e5eebef63a2
3
+ metadata.gz: 4ad9a4f94d6491f661821d79ac6a8fa3c36527927f8fb0916eee26c87294ebdf
4
+ data.tar.gz: d50524564c23e50423e186edd1ed5883d9a4e1575fc687d9d80036fcac6201ec
5
5
  SHA512:
6
- metadata.gz: 18eb395292b406e4f0cd690eafcf9dc68ac5b39cac89c459e0685c95e7cfe42bd551348c3146df1dcd596405b6198c15ecba41ba9e48abceee8068cd65f020ac
7
- data.tar.gz: b2135050a6a827ac7e0c596ed64ad8d6d568ad6f18d278a6b8c819c464564a110396fc76c597985d1d4cc4e1be2ddd0b4aab1aa9b58fb4a5b1663509a9762a7d
6
+ metadata.gz: 017f3a4b81fe35bbc8fc17ad5b22cd8a0400ce3e4a14aa20942a517f8030c1cbf08c67b1e590b090726f20dd67c5b71869319fa568b07e01ebdc320867a829be
7
+ data.tar.gz: 9ccd364a0a6a6b1960bcd5c9af17475b5e972dbfc2ee839bb86d9cb3bf69fedfeb3ccbc20b471e9d6dfe42f9e458f59f32cdd158d1f2c5f6f40f1b022e41f9d8
data/README.md CHANGED
@@ -129,9 +129,11 @@ Add to any ActiveRecord model:
129
129
 
130
130
  ```ruby
131
131
  class Message < ApplicationRecord
132
+ # Sync to a single user.
132
133
  syncs_to_dexie via: -> { UserChannel[sender] }
133
- syncs_to_dexie via: -> { UserChannel[receiver] }
134
- syncs_to_dexie via: RoomChannel['public']
134
+
135
+ # Sync to all participants of a conversation.
136
+ syncs_to_dexie via: -> { conversation.participants.map { |u| UserChannel[u] } }
135
137
  end
136
138
  ```
137
139
 
@@ -145,7 +147,7 @@ end
145
147
 
146
148
  | Option | Default | Description |
147
149
  |---|---|---|
148
- | `via:` | *(required)* | Proc (evaluated in record context), or channel instance |
150
+ | `via:` | *(required)* | Proc (evaluated in record context), a channel, or an array of channels |
149
151
  | `table:` | model's `table_name` | Override the Dexie table name. A Proc is evaluated in the record's context. |
150
152
  | `only:` | `[:create, :update, :destroy]` | Limit which events trigger a sync |
151
153
  | `if:` | *(none)* | Symbol (method name) or Proc — only sync when it returns truthy |
@@ -14,9 +14,9 @@ module DexieCable
14
14
  # syncs_to_dexie via: PublicChannel
15
15
  # end
16
16
  #
17
- # @param via [Proc, DexieCable] Proc evaluated in record context,
18
- # must return a channel (responds to +table+). A channel
19
- # class/instance can also be passed directly. Skipped if nil.
17
+ # @param via [Proc, DexieCable, Array<DexieCable>] Proc evaluated in
18
+ # record context, must return a channel (or array of
19
+ # channels) that responds to +table+. Skipped if nil.
20
20
  # @param table [String, Symbol, Proc] Override the Dexie table name
21
21
  # (defaults to the model's table_name). A Proc is
22
22
  # evaluated in the record's context.
@@ -37,27 +37,30 @@ module DexieCable
37
37
  before_destroy :dexie_sync_before_destroy
38
38
 
39
39
  after_commit on: :destroy, **conditions do
40
- channel = resolve_channel(via)
41
- next unless channel
42
- channel.table(resolve_table(table)).delete(dexie_destroy_id)
40
+ Array(resolve_channel(via)).each do |channel|
41
+ next unless channel
42
+ channel.table(resolve_table(table)).delete(dexie_destroy_id)
43
+ end
43
44
  end
44
45
  end
45
46
 
46
47
  if events.include?(:create)
47
48
  after_commit on: :create, **conditions do
48
- channel = resolve_channel(via)
49
- next unless channel
50
- channel.table(resolve_table(table)).add(as_json_for_dexie)
49
+ Array(resolve_channel(via)).each do |channel|
50
+ next unless channel
51
+ channel.table(resolve_table(table)).add(as_json_for_dexie)
52
+ end
51
53
  end
52
54
  end
53
55
 
54
56
  if events.include?(:update)
55
57
  after_commit on: :update, **conditions do
56
- channel = resolve_channel(via)
57
- next unless channel
58
+ Array(resolve_channel(via)).each do |channel|
59
+ next unless channel
58
60
 
59
- changes = as_json_for_dexie.slice(*saved_changes.keys)
60
- channel.table(resolve_table(table)).update(id, changes)
61
+ changes = as_json_for_dexie.slice(*saved_changes.keys)
62
+ channel.table(resolve_table(table)).update(id, changes)
63
+ end
61
64
  end
62
65
  end
63
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DexieCable
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dexiecable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Buhrmester