Sha256: f1db5793ebb6e2a79b3274831a55a6ec229ccd6c3f436dac6fbe067bb07d5953

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true
module Basquiat
  module Adapters
    # The simplest Message class. It's encouraged to tailor it to your adapter needs (hence BaseMessage).
    class BaseMessage < SimpleDelegator
      attr_reader :action

      # @param message [Object] It's assumed that message is some kind of JSON
      # @note All unknown messages will be delegated to the resulting Hash
      def initialize(message)
        @message = Basquiat::Json.decode(message)
        super(@message)
        @action = :ack
      end

      # @!group Action Setters
      # Sets the action to be taken after processing to be an ack.
      # Here just in case as the default is to acknowledge the message.
      def ack
        @action = :ack
      end

      # Sets the action to be taken after processing to be an nack / reject
      def nack
        @action = :nack
      end

      # Sets the action to be taken after processing to be a requeue
      def requeue
        @action = :requeue
      end
      # @!endgroup
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
basquiat-1.3.2 lib/basquiat/adapters/base_message.rb
basquiat-1.3.1 lib/basquiat/adapters/base_message.rb
basquiat-1.3.0 lib/basquiat/adapters/base_message.rb