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.



149
150
151
152
153
# File 'lib/shopcircle/orbit/transport.rb', line 149

def initialize
  @events  = []
  @batches = []
  @mutex   = Mutex.new
end

Instance Attribute Details

#batchesObject (readonly)

Returns the value of attribute batches.



147
148
149
# File 'lib/shopcircle/orbit/transport.rb', line 147

def batches
  @batches
end

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