Skip to content

Commit d179e5b

Browse files
author
dmitrii.buk
committed
updated rabbit-messaging gem
1 parent 26f244e commit d179e5b

File tree

13 files changed

+204
-78
lines changed

13 files changed

+204
-78
lines changed

Gemfile.lock

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PATH
22
remote: .
33
specs:
4-
table_sync (6.6.3)
4+
table_sync (6.7.0)
55
memery
6-
rabbit_messaging (>= 1.1.0)
6+
rabbit_messaging (>= 1.6.2)
77
rails
88
self_data
99

@@ -148,6 +148,22 @@ GEM
148148
nokogiri (1.18.8)
149149
mini_portile2 (~> 2.8.2)
150150
racc (~> 1.4)
151+
nokogiri (1.18.8-aarch64-linux-gnu)
152+
racc (~> 1.4)
153+
nokogiri (1.18.8-aarch64-linux-musl)
154+
racc (~> 1.4)
155+
nokogiri (1.18.8-arm-linux-gnu)
156+
racc (~> 1.4)
157+
nokogiri (1.18.8-arm-linux-musl)
158+
racc (~> 1.4)
159+
nokogiri (1.18.8-arm64-darwin)
160+
racc (~> 1.4)
161+
nokogiri (1.18.8-x86_64-darwin)
162+
racc (~> 1.4)
163+
nokogiri (1.18.8-x86_64-linux-gnu)
164+
racc (~> 1.4)
165+
nokogiri (1.18.8-x86_64-linux-musl)
166+
racc (~> 1.4)
151167
ostruct (0.6.1)
152168
parallel (1.27.0)
153169
parser (3.3.8.0)
@@ -164,10 +180,9 @@ GEM
164180
psych (5.2.6)
165181
date
166182
stringio
167-
rabbit_messaging (1.5.0)
183+
rabbit_messaging (1.6.2)
168184
bunny (~> 2.0)
169185
kicks
170-
tainbox
171186
racc (1.8.1)
172187
rack (3.1.15)
173188
rack-session (2.1.1)
@@ -294,8 +309,6 @@ GEM
294309
rbtree
295310
set (~> 1.0)
296311
stringio (3.1.7)
297-
tainbox (2.1.2)
298-
activesupport
299312
thor (1.3.2)
300313
timecop (0.9.10)
301314
timeout (0.4.3)
@@ -312,7 +325,15 @@ GEM
312325
zeitwerk (2.6.18)
313326

314327
PLATFORMS
328+
aarch64-linux-gnu
329+
aarch64-linux-musl
330+
arm-linux-gnu
331+
arm-linux-musl
332+
arm64-darwin
315333
ruby
334+
x86_64-darwin
335+
x86_64-linux-gnu
336+
x86_64-linux-musl
316337

317338
DEPENDENCIES
318339
activejob

lib/table_sync/publishing/batch.rb

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# frozen_string_literal: true
22

33
class TableSync::Publishing::Batch
4-
include Tainbox
5-
include TableSync::Utils::RequiredValidator
4+
attr_accessor :object_class,
5+
:original_attributes,
6+
:custom_version,
7+
:routing_key,
8+
:headers,
9+
:event
610

7-
attribute :object_class
8-
attribute :original_attributes
9-
attribute :custom_version
10-
attribute :routing_key
11-
attribute :headers
11+
def initialize(attrs = {})
12+
@object_class = attrs[:object_class]
13+
@original_attributes = attrs[:original_attributes]
14+
@custom_version = attrs[:custom_version]
15+
@routing_key = attrs[:routing_key]
16+
@headers = attrs[:headers]
17+
@event = attrs.fetch(:event, :update)
1218

13-
attribute :event, default: :update
14-
15-
require_attributes :object_class, :original_attributes
19+
validate_required_attributes!
20+
end
1621

1722
def publish_later
1823
job.perform_later(job_attributes)
@@ -30,6 +35,27 @@ def message
3035

3136
private
3237

38+
def validate_required_attributes!
39+
missing = []
40+
missing << :object_class if object_class.nil?
41+
missing << :original_attributes if original_attributes.nil?
42+
43+
unless missing.empty?
44+
raise ArgumentError, "Some of required attributes is not provided: #{missing.inspect}"
45+
end
46+
end
47+
48+
def attributes
49+
{
50+
object_class: object_class,
51+
original_attributes: original_attributes,
52+
custom_version: custom_version,
53+
routing_key: routing_key,
54+
headers: headers,
55+
event: event,
56+
}
57+
end
58+
3359
# JOB
3460

3561
def job

lib/table_sync/publishing/message/base.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
module TableSync::Publishing::Message
44
class Base
5-
include Tainbox
5+
attr_accessor :custom_version,
6+
:object_class,
7+
:original_attributes,
8+
:event
69

710
attr_reader :objects
811

9-
attribute :custom_version
10-
attribute :object_class
11-
attribute :original_attributes
12-
attribute :event
13-
14-
def initialize(params)
15-
super
12+
def initialize(params = {})
13+
@custom_version = params[:custom_version]
14+
@object_class = params[:object_class]
15+
@original_attributes = params[:original_attributes]
16+
@event = params[:event]
1617

1718
@objects = find_or_init_objects
1819

lib/table_sync/publishing/message/batch.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
module TableSync::Publishing::Message
44
class Batch < Base
5-
attribute :headers
6-
attribute :routing_key
5+
attr_accessor :headers, :routing_key
6+
7+
def initialize(params = {})
8+
super
9+
10+
@headers = params[:headers]
11+
@routing_key = params[:routing_key]
12+
end
713

814
def params
915
TableSync::Publishing::Params::Batch.new(
10-
attributes.slice(:object_class, :headers, :routing_key).compact,
16+
{ object_class:, headers:, routing_key: }.compact,
1117
).construct
1218
end
1319
end

lib/table_sync/publishing/message/raw.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22

33
module TableSync::Publishing::Message
44
class Raw
5-
include Tainbox
5+
attr_accessor :model_name,
6+
:table_name,
7+
:schema_name,
8+
:original_attributes,
9+
:routing_key,
10+
:headers,
11+
:custom_version,
12+
:event
613

7-
attribute :model_name
8-
attribute :table_name
9-
attribute :schema_name
10-
attribute :original_attributes
11-
12-
attribute :routing_key
13-
attribute :headers
14-
attribute :custom_version
15-
attribute :event
14+
def initialize(params = {})
15+
self.model_name = params[:model_name]
16+
self.table_name = params[:table_name]
17+
self.schema_name = params[:schema_name]
18+
self.original_attributes = params[:original_attributes]
19+
self.routing_key = params[:routing_key]
20+
self.headers = params[:headers]
21+
self.custom_version = params[:custom_version]
22+
self.event = params[:event]
23+
end
1624

1725
def publish
1826
Rabbit.publish(message_params)
@@ -49,7 +57,7 @@ def data
4957

5058
def params
5159
TableSync::Publishing::Params::Raw.new(
52-
attributes.slice(:model_name, :headers, :routing_key).compact,
60+
{ model_name:, headers:, routing_key: }.compact,
5361
).construct
5462
end
5563
end

lib/table_sync/publishing/params/batch.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22

33
module TableSync::Publishing::Params
44
class Batch < Base
5-
include Tainbox
5+
attr_accessor :object_class
6+
attr_writer :exchange_name, :routing_key, :headers
67

7-
attribute :object_class
8+
def initialize(attrs = {})
9+
self.object_class = attrs[:object_class]
10+
@exchange_name = attrs[:exchange_name]
11+
@routing_key = attrs[:routing_key]
12+
@headers = attrs[:headers]
13+
end
14+
15+
def exchange_name
16+
@exchange_name || TableSync.exchange_name
17+
end
818

9-
attribute :exchange_name, default: -> { TableSync.exchange_name }
10-
attribute :routing_key, default: -> { calculated_routing_key }
11-
attribute :headers, default: -> { calculated_headers }
19+
def routing_key
20+
@routing_key || calculated_routing_key
21+
end
22+
23+
def headers
24+
@headers || calculated_headers
25+
end
1226

1327
private
1428

lib/table_sync/publishing/params/raw.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
module TableSync::Publishing::Params
44
class Raw < Batch
5-
attribute :model_name
5+
attr_accessor :model_name
66

77
alias_method :object_class, :model_name
8+
9+
def initialize(attrs = {})
10+
super
11+
self.model_name = attrs[:model_name]
12+
end
813
end
914
end

lib/table_sync/publishing/raw.rb

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
# frozen_string_literal: true
22

33
class TableSync::Publishing::Raw
4-
include Tainbox
54
include TableSync::Utils::RequiredValidator
65

7-
attribute :model_name
8-
attribute :table_name
9-
attribute :schema_name
10-
attribute :original_attributes
11-
attribute :custom_version
12-
attribute :routing_key
13-
attribute :headers
6+
attr_accessor :model_name,
7+
:table_name,
8+
:schema_name,
9+
:original_attributes,
10+
:custom_version,
11+
:routing_key,
12+
:headers,
13+
:event
1414

15-
attribute :event, default: :update
15+
def initialize(attributes = {})
16+
attributes ||= {}
17+
18+
@model_name = attributes[:model_name]
19+
@table_name = attributes[:table_name]
20+
@schema_name = attributes[:schema_name]
21+
@original_attributes = attributes[:original_attributes]
22+
@custom_version = attributes[:custom_version]
23+
@routing_key = attributes[:routing_key]
24+
@headers = attributes[:headers]
25+
@event = attributes.fetch(:event, :update)
26+
end
1627

1728
require_attributes :model_name, :original_attributes
1829

@@ -23,4 +34,19 @@ def publish_now
2334
def message
2435
TableSync::Publishing::Message::Raw.new(attributes)
2536
end
37+
38+
private
39+
40+
def attributes
41+
{
42+
model_name: model_name,
43+
table_name: table_name,
44+
schema_name: schema_name,
45+
original_attributes: original_attributes,
46+
custom_version: custom_version,
47+
routing_key: routing_key,
48+
headers: headers,
49+
event: event,
50+
}
51+
end
2652
end

lib/table_sync/publishing/single.rb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# frozen_string_literal: true
22

33
class TableSync::Publishing::Single
4-
include Tainbox
54
include Memery
65

7-
attribute :object_class
8-
attribute :original_attributes
9-
attribute :debounce_time
10-
attribute :custom_version
11-
attribute :event, Symbol, default: :update
6+
attr_accessor :object_class,
7+
:original_attributes,
8+
:debounce_time,
9+
:custom_version,
10+
:event
11+
12+
def initialize(attrs = {})
13+
self.object_class = attrs[:object_class]
14+
self.original_attributes = attrs[:original_attributes]
15+
self.debounce_time = attrs[:debounce_time]
16+
self.custom_version = attrs[:custom_version]
17+
self.event = attrs.fetch(:event, :update)
18+
end
1219

1320
# expect job to have perform_at method
1421
# debounce destroyed event
@@ -40,6 +47,16 @@ def publish_now
4047

4148
private
4249

50+
def attributes
51+
{
52+
object_class: object_class,
53+
original_attributes: original_attributes,
54+
debounce_time: debounce_time,
55+
custom_version: custom_version,
56+
event: event,
57+
}
58+
end
59+
4360
# JOB
4461

4562
def job

0 commit comments

Comments
 (0)