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(callable = nil, &block) ⇒ Object
Record every document change durably before it is applied or distributed.
-
#on_load(callable = nil, &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.
94 95 96 97 98 99 |
# File 'lib/yrb_lite/action_cable/sync.rb', line 94 def max_frame_bytes(bytes = :__unset__) @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(callable = nil, &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.
A block recorder runs in the *channel instance’s* context, so it can call the channel’s own methods (current_user, params, a per-connection Current.* accessor) directly, with no thread-local plumbing. (A non-Proc callable is invoked with #call instead, since it carries its own context.) on_change always fires from within sync_receive.
83 84 85 86 87 88 |
# File 'lib/yrb_lite/action_cable/sync.rb', line 83 def on_change(callable = nil, &block) @on_change = callable || block if callable || block return @on_change if defined?(@on_change) && @on_change superclass.respond_to?(:on_change) ? superclass.on_change : nil end |
#on_load(callable = nil, &block) ⇒ Object
Load persisted document state. Called once per key with (key); return a binary Y.js update (or nil for a fresh document).
66 67 68 69 70 71 |
# File 'lib/yrb_lite/action_cable/sync.rb', line 66 def on_load(callable = nil, &block) @on_load = callable || block if callable || block return @on_load if defined?(@on_load) && @on_load superclass.respond_to?(:on_load) ? superclass.on_load : nil end |