Sha256: b32287da450f0675cb33f630eebc9c242c54a9d6d95c4015f91416d94153a203

Contents?: true

Size: 1.98 KB

Versions: 6

Compression:

Stored size: 1.98 KB

Contents

module Nanoc::Int::Compiler::Stages
  class CompileReps
    def initialize(outdatedness_store:, dependency_store:, action_sequences:, compilation_context:, compiled_content_cache:)
      @outdatedness_store = outdatedness_store
      @dependency_store = dependency_store
      @action_sequences = action_sequences
      @compilation_context = compilation_context
      @compiled_content_cache = compiled_content_cache
    end

    def run
      selector = Nanoc::Int::ItemRepSelector.new(@outdatedness_store.to_a)
      selector.each do |rep|
        handle_errors_while(rep) { compile_rep(rep, is_outdated: @outdatedness_store.include?(rep)) }
      end
    ensure
      @outdatedness_store.store
      @compiled_content_cache.store
    end

    private

    def handle_errors_while(item_rep)
      yield
    rescue => e
      raise Nanoc::Int::Errors::CompilationError.new(e, item_rep)
    end

    def compile_rep(rep, is_outdated:)
      item_rep_compiler.call(rep, is_outdated: is_outdated)
    end

    def item_rep_compiler
      @_item_rep_compiler ||= begin
        recalculate_phase = Nanoc::Int::Compiler::Phases::Recalculate.new(
          action_sequences: @action_sequences,
          dependency_store: @dependency_store,
          compilation_context: @compilation_context,
        )

        cache_phase = Nanoc::Int::Compiler::Phases::Cache.new(
          compiled_content_cache: @compiled_content_cache,
          snapshot_repo: @compilation_context.snapshot_repo,
          wrapped: recalculate_phase,
        )

        resume_phase = Nanoc::Int::Compiler::Phases::Resume.new(
          wrapped: cache_phase,
        )

        write_phase = Nanoc::Int::Compiler::Phases::Write.new(
          snapshot_repo: @compilation_context.snapshot_repo,
          wrapped: resume_phase,
        )

        mark_done_phase = Nanoc::Int::Compiler::Phases::MarkDone.new(
          wrapped: write_phase,
          outdatedness_store: @outdatedness_store,
        )

        mark_done_phase
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nanoc-4.7.9 lib/nanoc/base/services/compiler/stages/compile_reps.rb
nanoc-4.7.8 lib/nanoc/base/services/compiler/stages/compile_reps.rb
nanoc-4.7.7 lib/nanoc/base/services/compiler/stages/compile_reps.rb
nanoc-4.7.6 lib/nanoc/base/services/compiler/stages/compile_reps.rb
nanoc-4.7.5 lib/nanoc/base/services/compiler/stages/compile_reps.rb
nanoc-4.7.4 lib/nanoc/base/services/compiler/stages/compile_reps.rb