Class: AMQP::Client::MessageCodecRegistry
- Inherits:
-
Object
- Object
- AMQP::Client::MessageCodecRegistry
- Defined in:
- lib/amqp/client/message_codec_registry.rb
Overview
Internal registry that stores content_type parsers and content_encoding coders. Only exact content_type and content_encoding matches are supported.
Instance Method Summary collapse
-
#dup ⇒ Object
Lightweight cloning: registry contents duplicated (shallow copy of handler references).
-
#enable_builtin_codecs ⇒ self
Enable all built-in codecs (parsers and coders).
-
#enable_builtin_coders ⇒ self
Enable built-in coders for common content encodings.
-
#enable_builtin_parsers ⇒ self
Enable built-in parsers for common content types.
-
#find_coder(content_encoding) ⇒ Object?
Find coder handler based on content_encoding.
-
#find_parser(content_type) ⇒ Object?
Find parser handler based on message properties.
-
#initialize ⇒ MessageCodecRegistry
constructor
A new instance of MessageCodecRegistry.
-
#list_content_encodings ⇒ Array<String>
Introspection helper to list all registered content encodings.
-
#list_content_types ⇒ Array<String>
Introspection helper to list all registered content types.
-
#register_coder(content_encoding:, coder:) ⇒ self
Register a coder for a specific content_encoding.
-
#register_parser(content_type:, parser:) ⇒ self
Register a parser for a content_type.
Constructor Details
#initialize ⇒ MessageCodecRegistry
Returns a new instance of MessageCodecRegistry.
8 9 10 11 |
# File 'lib/amqp/client/message_codec_registry.rb', line 8 def initialize @parsers = {} # content_type => handler @coders = {} # content_encoding => handler end |
Instance Method Details
#dup ⇒ Object
Lightweight cloning: registry contents duplicated (shallow copy of handler references)
84 85 86 87 88 89 |
# File 'lib/amqp/client/message_codec_registry.rb', line 84 def dup copy = self.class.new @parsers.each { |k, v| copy.register_parser(content_type: k, parser: v) } @coders.each { |k, v| copy.register_coder(content_encoding: k, coder: v) } copy end |
#enable_builtin_codecs ⇒ self
Enable all built-in codecs (parsers and coders)
79 80 81 |
# File 'lib/amqp/client/message_codec_registry.rb', line 79 def enable_builtin_codecs enable_builtin_parsers.enable_builtin_coders end |
#enable_builtin_coders ⇒ self
Enable built-in coders for common content encodings
71 72 73 74 75 |
# File 'lib/amqp/client/message_codec_registry.rb', line 71 def enable_builtin_coders register_coder(content_encoding: "gzip", coder: Coders::Gzip) register_coder(content_encoding: "deflate", coder: Coders::Deflate) self end |
#enable_builtin_parsers ⇒ self
Enable built-in parsers for common content types
63 64 65 66 67 |
# File 'lib/amqp/client/message_codec_registry.rb', line 63 def enable_builtin_parsers register_parser(content_type: "text/plain", parser: Parsers::Plain) register_parser(content_type: "application/json", parser: Parsers::JSONParser) self end |
#find_coder(content_encoding) ⇒ Object?
Find coder handler based on content_encoding
45 46 47 |
# File 'lib/amqp/client/message_codec_registry.rb', line 45 def find_coder(content_encoding) @coders[content_encoding] end |
#find_parser(content_type) ⇒ Object?
Find parser handler based on message properties
38 39 40 |
# File 'lib/amqp/client/message_codec_registry.rb', line 38 def find_parser(content_type) @parsers[content_type] end |
#list_content_encodings ⇒ Array<String>
Introspection helper to list all registered content encodings
57 58 59 |
# File 'lib/amqp/client/message_codec_registry.rb', line 57 def list_content_encodings @coders.keys end |
#list_content_types ⇒ Array<String>
Introspection helper to list all registered content types
51 52 53 |
# File 'lib/amqp/client/message_codec_registry.rb', line 51 def list_content_types @parsers.keys end |
#register_coder(content_encoding:, coder:) ⇒ self
Register a coder for a specific content_encoding
29 30 31 32 33 |
# File 'lib/amqp/client/message_codec_registry.rb', line 29 def register_coder(content_encoding:, coder:) validate_coder!(coder) @coders[content_encoding] = coder self end |
#register_parser(content_type:, parser:) ⇒ self
Register a parser for a content_type
18 19 20 21 22 |
# File 'lib/amqp/client/message_codec_registry.rb', line 18 def register_parser(content_type:, parser:) validate_parser!(parser) @parsers[content_type] = parser self end |