Module: Omnizip::ArchiveHandler
- Defined in:
- lib/omnizip/archive_handler.rb
Overview
Unified archive handler interface for the Convenience module.
Each format that wants to participate in Omnizip.compress_file /
extract_archive / etc. registers a Handler here. The Handler exposes
a small canonical API (+create+, open, extract_to, list) that
the Convenience module calls; the Handler then delegates to the
format-specific reader/writer.
Class Method Summary collapse
-
.available ⇒ Array<Symbol>
List of registered format names.
-
.for(format) ⇒ Object
Look up the handler for
format. -
.register(format, handler) ⇒ void
Register a handler for a format symbol.
-
.unregister(format) ⇒ void
Remove a handler (primarily for testing).
Class Method Details
.available ⇒ Array<Symbol>
List of registered format names.
55 56 57 |
# File 'lib/omnizip/archive_handler.rb', line 55 def available @handlers.keys end |
.for(format) ⇒ Object
Look up the handler for format. Triggers the registered lazy
load constant if the format is one of the built-ins.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/omnizip/archive_handler.rb', line 36 def for(format) handler = @handlers[format.to_sym] return handler if handler trigger = LAZY_LOAD_TRIGGERS[format.to_sym] if trigger trigger.call handler = @handlers[format.to_sym] return handler if handler end raise Omnizip::UnsupportedFormatError, "No archive handler registered for #{format.inspect}. " \ "Registered: #{@handlers.keys.join(', ')}" end |
.register(format, handler) ⇒ void
This method returns an undefined value.
Register a handler for a format symbol.
26 27 28 |
# File 'lib/omnizip/archive_handler.rb', line 26 def register(format, handler) @handlers[format.to_sym] = handler end |
.unregister(format) ⇒ void
This method returns an undefined value.
Remove a handler (primarily for testing).
62 63 64 |
# File 'lib/omnizip/archive_handler.rb', line 62 def unregister(format) @handlers.delete(format.to_sym) end |