Sha256: 8c7a2cfd2eddf11f3fe430ffd15b5594b9e7fac3064a041d21ee01286c80d601

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Nanoc
  module Int
    class Compiler
      module Stages
        class DetermineOutdatedness < Nanoc::Core::CompilationStage
          include Nanoc::Core::ContractsSupport

          def initialize(reps:, outdatedness_checker:, outdatedness_store:)
            @reps = reps
            @outdatedness_checker = outdatedness_checker
            @outdatedness_store = outdatedness_store
          end

          contract C::None => C::Any
          def run
            outdated_items = select_outdated_items
            outdated_reps = reps_of_items(outdated_items)

            store_outdated_reps(outdated_reps)

            outdated_items
          end

          private

          def store_outdated_reps(reps)
            @outdatedness_store.clear
            reps.each { |r| @outdatedness_store.add(r) }
          end

          def select_outdated_items
            @reps
              .select { |r| outdated?(r) }
              .map(&:item)
              .uniq
          end

          def reps_of_items(items)
            Set.new(items.flat_map { |i| @reps[i] })
          end

          def outdated?(rep)
            @outdatedness_store.include?(rep) || @outdatedness_checker.outdated?(rep)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nanoc-4.11.12 lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb
nanoc-4.11.11 lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb
nanoc-4.11.10 lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb