Class: ShopCircle::Orbit::TestTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/shopcircle/orbit/transport.rb

Overview

Stub transport for testing - records events in memory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestTransport

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

#batchesObject (readonly)

Returns the value of attribute batches.



184
185
186
# File 'lib/shopcircle/orbit/transport.rb', line 184

def batches
  @batches
end

#eventsObject (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