Module: ModelTransporter::BatchModelUpdates

Extended by:
BatchModelUpdates
Included in:
BatchModelUpdates
Defined in:
lib/model_transporter/batch_model_updates.rb

Constant Summary collapse

MODEL_UPDATES_EVENT =
'server_event/MODEL_UPDATES'
REQUEST_STORE_NAMESPACE =
'MODEL_TRANSPORTER'

Instance Method Summary collapse

Instance Method Details

#batch_model_updatesObject



23
24
25
26
27
28
29
30
31
# File 'lib/model_transporter/batch_model_updates.rb', line 23

def batch_model_updates
  RequestStore.store["#{REQUEST_STORE_NAMESPACE}.model_updates"] = Hash.new { |h, k| h[k] = [] }

  yield
ensure
  consolidate_model_updates.each do |channel, message|
    push_update(channel, message)
  end
end

#enqueue_model_updates(channel, message) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/model_transporter/batch_model_updates.rb', line 7

def enqueue_model_updates(channel, message)
  if updates_being_batched?
    current_model_updates[channel] << message
  else
    cooked_message = base_model_update_message.merge(payload: message)
    push_update(channel, cooked_message)
  end
end

#with_transporter_actor(actor) ⇒ Object



16
17
18
19
20
21
# File 'lib/model_transporter/batch_model_updates.rb', line 16

def with_transporter_actor(actor)
  RequestStore.store["#{REQUEST_STORE_NAMESPACE}.transporter_actor"] = actor
  yield
ensure
  RequestStore.store.delete("#{REQUEST_STORE_NAMESPACE}.transporter_actor")
end