Class: TableSync::Publishing::Message::Raw

Inherits:
Object
  • Object
show all
Defined in:
lib/table_sync/publishing/message/raw.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Raw

Returns a new instance of Raw.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/table_sync/publishing/message/raw.rb', line 15

def initialize(params = {})
  self.model_name          = params[:model_name]
  self.table_name          = params[:table_name]
  self.schema_name         = params[:schema_name]
  self.original_attributes = params[:original_attributes]
  self.routing_key         = params[:routing_key]
  self.headers             = params[:headers]
  self.custom_version      = params[:custom_version]
  self.event               = params[:event]
  self.compress            = params.dig(:headers, :compress) || false
end

Instance Attribute Details

#compressObject

Returns the value of attribute compress.



5
6
7
# File 'lib/table_sync/publishing/message/raw.rb', line 5

def compress
  @compress
end

#custom_versionObject

Returns the value of attribute custom_version.



5
6
7
# File 'lib/table_sync/publishing/message/raw.rb', line 5

def custom_version
  @custom_version
end

#eventObject

Returns the value of attribute event.



5
6
7
# File 'lib/table_sync/publishing/message/raw.rb', line 5

def event
  @event
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/table_sync/publishing/message/raw.rb', line 5

def headers
  @headers
end

#model_nameObject

Returns the value of attribute model_name.



5
6
7
# File 'lib/table_sync/publishing/message/raw.rb', line 5

def model_name
  @model_name
end

#original_attributesObject

Returns the value of attribute original_attributes.



5
6
7
# File 'lib/table_sync/publishing/message/raw.rb', line 5

def original_attributes
  @original_attributes
end

#routing_keyObject

Returns the value of attribute routing_key.



5
6
7
# File 'lib/table_sync/publishing/message/raw.rb', line 5

def routing_key
  @routing_key
end

#schema_nameObject

Returns the value of attribute schema_name.



5
6
7
# File 'lib/table_sync/publishing/message/raw.rb', line 5

def schema_name
  @schema_name
end

#table_nameObject

Returns the value of attribute table_name.



5
6
7
# File 'lib/table_sync/publishing/message/raw.rb', line 5

def table_name
  @table_name
end

Instance Method Details

#dataObject



52
53
54
55
56
57
58
59
# File 'lib/table_sync/publishing/message/raw.rb', line 52

def data
  TableSync::Publishing::Data::Raw.new(
    model_name:,
    attributes_for_sync: original_attributes,
    event:,
    custom_version:,
  ).construct
end

#message_paramsObject

MESSAGE PARAMS



48
49
50
# File 'lib/table_sync/publishing/message/raw.rb', line 48

def message_params
  params.merge(data:)
end

#notify!Object

NOTIFY



35
36
37
38
39
40
41
42
43
44
# File 'lib/table_sync/publishing/message/raw.rb', line 35

def notify!
  TableSync::Instrument.notify(
    table: table_name,
    schema: schema_name,
    event:,
    compress: compress,
    count: original_attributes.count,
    direction: :publish,
  )
end

#paramsObject



61
62
63
64
65
# File 'lib/table_sync/publishing/message/raw.rb', line 61

def params
  TableSync::Publishing::Params::Raw.new(
    { model_name:, headers:, routing_key: }.compact,
  ).construct
end

#publishObject



27
28
29
30
31
# File 'lib/table_sync/publishing/message/raw.rb', line 27

def publish
  Rabbit.publish(**message_params)

  notify!
end