Class: Omnizip::FilterRegistry
- Inherits:
-
Registry
- Object
- Registry
- Omnizip::FilterRegistry
- Defined in:
- lib/omnizip/filter_registry.rb
Constant Summary collapse
- DEFAULT_FORMATS =
%i[xz seven_zip].freeze
- BUILTIN_FILTERS =
Single source of truth for builtin filters. Each entry binds the filter name to its class and the formats that support it.
{ "bcj-x86": { const: "Omnizip::Filters::BcjX86", formats: %i[xz seven_zip] }, "bcj-arm": { const: "Omnizip::Filters::BcjArm", formats: %i[xz seven_zip] }, "bcj-arm64": { const: "Omnizip::Filters::BcjArm64", formats: [:seven_zip] }, "bcj-ia64": { const: "Omnizip::Filters::BcjIa64", formats: %i[xz seven_zip] }, "bcj-ppc": { const: "Omnizip::Filters::BcjPpc", formats: %i[xz seven_zip] }, "bcj-sparc": { const: "Omnizip::Filters::BcjSparc", formats: %i[xz seven_zip] }, bcj: { const: "Omnizip::Filters::BCJ", formats: [:seven_zip] }, bcj2: { const: "Omnizip::Filters::Bcj2", formats: [:seven_zip] }, delta: { const: "Omnizip::Filters::Delta", formats: %i[xz seven_zip] }, }.freeze
Class Method Summary collapse
- .filters_for_format(format) ⇒ Object
- .get(name) ⇒ Object
- .get_for_format(name, format) ⇒ Object
- .label ⇒ Object
- .not_found_error_class ⇒ Object
- .register(name, filter_class, formats: DEFAULT_FORMATS) ⇒ Object (also: register_with_formats)
- .supports_format?(name, format) ⇒ Boolean
Class Method Details
.filters_for_format(format) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/omnizip/filter_registry.rb', line 74 def filters_for_format(format) # Ensure all lazy triggers have fired so the format filter list # reflects every registered builtin. lazy_triggers.keys.dup.each { |name| get(name) } storage.select { |_, info| info[:formats]&.include?(format) }.keys end |
.get(name) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/omnizip/filter_registry.rb', line 44 def get(name) entry = entry_for(name) unless entry raise not_found_error_class, "#{label} not registered: #{name.inspect}. " \ "Available: #{available.join(', ')}" end entry[:class] end |
.get_for_format(name, format) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/omnizip/filter_registry.rb', line 55 def get_for_format(name, format) entry = entry_for(name) raise KeyError, "Filter not found: #{name}" unless entry unless entry[:formats].include?(format) raise ArgumentError, "Filter #{name} not supported for format #{format}" end entry[:class].new end |
.label ⇒ Object
26 27 28 |
# File 'lib/omnizip/filter_registry.rb', line 26 def label "Filter" end |
.not_found_error_class ⇒ Object
22 23 24 |
# File 'lib/omnizip/filter_registry.rb', line 22 def not_found_error_class Omnizip::UnknownFilterError end |
.register(name, filter_class, formats: DEFAULT_FORMATS) ⇒ Object Also known as: register_with_formats
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/omnizip/filter_registry.rb', line 30 def register(name, filter_class, formats: DEFAULT_FORMATS) raise ArgumentError, "Filter name cannot be nil" if name.nil? raise ArgumentError, "Filter class cannot be nil" if filter_class.nil? synchronize do storage[normalize_key(name)] = { class: filter_class, formats: formats, } end filter_class end |
.supports_format?(name, format) ⇒ Boolean
67 68 69 70 71 72 |
# File 'lib/omnizip/filter_registry.rb', line 67 def supports_format?(name, format) entry = entry_for(name) return false unless entry entry[:formats]&.include?(format) end |