Class: Fare::TestMode::MessageList
- Inherits:
-
Object
- Object
- Fare::TestMode::MessageList
- Defined in:
- lib/fare/test_mode.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #get(subject, action) ⇒ Object
- #given_event(event_or_queue_name, event = nil) ⇒ Object
-
#initialize ⇒ MessageList
constructor
A new instance of MessageList.
- #list ⇒ Object
- #queue_adapter ⇒ Object
- #register_publish(message) ⇒ Object
- #run(queue_name = app_name, timeout: 2) ⇒ Object
- #size ⇒ Object
- #topic_adapter ⇒ Object
Constructor Details
#initialize ⇒ MessageList
Returns a new instance of MessageList.
6 7 8 |
# File 'lib/fare/test_mode.rb', line 6 def initialize = {} end |
Instance Method Details
#clear ⇒ Object
23 24 25 |
# File 'lib/fare/test_mode.rb', line 23 def clear .clear end |
#get(subject, action) ⇒ Object
27 28 29 |
# File 'lib/fare/test_mode.rb', line 27 def get(subject, action) [[subject.to_s, action.to_s]] end |
#given_event(event_or_queue_name, event = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fare/test_mode.rb', line 41 def given_event(event_or_queue_name, event = nil) if event queue_name = event_or_queue_name else event = event_or_queue_name queue_name = app_name end serialized_event = Event.new(event).serialize queue = fetch_queue(queue_name.to_s) queue.publish(serialized_event) end |
#list ⇒ Object
35 36 37 38 39 |
# File 'lib/fare/test_mode.rb', line 35 def list .values.map { |event| "* #{event.subject}##{event.action}" }.join("\n") end |
#queue_adapter ⇒ Object
10 11 12 |
# File 'lib/fare/test_mode.rb', line 10 def queue_adapter @queue_adapter ||= QueueAdapter.new end |
#register_publish(message) ⇒ Object
18 19 20 21 |
# File 'lib/fare/test_mode.rb', line 18 def register_publish() event = Event.deserialize() [[event.subject.to_s, event.action.to_s]] ||= event end |
#run(queue_name = app_name, timeout: 2) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fare/test_mode.rb', line 53 def run(queue_name = app_name, timeout: 2) subscriber = Subscriber.new(Fare.configuration, name: queue_name) Timeout.timeout(timeout) do while = (subscriber) begin subscriber.consume() rescue # manually delete in case of errors, so not to retry it .delete raise end end end end |
#size ⇒ Object
31 32 33 |
# File 'lib/fare/test_mode.rb', line 31 def size .size end |
#topic_adapter ⇒ Object
14 15 16 |
# File 'lib/fare/test_mode.rb', line 14 def topic_adapter @topic_adapter ||= TopicAdapter.new(self) end |