table_sync 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/docs/synopsis.md +22 -2
- data/lib/table_sync/batch_publisher.rb +8 -9
- data/lib/table_sync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00c09777052902dc012d825d79668aeebe130d2fd4fcfefb77d3d33bbb1dc511
|
4
|
+
data.tar.gz: ec571dc138e800ada7e0f4fd112516caed6f110bbaabcc64cdfb3aac36b81989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18ed6af8a53a850c59ec1fbffa2ae9e85d197644528cbde81f8502fce2a88affbedfed071890430f0abbcfa718c11567c0171eef2f90886d6d01ff4db21c10fa
|
7
|
+
data.tar.gz: ea36659bef94f7cf27109c8882f5f6e5cacc90201032024ce8c41ce0bac3449dfb3172d0ba675b0f5b8d075e82bd9b0807571f49340e2d6e6a62330028c7695f
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [2.1.0] - 2020-04-09
|
5
|
+
### Added
|
6
|
+
- **TableSync::BatchPublisher**: custom headers;
|
7
|
+
- **TableSync::BatchPublisher**: custom events;
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
- Slight changes to specs
|
11
|
+
|
4
12
|
## [2.0.0] - 2020-04-06
|
5
13
|
### Changed
|
6
14
|
- Sequel publishing hooks: checking for `:destroy` events inside `:if`/`:unless` predicates
|
data/docs/synopsis.md
CHANGED
@@ -103,11 +103,21 @@ And `TableSync.routing_metadata_callable` is not called at all: header value is
|
|
103
103
|
- `routing_key`, which is a custom key used (if given) to override one from `TableSync.routing_key_callable`, `nil` by default
|
104
104
|
- `push_original_attributes` (default value is `false`), if this option is set to `true`,
|
105
105
|
original_attributes_array will be pushed to Rabbit instead of fetching records from database and sending their mapped attributes.
|
106
|
+
- `headers`, which is an option for custom headers (can be used for headers exchanges routes), `nil` by default
|
107
|
+
- `event`, which is an option for event specification (`:destroy` or `:update`), `:update` by default
|
106
108
|
|
107
109
|
Example:
|
108
110
|
|
109
111
|
```ruby
|
110
|
-
TableSync::BatchPublisher.new(
|
112
|
+
TableSync::BatchPublisher.new(
|
113
|
+
"SomeClass",
|
114
|
+
[{ id: 1 }, { id: 2 }],
|
115
|
+
confirm: false,
|
116
|
+
routing_key: "custom_routing_key",
|
117
|
+
push_original_attributes: true,
|
118
|
+
headers: { key: :value },
|
119
|
+
event: :destroy,
|
120
|
+
)
|
111
121
|
```
|
112
122
|
|
113
123
|
# Manual publishing with batches (Russian)
|
@@ -125,11 +135,21 @@ TableSync::BatchPublisher.new("SomeClass", [{ id: 1 }, { id: 2 }], confirm: fals
|
|
125
135
|
- `confirm`, флаг для RabbitMQ, по умолчанию - `true`
|
126
136
|
- `routing_key`, ключ, который (если указан) замещает ключ, получаемый из `TableSync.routing_key_callable`, по умолчанию - `nil`
|
127
137
|
- `push_original_attributes` (значение по умолчанию `false`), если для этой опции задано значение true, в Rabbit будут отправлены original_attributes_array, вместо получения значений записей из базы непосредственно перед отправкой.
|
138
|
+
- `headers`, опция для задания headers (можно использовать для задания маршрутов в headers exchange'ах), `nil` по умолчанию
|
139
|
+
- `event`, опция для указания типа события (`:destroy` или `:update`), `:update` по умолчанию
|
128
140
|
|
129
141
|
Example:
|
130
142
|
|
131
143
|
```ruby
|
132
|
-
TableSync::BatchPublisher.new(
|
144
|
+
TableSync::BatchPublisher.new(
|
145
|
+
"SomeClass",
|
146
|
+
[{ id: 1 }, { id: 2 }],
|
147
|
+
confirm: false,
|
148
|
+
routing_key: "custom_routing_key",
|
149
|
+
push_original_attributes: true,
|
150
|
+
headers: { key: :value },
|
151
|
+
event: :destroy,
|
152
|
+
)
|
133
153
|
```
|
134
154
|
|
135
155
|
# Receiving changes
|
@@ -2,13 +2,16 @@
|
|
2
2
|
|
3
3
|
class TableSync::BatchPublisher < TableSync::BasePublisher
|
4
4
|
def initialize(object_class, original_attributes_array, **options)
|
5
|
-
@object_class = object_class.constantize
|
6
5
|
@original_attributes_array = original_attributes_array.map do |hash|
|
7
6
|
filter_safe_for_serialization(hash.deep_symbolize_keys)
|
8
7
|
end
|
9
|
-
|
10
|
-
@
|
8
|
+
|
9
|
+
@object_class = object_class.constantize
|
10
|
+
@confirm = options[:confirm] || true
|
11
|
+
@routing_key = options[:routing_key] || resolve_routing_key
|
11
12
|
@push_original_attributes = options[:push_original_attributes] || false
|
13
|
+
@headers = options[:headers]
|
14
|
+
@event = options[:event] || :update
|
12
15
|
end
|
13
16
|
|
14
17
|
def publish
|
@@ -27,7 +30,7 @@ class TableSync::BatchPublisher < TableSync::BasePublisher
|
|
27
30
|
|
28
31
|
private
|
29
32
|
|
30
|
-
attr_reader :original_attributes_array, :routing_key
|
33
|
+
attr_reader :original_attributes_array, :routing_key, :headers, :event
|
31
34
|
|
32
35
|
def push_original_attributes?
|
33
36
|
@push_original_attributes
|
@@ -64,7 +67,7 @@ class TableSync::BatchPublisher < TableSync::BasePublisher
|
|
64
67
|
def params
|
65
68
|
{
|
66
69
|
**super,
|
67
|
-
headers:
|
70
|
+
headers: headers,
|
68
71
|
}
|
69
72
|
end
|
70
73
|
|
@@ -80,10 +83,6 @@ class TableSync::BatchPublisher < TableSync::BasePublisher
|
|
80
83
|
}
|
81
84
|
end
|
82
85
|
|
83
|
-
def event
|
84
|
-
:update
|
85
|
-
end
|
86
|
-
|
87
86
|
def attributes_for_sync
|
88
87
|
return original_attributes_array if push_original_attributes?
|
89
88
|
|
data/lib/table_sync/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Umbrellio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: memery
|