Sha256: 945086854fe6a05ee9e12d434967f5a61b17150e3c0581cfd8360e3666b934b1

Contents?: true

Size: 1.05 KB

Versions: 12

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Nanoc::CLI::Commands::CompileListeners
  class Abstract
    def initialize(*)
      super()
    end

    def self.enable_for?(command_runner, site) # rubocop:disable Lint/UnusedMethodArgument
      true
    end

    # @abstract
    def start
      raise NotImplementedError, "Subclasses of #{self.class} must implement #start"
    end

    # @abstract
    def stop; end

    def wrapped_start
      @_notification_names = []
      start
    end

    def wrapped_stop
      stop

      Nanoc::Core::NotificationCenter.sync

      @_notification_names.each do |name|
        Nanoc::Core::NotificationCenter.remove(name, self)
      end
    end

    def run_while
      wrapped_start
      yield
    ensure
      wrapped_stop
    end

    def start_safely
      wrapped_start
      @_started = true
    end

    def stop_safely
      wrapped_stop if @_started
      @_started = false
    end

    def on(sym)
      @_notification_names << sym
      Nanoc::Core::NotificationCenter.on(sym, self) { |*args| yield(*args) }
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
nanoc-4.11.12 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.11 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.10 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.9 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.8 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.7 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.6 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.5 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.4 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.3 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.2 lib/nanoc/cli/commands/compile_listeners/abstract.rb
nanoc-4.11.1 lib/nanoc/cli/commands/compile_listeners/abstract.rb