Sha256: 4a8387b4f09f8e1722abef6dc66edde512a03a31372a9180cb829fff3c5369d4

Contents?: true

Size: 1.15 KB

Versions: 15

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Nanoc::CLI::Commands::CompileListeners
  class Aggregate < Abstract
    def initialize(command_runner:, site:, compiler:)
      @site = site
      @compiler = compiler
      @command_runner = command_runner

      @listener_classes = self.class.default_listener_classes
    end

    def start
      setup_listeners
    end

    def stop
      teardown_listeners
    end

    def self.default_listener_classes
      [
        Nanoc::CLI::Commands::CompileListeners::DiffGenerator,
        Nanoc::CLI::Commands::CompileListeners::DebugPrinter,
        Nanoc::CLI::Commands::CompileListeners::TimingRecorder,
        Nanoc::CLI::Commands::CompileListeners::FileActionPrinter,
      ]
    end

    protected

    def setup_listeners
      res = @compiler.run_until_reps_built
      reps = res.fetch(:reps)

      @listeners =
        @listener_classes
        .select { |klass| klass.enable_for?(@command_runner, @site) }
        .map    { |klass| klass.new(reps: reps) }

      @listeners.each(&:start_safely)
    end

    def teardown_listeners
      return unless @listeners
      @listeners.reverse_each(&:stop_safely)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nanoc-4.9.4 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.9.3 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.9.2 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.9.1 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.9.0 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.19 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.18 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.17 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.16 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.15 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.14 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.13 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.12 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.11 lib/nanoc/cli/commands/compile_listeners/aggregate.rb
nanoc-4.8.10 lib/nanoc/cli/commands/compile_listeners/aggregate.rb