Class: ShopCircle::Orbit::TestTransport
- Inherits:
-
Object
- Object
- ShopCircle::Orbit::TestTransport
- Defined in:
- lib/shopcircle/orbit/transport.rb
Overview
Stub transport for testing - records events in memory
Instance Attribute Summary collapse
-
#batches ⇒ Object
readonly
Returns the value of attribute batches.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
- #clear! ⇒ Object
-
#initialize ⇒ TestTransport
constructor
A new instance of TestTransport.
- #send_batch(events) ⇒ Object
- #send_single(event) ⇒ Object
Constructor Details
#initialize ⇒ TestTransport
Returns a new instance of TestTransport.
186 187 188 189 190 |
# File 'lib/shopcircle/orbit/transport.rb', line 186 def initialize @events = [] @batches = [] @mutex = Mutex.new end |
Instance Attribute Details
#batches ⇒ Object (readonly)
Returns the value of attribute batches.
184 185 186 |
# File 'lib/shopcircle/orbit/transport.rb', line 184 def batches @batches end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
184 185 186 |
# File 'lib/shopcircle/orbit/transport.rb', line 184 def events @events end |
Instance Method Details
#clear! ⇒ Object
204 205 206 207 208 209 |
# File 'lib/shopcircle/orbit/transport.rb', line 204 def clear! @mutex.synchronize do @events.clear @batches.clear end end |
#send_batch(events) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/shopcircle/orbit/transport.rb', line 196 def send_batch(events) payloads = events.map(&:to_payload) @mutex.synchronize do @batches << payloads @events.concat(payloads) end end |
#send_single(event) ⇒ Object
192 193 194 |
# File 'lib/shopcircle/orbit/transport.rb', line 192 def send_single(event) @mutex.synchronize { @events << event.to_payload } end |