Sha256: c6716cf74cee8a698de273018897db03141a6d8a4972666b3e231538a4bbd594

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module TableSync::Publishing::Message
  class Raw
    include Tainbox

    attribute :object_class
    attribute :original_attributes
    attribute :routing_key
    attribute :headers

    attribute :event

    def publish
      Rabbit.publish(message_params)

      notify!
    end

    # NOTIFY

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

    def model_naming
      TableSync.publishing_adapter.model_naming(object_class.constantize)
    end

    # MESSAGE PARAMS

    def message_params
      params.merge(data: data)
    end

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

    def params
      TableSync::Publishing::Params::Raw.new(
        object_class: object_class, routing_key: routing_key, headers: headers,
      ).construct
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
table_sync-6.0.2 lib/table_sync/publishing/message/raw.rb
table_sync-6.0 lib/table_sync/publishing/message/raw.rb