Sha256: a3f73a573ce05eac82e6162b81272afac260fa8142b675d95caeb82ed8547dd5

Contents?: true

Size: 1006 Bytes

Versions: 16

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

module Nanoc::Int::Compiler::Phases
  class Abstract
    include Nanoc::Int::ContractsSupport

    def initialize(wrapped:)
      @wrapped = wrapped
    end

    def start
      @wrapped&.start
    end

    def stop
      @wrapped&.stop
    end

    def call(rep, is_outdated:)
      notify(:phase_started, rep)
      run(rep, is_outdated: is_outdated) do
        notify(:phase_yielded, rep)
        @wrapped.call(rep, is_outdated: is_outdated)
        notify(:phase_resumed, rep)
      end
      notify(:phase_ended, rep)
    rescue
      notify(:phase_aborted, rep)
      raise
    end

    contract Nanoc::Int::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
    def run(_rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
      raise NotImplementedError
    end

    private

    def notify(sym, rep)
      name = self.class.to_s.sub(/^.*::/, '')
      Nanoc::Int::NotificationCenter.post(sym, name, rep)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
nanoc-4.11.0 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.10.4 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.10.3 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.10.2 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.10.1 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.10.0 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.9 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.8 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.7 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.6 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.5 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.4 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.3 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.2 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.1 lib/nanoc/base/services/compiler/phases/abstract.rb
nanoc-4.9.0 lib/nanoc/base/services/compiler/phases/abstract.rb