Module: Turbocable::Codecs
- Defined in:
- lib/turbocable/codecs.rb,
lib/turbocable/codecs/json.rb,
lib/turbocable/codecs/msgpack.rb
Overview
Registry for payload codecs. Each codec exposes:
.encode(payload) -> String (bytes)
.decode(bytes) -> Object (for tests / round-trips)
.content_type -> String (WebSocket sub-protocol name, informational)
Built-in codecs:
-
:json— always available, no extra dependencies -
:msgpack— requires themsgpackgem (~> 1.7); loaded lazily on first use
Defined Under Namespace
Class Method Summary collapse
-
.fetch(name) ⇒ Module
Returns the codec module for
name. -
.registered ⇒ Array<Symbol>
All codec names (eager + lazy).
Class Method Details
.fetch(name) ⇒ Module
Returns the codec module for name.
:msgpack is loaded on first access; it raises LoadError if the msgpack gem is not installed.
43 44 45 46 47 48 49 50 51 |
# File 'lib/turbocable/codecs.rb', line 43 def self.fetch(name) key = name.to_sym return REGISTRY[key] if REGISTRY.key?(key) return load_lazy_codec!(key) if LAZY_CODECS.include?(key) raise ConfigurationError, "Unknown codec #{key.inspect}. " \ "Available: #{registered.map(&:inspect).join(", ")}." end |
.registered ⇒ Array<Symbol>
Returns all codec names (eager + lazy).
54 55 56 |
# File 'lib/turbocable/codecs.rb', line 54 def self.registered (REGISTRY.keys + LAZY_CODECS).freeze end |