Class: Ace::Compressor::Organisms::CompressionRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/compressor/organisms/compression_runner.rb

Constant Summary collapse

SUPPORTED_FORMATS =
%w[path stdio stats].freeze
SUPPORTED_MODES =
%w[exact compact agent].freeze
SUPPORTED_SOURCE_SCOPES =
%w[merged per-source].freeze

Instance Method Summary collapse

Constructor Details

#initialize(paths, mode:, source_scope: "merged", output: nil, format: nil, verbose: false) ⇒ CompressionRunner

Returns a new instance of CompressionRunner.



11
12
13
14
15
16
17
18
19
# File 'lib/ace/compressor/organisms/compression_runner.rb', line 11

def initialize(paths, mode:, source_scope: "merged", output: nil, format: nil, verbose: false)
  @paths = Array(paths)
  @mode = mode
  @source_scope = source_scope.to_s
  @output = output
  @format = (format || Ace::Compressor.config["default_format"] || "path").to_s
  @verbose = verbose
  @cache_store = Ace::Compressor::Molecules::CacheStore.new
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ace/compressor/organisms/compression_runner.rb', line 21

def call
  raise Ace::Compressor::Error, "Unsupported format '#{@format}'. Use --format path, stdio, or stats" unless SUPPORTED_FORMATS.include?(@format)
  unless SUPPORTED_MODES.include?(@mode)
    raise Ace::Compressor::Error,
      "Unsupported mode '#{@mode}'. Use --mode exact, --mode compact, or --mode agent"
  end
  unless SUPPORTED_SOURCE_SCOPES.include?(@source_scope)
    raise Ace::Compressor::Error,
      "Unsupported source scope '#{@source_scope}'. Use --source-scope merged or --source-scope per-source"
  end

  resolver = Ace::Compressor::Molecules::InputResolver.new(@paths)
  begin
    resolved_inputs = resolver.call
    return run_per_source(resolved_inputs) if @source_scope == "per-source"

    run_for_sources(resolved_inputs)
  ensure
    resolver.cleanup if resolver.respond_to?(:cleanup)
  end
end