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.
149 150 151 152 153 |
# File 'lib/shopcircle/orbit/transport.rb', line 149 def initialize @events = [] @batches = [] @mutex = Mutex.new end |
Instance Attribute Details
#batches ⇒ Object (readonly)
Returns the value of attribute batches.
147 148 149 |
# File 'lib/shopcircle/orbit/transport.rb', line 147 def batches @batches end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
147 148 149 |
# File 'lib/shopcircle/orbit/transport.rb', line 147 def events @events end |
Instance Method Details
#clear! ⇒ Object
167 168 169 170 171 172 |
# File 'lib/shopcircle/orbit/transport.rb', line 167 def clear! @mutex.synchronize do @events.clear @batches.clear end end |
#send_batch(events) ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/shopcircle/orbit/transport.rb', line 159 def send_batch(events) payloads = events.map(&:to_payload) @mutex.synchronize do @batches << payloads @events.concat(payloads) end end |
#send_single(event) ⇒ Object
155 156 157 |
# File 'lib/shopcircle/orbit/transport.rb', line 155 def send_single(event) @mutex.synchronize { @events << event.to_payload } end |