class OpenUI::Rails::Stream::Accumulator
Client-side (Ruby) sequence accumulator mirroring what the browser must do: apply ordered deltas, ignore duplicates, and treat a missing sequence as “fetch the authoritative snapshot” rather than executing a malformed partial. Used by server tests and by hosts that consume their own stream.
Attributes
Public Class Methods
Source
# File lib/openui/rails/stream/accumulator.rb, line 14 def initialize(message_id:) @message_id = message_id @source = +"" @next_sequence = 0 @completed = false @error = nil @needs_snapshot = false end
Public Instance Methods
Source
# File lib/openui/rails/stream/accumulator.rb, line 29 def apply(envelope) return :ignored unless envelope.message_id == message_id unless envelope.snapshot? return :duplicate if envelope.sequence < @next_sequence return :ignored if @completed || error? return :gap if @needs_snapshot if envelope.sequence > @next_sequence @needs_snapshot = true return :gap end end case envelope.type when Envelope::DELTA then apply_delta(envelope) when Envelope::SNAPSHOT then apply_snapshot(envelope) when Envelope::COMPLETED then apply_completed(envelope) when Envelope::ERROR then apply_error(envelope) else :ignored end end
Apply one envelope for this message.
@param envelope [Envelope]
@return [Symbol] one of :applied, :duplicate, :gap, :snapshot,
:completed, :error, :ignored. After :gap, only a snapshot applies.
Source
# File lib/openui/rails/stream/accumulator.rb, line 51 def completed? = @completed
Source
# File lib/openui/rails/stream/accumulator.rb, line 53 def needs_snapshot? = @needs_snapshot
Source
# File lib/openui/rails/stream/accumulator.rb, line 50 def next_sequence = @next_sequence