Module: YrbLite::ActionCable::Sync::ClassMethods
- Defined in:
- lib/yrb_lite/action_cable/sync.rb
Instance Method Summary collapse
-
#max_frame_bytes(bytes = :__unset__) ⇒ Object
Maximum size, in decoded bytes, of an incoming document/awareness frame.
-
#on_change(&block) ⇒ Object
Record every document change durably before it is applied or distributed.
-
#on_load(&block) ⇒ Object
Load persisted document state.
Instance Method Details
#max_frame_bytes(bytes = :__unset__) ⇒ Object
Maximum size, in decoded bytes, of an incoming document/awareness frame. Oversized frames are dropped before base64 decode and before native parsing, so a client can’t force huge allocations/CPU (a DoS vector). Defaults to DEFAULT_MAX_FRAME_BYTES; set to nil to disable the cap.
87 88 89 90 91 92 93 |
# File 'lib/yrb_lite/action_cable/sync.rb', line 87 def max_frame_bytes(bytes = :__unset__) # Combined reader/writer; the sentinel keeps nil a real value (disables the cap). @max_frame_bytes = bytes unless bytes == :__unset__ return @max_frame_bytes if defined?(@max_frame_bytes) superclass.respond_to?(:max_frame_bytes) ? superclass.max_frame_bytes : DEFAULT_MAX_FRAME_BYTES end |
#on_change(&block) ⇒ Object
Record every document change durably before it is applied or distributed. Called synchronously with (key, update), where update is the exact CRDT delta. If the block raises, the change is rejected: neither acknowledged nor broadcast to other subscribers.
Runs in the channel instance’s context (instance_exec). Fires from within sync_receive.
76 77 78 79 80 81 |
# File 'lib/yrb_lite/action_cable/sync.rb', line 76 def on_change(&block) @on_change = block if block return @on_change if defined?(@on_change) && @on_change superclass.respond_to?(:on_change) ? superclass.on_change : nil end |
#on_load(&block) ⇒ Object
Load persisted document state. Called once per key with (key); return a binary Y.js update (or nil for a fresh document). Runs in the channel instance’s context (instance_exec).
62 63 64 65 66 67 |
# File 'lib/yrb_lite/action_cable/sync.rb', line 62 def on_load(&block) @on_load = block if block return @on_load if defined?(@on_load) && @on_load superclass.respond_to?(:on_load) ? superclass.on_load : nil end |