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 +4 -4
- data/README.md +5 -3
- data/lib/dexiecable/active_record_ext.rb +16 -13
- data/lib/dexiecable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ad9a4f94d6491f661821d79ac6a8fa3c36527927f8fb0916eee26c87294ebdf
|
|
4
|
+
data.tar.gz: d50524564c23e50423e186edd1ed5883d9a4e1575fc687d9d80036fcac6201ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
134
|
-
|
|
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),
|
|
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
|
|
18
|
-
# must return a channel (
|
|
19
|
-
#
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
+
Array(resolve_channel(via)).each do |channel|
|
|
59
|
+
next unless channel
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
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
|
data/lib/dexiecable/version.rb
CHANGED