class Corundum::QuestionableContent

Constants

CANONICAL_WORD_SETS
WORD_SETS

I hate putting these lists together. I have to keep reminding myself that it's akin to discussing the use of the word. Also, this is a place I'm especially open to contributions.

Public Class Methods

all_sets(core) click to toggle source
# File lib/corundum/questionable-content.rb, line 28
def self.all_sets(core)
  CANONICAL_WORD_SETS.each do |word_set|
    self.new(core) do |qc|
      qc.type = word_set
    end
  end
end

Public Instance Methods

default_configuration(core) click to toggle source
Calls superclass method
# File lib/corundum/questionable-content.rb, line 45
def default_configuration(core)
  super
  core.copy_settings_to(self)
  self.files = core.file_lists.code
  self.qa_rejections = core.qa_rejections
end
define() click to toggle source
# File lib/corundum/questionable-content.rb, line 61
def define
  in_namespace do
    task type do |task|
      require 'corundum/qa-report'

      word_regexp = %r{(?i:#{words.map{|word| "\\b#{word}\\b"}.join("|")})}
      line_regexp = case comments
                    when true, :only
                      %r{\A\s*#.*#{word_regexp}}
                    when false, :both
                      word_regexp
                    when :ignore
                      %r{\A\s*[^#]*#{word_regexp}} #this will fail like "Stuff #{interp}" <word>
                    end

      unless accept_token.nil?
        line_regexp = /#{line_regexp}(?:.(?!#{accept_token}))*\s*\Z/
      end

      rejections = QA::Report.new("Content: #{type}")
      qa_rejections << rejections
      files.each do |filename|
        File::open(filename) do |file|
          file.each_line.with_index do |line, line_number|
            next unless line_regexp =~ line
            line.scan(word_regexp) do |word|
              rejections << QA::Rejection.new(word, filename, line_number+1)
            end
          end
        end
      end

      if rejections.length > limit
        rejections.fail "Maximum allowed uses: #{limit}"
      end
    end
  end
  task :run_quality_assurance => in_namespace(type)
  task :run_continuous_integration => in_namespace(type)
end
resolve_configuration() click to toggle source
Calls superclass method
# File lib/corundum/questionable-content.rb, line 52
def resolve_configuration
  if field_unset?(:words)
    self.words = WORD_SETS.fetch(type.to_s) do
      raise "Word set #{type.inspect} unknown. Choose from: #{WORD_SETS.keys.inspect}"
    end
  end
  super
end