Sha256: d1559290186da4888cfdd08e11234fcdf7e19372c58f61c91a66e3189aa40c20

Contents?: true

Size: 1 KB

Versions: 10

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require "tainbox"

require "rabbit/receiving/malformed_message"

module Rabbit::Receiving
  class Message
    include Tainbox

    attribute :group_id
    attribute :project_id
    attribute :message_id
    attribute :event
    attribute :data
    attribute :arguments
    attribute :original_message

    def self.build(message, arguments)
      group_id, project_id = arguments.fetch(:app_id).split(".")

      new(
        group_id: group_id,
        project_id: project_id,
        event: arguments.fetch(:type),
        data: message,
        message_id: arguments.fetch(:message_id, nil),
        arguments: arguments,
      )
    end

    def data=(value)
      self.original_message = value
      super(JSON.parse(value).deep_symbolize_keys)
    rescue JSON::ParserError => error
      mark_as_malformed!("JSON::ParserError: #{error.message}")
    end

    def mark_as_malformed!(errors = "Error not specified")
      MalformedMessage.raise!(self, errors, caller(1))
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rabbit_messaging-1.1.0 lib/rabbit/receiving/message.rb
rabbit_messaging-1.0.0 lib/rabbit/receiving/message.rb
rabbit_messaging-0.15.0 lib/rabbit/receiving/message.rb
rabbit_messaging-0.13.0 lib/rabbit/receiving/message.rb
rabbit_messaging-0.12.1 lib/rabbit/receiving/message.rb
rabbit_messaging-0.12.0 lib/rabbit/receiving/message.rb
rabbit_messaging-0.11.0 lib/rabbit/receiving/message.rb
rabbit_messaging-0.10.0 lib/rabbit/receiving/message.rb
rabbit_messaging-0.9.0 lib/rabbit/receiving/message.rb
rabbit_messaging-0.8.1 lib/rabbit/receiving/message.rb