Class: Postpeek::Decoders::Registry
- Inherits:
-
Object
- Object
- Postpeek::Decoders::Registry
- Defined in:
- lib/postpeek/decoders/registry.rb
Class Method Summary collapse
-
.find(encoding, config: Postpeek.configuration) ⇒ Base?
Returns an instantiated decoder for the given encoding.
-
.register(decoder_class) ⇒ Object
Registers a decoder class for all encodings it handles.
-
.registered ⇒ Hash{String => Class}
Returns a frozen copy of the current registry map.
-
.reset! ⇒ Object
Resets the registry to the built-in defaults.
Class Method Details
.find(encoding, config: Postpeek.configuration) ⇒ Base?
Returns an instantiated decoder for the given encoding. Behaviour on unknown encoding is controlled by config.unknown_encoding:
:raise
23 24 25 26 27 28 29 |
# File 'lib/postpeek/decoders/registry.rb', line 23 def find(encoding, config: Postpeek.configuration) decoder_class = registry[encoding.to_s.downcase] return decoder_class.new if decoder_class handle_unknown_encoding(encoding, config) end |
.register(decoder_class) ⇒ Object
Registers a decoder class for all encodings it handles.
9 10 11 12 13 |
# File 'lib/postpeek/decoders/registry.rb', line 9 def register(decoder_class) decoder_class.handles.each do |encoding| registry[encoding.downcase] = decoder_class end end |
.registered ⇒ Hash{String => Class}
Returns a frozen copy of the current registry map.
33 34 35 |
# File 'lib/postpeek/decoders/registry.rb', line 33 def registered registry.dup.freeze end |
.reset! ⇒ Object
Resets the registry to the built-in defaults. Intended for use in tests only.
38 39 40 41 42 |
# File 'lib/postpeek/decoders/registry.rb', line 38 def reset! @registry = nil seed_built_ins end |