Sha256: bf80dc3a0d705d3c5b65c30ba4bd231b2e783381e7bc730f198c3d074814e6a7

Contents?: true

Size: 1.41 KB

Versions: 15

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Nanoc::Checking
  # @api private
  class OutputDirNotFoundError < Nanoc::Int::Errors::Generic
    def initialize(directory_path)
      super("Unable to run check against output directory at “#{directory_path}”: directory does not exist.")
    end
  end

  # @api private
  class Check < Nanoc::Int::Context
    extend DDPlugin::Plugin

    attr_reader :issues

    def self.create(site)
      output_dir = site.config[:output_dir]
      unless File.exist?(output_dir)
        raise Nanoc::Checking::OutputDirNotFoundError.new(output_dir)
      end
      output_filenames = Dir[output_dir + '/**/*'].select { |f| File.file?(f) }

      # FIXME: ugly
      view_context = site.compiler.compilation_context.create_view_context(Nanoc::Int::DependencyTracker::Null.new)

      context = {
        items: Nanoc::PostCompileItemCollectionView.new(site.items, view_context),
        layouts: Nanoc::LayoutCollectionView.new(site.layouts, view_context),
        config: Nanoc::ConfigView.new(site.config, view_context),
        output_filenames: output_filenames,
      }

      new(context)
    end

    def initialize(context)
      super(context)

      @issues = Set.new
    end

    def run
      raise NotImplementedError.new('Nanoc::Checking::Check subclasses must implement #run')
    end

    def add_issue(desc, subject: nil)
      @issues << Issue.new(desc, subject, self.class)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nanoc-4.8.9 lib/nanoc/checking/check.rb
nanoc-4.8.8 lib/nanoc/checking/check.rb
nanoc-4.8.7 lib/nanoc/checking/check.rb
nanoc-4.8.6 lib/nanoc/checking/check.rb
nanoc-4.8.5 lib/nanoc/checking/check.rb
nanoc-4.8.4 lib/nanoc/checking/check.rb
nanoc-4.8.3 lib/nanoc/checking/check.rb
nanoc-4.8.2 lib/nanoc/checking/check.rb
nanoc-4.8.1 lib/nanoc/checking/check.rb
nanoc-4.8.0 lib/nanoc/checking/check.rb
nanoc-4.7.14 lib/nanoc/checking/check.rb
nanoc-4.7.13 lib/nanoc/checking/check.rb
nanoc-4.7.12 lib/nanoc/checking/check.rb
nanoc-4.7.11 lib/nanoc/checking/check.rb
nanoc-4.7.10 lib/nanoc/checking/check.rb