Sha256: 138c9455e5913b702944d7714f4ff2c06fa80f9c0e7d68cdd3df7750003c9707

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

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

    attribute :model_name
    attribute :table_name
    attribute :schema_name
    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: table_name,
        schema: schema_name,
        event: event,
        count: original_attributes.count,
        direction: :publish,
      )
    end

    # MESSAGE PARAMS

    def message_params
      params.merge(data: data)
    end

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
table_sync-6.5.1 lib/table_sync/publishing/message/raw.rb
table_sync-6.5.0 lib/table_sync/publishing/message/raw.rb
table_sync-6.4.2 lib/table_sync/publishing/message/raw.rb
table_sync-6.4.1 lib/table_sync/publishing/message/raw.rb
table_sync-6.4.0 lib/table_sync/publishing/message/raw.rb
table_sync-6.3.0 lib/table_sync/publishing/message/raw.rb
table_sync-6.1.0 lib/table_sync/publishing/message/raw.rb