Class: Ace::Bundle::Molecules::SectionCompressor
- Inherits:
-
Object
- Object
- Ace::Bundle::Molecules::SectionCompressor
- Defined in:
- lib/ace/bundle/molecules/section_compressor.rb
Overview
Compresses file content within bundle sections using ace-compressor. Each section is compressed independently. Files that are not compressible (non-markdown/text) pass through unchanged.
Uses the compressor’s file-based API (compress_sources) so that both “exact” and “agent” engines work through the same code path.
Constant Summary collapse
- COMPRESSIBLE_EXTENSIONS =
%w[.md .markdown .mdown .mkd .txt .text].freeze
Instance Method Summary collapse
-
#call(bundle_data) ⇒ Models::BundleData
Compress files in all sections of a bundle.
-
#initialize(default_mode: "off", compressor_mode: "exact", cache_store: nil) ⇒ SectionCompressor
constructor
A new instance of SectionCompressor.
Constructor Details
#initialize(default_mode: "off", compressor_mode: "exact", cache_store: nil) ⇒ SectionCompressor
Returns a new instance of SectionCompressor.
22 23 24 25 26 27 |
# File 'lib/ace/bundle/molecules/section_compressor.rb', line 22 def initialize(default_mode: "off", compressor_mode: "exact", cache_store: nil) @default_mode = default_mode.to_s @compressor_mode = compressor_mode.to_s @cache_store = cache_store || Ace::Compressor::Molecules::CacheStore.new validate_compressor_mode! end |
Instance Method Details
#call(bundle_data) ⇒ Models::BundleData
Compress files in all sections of a bundle.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ace/bundle/molecules/section_compressor.rb', line 32 def call(bundle_data) original_bytes, original_lines = measure_compressible_content(bundle_data) unless bundle_data.has_sections? compress_content(bundle_data) if @default_mode != "off" store_compression_stats(bundle_data, original_bytes, original_lines) return bundle_data end bundle_data.sections.each do |name, section_data| section_mode = resolve_mode(section_data) next if section_mode == "off" compress_section_files(section_data, section_mode) end store_compression_stats(bundle_data, original_bytes, original_lines) bundle_data end |