table_sync 2.0.0 → 4.1.0
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/.gitignore +0 -1
- data/.rubocop.yml +26 -1
- data/.travis.yml +6 -6
- data/CHANGELOG.md +74 -0
- data/Gemfile.lock +262 -0
- data/LICENSE.md +1 -1
- data/README.md +4 -1
- data/docs/message_protocol.md +24 -0
- data/docs/notifications.md +45 -0
- data/docs/publishing.md +147 -0
- data/docs/receiving.md +341 -0
- data/lib/table_sync.rb +23 -33
- data/lib/table_sync/errors.rb +60 -22
- data/lib/table_sync/instrument.rb +2 -2
- data/lib/table_sync/publishing.rb +11 -0
- data/lib/table_sync/{base_publisher.rb → publishing/base_publisher.rb} +1 -1
- data/lib/table_sync/{batch_publisher.rb → publishing/batch_publisher.rb} +12 -13
- data/lib/table_sync/{orm_adapter → publishing/orm_adapter}/active_record.rb +4 -8
- data/lib/table_sync/{orm_adapter → publishing/orm_adapter}/sequel.rb +3 -7
- data/lib/table_sync/{publisher.rb → publishing/publisher.rb} +4 -4
- data/lib/table_sync/receiving.rb +14 -0
- data/lib/table_sync/receiving/config.rb +218 -0
- data/lib/table_sync/receiving/config_decorator.rb +27 -0
- data/lib/table_sync/receiving/dsl.rb +28 -0
- data/lib/table_sync/receiving/handler.rb +132 -0
- data/lib/table_sync/{model → receiving/model}/active_record.rb +44 -37
- data/lib/table_sync/receiving/model/sequel.rb +83 -0
- data/lib/table_sync/utils.rb +9 -0
- data/lib/table_sync/utils/interface_checker.rb +103 -0
- data/lib/table_sync/utils/proc_array.rb +17 -0
- data/lib/table_sync/utils/proc_keywords_resolver.rb +46 -0
- data/lib/table_sync/version.rb +1 -1
- data/table_sync.gemspec +5 -4
- metadata +51 -33
- data/docs/synopsis.md +0 -318
- data/lib/table_sync/config.rb +0 -105
- data/lib/table_sync/config/callback_registry.rb +0 -53
- data/lib/table_sync/config_decorator.rb +0 -38
- data/lib/table_sync/dsl.rb +0 -25
- data/lib/table_sync/event_actions.rb +0 -96
- data/lib/table_sync/event_actions/data_wrapper.rb +0 -7
- data/lib/table_sync/event_actions/data_wrapper/base.rb +0 -23
- data/lib/table_sync/event_actions/data_wrapper/destroy.rb +0 -19
- data/lib/table_sync/event_actions/data_wrapper/update.rb +0 -21
- data/lib/table_sync/model/sequel.rb +0 -88
- data/lib/table_sync/receiving_handler.rb +0 -76
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class TableSync::ReceivingHandler < Rabbit::EventHandler
|
4
|
-
extend TableSync::DSL
|
5
|
-
|
6
|
-
attribute :event
|
7
|
-
attribute :model
|
8
|
-
attribute :version
|
9
|
-
|
10
|
-
def call
|
11
|
-
raise TableSync::UndefinedConfig.new(model) if configs.blank?
|
12
|
-
|
13
|
-
configs.each do |config|
|
14
|
-
next unless config.allow_event?(event)
|
15
|
-
|
16
|
-
data = processed_data(config)
|
17
|
-
next if data.empty?
|
18
|
-
|
19
|
-
case event
|
20
|
-
when :update
|
21
|
-
config.model.transaction do
|
22
|
-
config.update(data)
|
23
|
-
end
|
24
|
-
when :destroy
|
25
|
-
config.destroy(data.values.first)
|
26
|
-
else
|
27
|
-
raise "Unknown event: #{event}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def data=(data)
|
35
|
-
@data = data[:attributes]
|
36
|
-
end
|
37
|
-
|
38
|
-
def event=(name)
|
39
|
-
super(name.to_sym)
|
40
|
-
end
|
41
|
-
|
42
|
-
def model=(name)
|
43
|
-
super(name.to_s)
|
44
|
-
end
|
45
|
-
|
46
|
-
def configs
|
47
|
-
@configs ||= self.class.configs[model]
|
48
|
-
&.map { |c| ::TableSync::ConfigDecorator.new(c, self) }
|
49
|
-
end
|
50
|
-
|
51
|
-
def processed_data(config)
|
52
|
-
parts = config.partitions&.transform_keys { |k| config.model.class.new(k) } ||
|
53
|
-
{ config.model => Array.wrap(data) }
|
54
|
-
|
55
|
-
parts.transform_values! do |data_part|
|
56
|
-
data_part.map do |row|
|
57
|
-
original_row_for_data = row.dup
|
58
|
-
row = row.dup
|
59
|
-
|
60
|
-
config.mapping_overrides.each do |before, after|
|
61
|
-
row[after] = row.delete(before)
|
62
|
-
end
|
63
|
-
|
64
|
-
only = config.only
|
65
|
-
row, missed = row.partition { |key, _| key.in?(only) }.map(&:to_h)
|
66
|
-
|
67
|
-
row.deep_merge!(config.rest_key => missed) if config.rest_key
|
68
|
-
row[config.version_key] = version
|
69
|
-
|
70
|
-
row.merge!(config.additional_data(original_row_for_data))
|
71
|
-
|
72
|
-
row unless config.skip(original_row_for_data)
|
73
|
-
end.compact.presence
|
74
|
-
end.compact
|
75
|
-
end
|
76
|
-
end
|