Sha256: da28a983720ac7d1b5db4c40c2d38d22c70cc934f0e4f4123e3a793bab75c548

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require 'fake_sqs/actions/change_message_visibility'
require 'fake_sqs/actions/create_queue'
require 'fake_sqs/actions/delete_queue'
require 'fake_sqs/actions/list_queues'
require 'fake_sqs/actions/get_queue_url'
require 'fake_sqs/actions/send_message'
require 'fake_sqs/actions/receive_message'
require 'fake_sqs/actions/delete_message'
require 'fake_sqs/actions/delete_message_batch'
require 'fake_sqs/actions/send_message_batch'
require 'fake_sqs/actions/get_queue_attributes'
require 'fake_sqs/actions/set_queue_attributes'

module FakeSQS

  InvalidAction = Class.new(ArgumentError)

  class API

    attr_reader :queues, :options

    def initialize(options = {})
      @queues    = options.fetch(:queues)
      @options   = options
      @run_timer = true
      @timer     = Thread.new do
        while @run_timer
          queues.timeout_messages!
          sleep(5)
        end
      end
    end

    def call(action, *args)
      if FakeSQS::Actions.const_defined?(action)
        action = FakeSQS::Actions.const_get(action).new(options)
        queues.transaction do
          action.call(*args)
        end
      else
        fail InvalidAction, "Unknown (or not yet implemented) action: #{action}"
      end
    end

    # Fake actions

    def reset
      queues.reset
    end

    def expire
      queues.expire
    end

    def stop
      @run_timer = false
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fake_sqs-0.2.0 lib/fake_sqs/api.rb
fake_sqs-0.1.0 lib/fake_sqs/api.rb