Sha256: da34e2215b60254d97c64cf59373a4243129d4f73cd15612332ad097025782b6

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

module Diecut
  module ReportBuilders
    class OrphanedField < ReportBuilder
      register

      def report_name
        "Template fields all have settings"
      end

      def report_fields
        ["Output field", "Source file"]
      end

      def collect
        context_class = mill.context_class

        required_fields = {}

        context_class.field_names.each do |field_name|
          if context_class.field_metadata(field_name).is?(:required)
            required_fields[field_name.to_s] = []
          end
        end

        each_template do |name, template|
          template.reduced.leaf_fields.each do |field|
            field = field.join(".")
            if required_fields.has_key?(field)
              required_fields[field] << template.path
            end
          end
        end

        each_option do |option, plugin|
          next unless option.has_context_path?
          field = option.context_path.join(".")
          required_fields.delete(field)
        end

        required_fields.each do |name, targets|
          targets.each do |target|
            report.add(name, target)
          end
        end
      end

      def report_status
        report.empty? ? "OK" : "WARN"
      end


      def other_advice
        <<-EOA
        These fields might not receive a value during generation, which will
        raise an error at use time.

        It's possible these fields are set in a resolve block in one of the
        plugins - Diecut can't check for that yet.
        EOA
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
diecut-0.0.5 lib/diecut/report-builders/orphaned-field.rb
diecut-0.0.4 lib/diecut/report-builders/orphaned-field.rb
diecut-0.0.3 lib/diecut/report-builders/orphaned-field.rb