Class: FakeSQS::API

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_sqs/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fake_sqs/api.rb', line 22

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/fake_sqs/api.rb', line 20

def options
  @options
end

#queuesObject (readonly)

Returns the value of attribute queues.



20
21
22
# File 'lib/fake_sqs/api.rb', line 20

def queues
  @queues
end

Instance Method Details

#call(action, *args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/fake_sqs/api.rb', line 34

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

#expireObject



51
52
53
# File 'lib/fake_sqs/api.rb', line 51

def expire
  queues.expire
end

#resetObject

Fake actions



47
48
49
# File 'lib/fake_sqs/api.rb', line 47

def reset
  queues.reset
end

#stopObject



55
56
57
# File 'lib/fake_sqs/api.rb', line 55

def stop
  @run_timer = false
end