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.



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

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]
end

Instance Attribute Details

#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



49
50
51
52
53
54
55
56
# File 'lib/table_sync/publishing/message/raw.rb', line 49

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

#message_paramsObject

MESSAGE PARAMS



45
46
47
# File 'lib/table_sync/publishing/message/raw.rb', line 45

def message_params
  params.merge(data:)
end

#notify!Object

NOTIFY



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

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

#paramsObject



58
59
60
61
62
# File 'lib/table_sync/publishing/message/raw.rb', line 58

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

#publishObject



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

def publish
  Rabbit.publish(**message_params)

  notify!
end