Sha256: e05325e8dbb32d27a31ccecc43b85641990645bb86715a904aa19d17dd48255e

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module FakeSQS
  module Actions
    class ReceiveMessage

      def initialize(options = {})
        @server    = options.fetch(:server)
        @queues    = options.fetch(:queues)
        @responder = options.fetch(:responder)
      end

      def call(queue_name, params)
        queue = @queues.get(queue_name)
        filtered_attribute_names = []
        params.select{|k,v | k =~ /AttributeName\.\d+/}.each do |key, value|
          filtered_attribute_names << value
        end
        messages = queue.receive_message(params.merge(queues: @queues))
        @responder.call :ReceiveMessage do |xml|
          messages.each do |receipt, message|
            xml.Message do
              xml.MessageId message.id
              xml.ReceiptHandle receipt
              xml.MD5OfBody message.md5
              xml.Body message.body
              message.attributes.each do |name, value|
                if filtered_attribute_names.include?("All") || filtered_attribute_names.include?(name)
                  xml.Attribute do
                    xml.Name name
                    xml.Value value
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fake_sqs-0.4.3 lib/fake_sqs/actions/receive_message.rb
fake_sqs-0.4.2 lib/fake_sqs/actions/receive_message.rb