Class: Goliath::TestHelper::SSEHelper
- Inherits:
-
Object
- Object
- Goliath::TestHelper::SSEHelper
- Defined in:
- lib/goliath/test_helper_sse.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(url) ⇒ SSEHelper
constructor
A new instance of SSEHelper.
- #listen ⇒ Object
- #listen_to(name) ⇒ Object
- #receive ⇒ Object
- #receive_on(name) ⇒ Object
- #with_async_http ⇒ Object
Constructor Details
#initialize(url) ⇒ SSEHelper
Returns a new instance of SSEHelper.
7 8 9 10 11 |
# File 'lib/goliath/test_helper_sse.rb', line 7 def initialize(url) @message_queue = EM::Queue.new @named_queues = {} @connection = EM::EventSource.new(url) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/goliath/test_helper_sse.rb', line 6 def connection @connection end |
Instance Method Details
#listen ⇒ Object
13 14 15 16 17 |
# File 'lib/goliath/test_helper_sse.rb', line 13 def listen @connection. do || @message_queue.push() end end |
#listen_to(name) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/goliath/test_helper_sse.rb', line 19 def listen_to(name) queue = (@named_queues[name] ||= []) @connection.on(name) do || queue.push() end end |
#receive ⇒ Object
26 27 28 |
# File 'lib/goliath/test_helper_sse.rb', line 26 def receive pop_queue(@message_queue) end |
#receive_on(name) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/goliath/test_helper_sse.rb', line 30 def receive_on(name) queue = @named_queues.fetch(name) do raise ArgumentError, "You have to call listen_to('#{name}') first" end pop_queue(queue) end |
#with_async_http ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/goliath/test_helper_sse.rb', line 38 def with_async_http klass = EM::HttpConnection if klass.instance_methods.include?(:aget) begin klass.send(:class_eval) do alias :sget :get alias :get :aget end yield if block_given? ensure klass.send(:class_eval) do alias :get :sget remove_method :sget end end else yield if block_given? end end |