Class: Ace::Bundle::Molecules::SectionCompressor

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(default_mode: "off", compressor_mode: "exact", cache_store: nil) ⇒ SectionCompressor

Returns a new instance of SectionCompressor.

Parameters:

  • default_mode (String) (defaults to: "off")

    default source scope: “off”, “per-source”, “merged”

  • compressor_mode (String) (defaults to: "exact")

    compressor engine: “exact”, “agent”

  • cache_store (Ace::Compressor::Molecules::CacheStore, nil) (defaults to: nil)

    injectable cache store



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.

Parameters:

Returns:



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