Class: Corundum::QuestionableContent
- Inherits:
-
Mattock::Tasklib
- Object
- Mattock::Tasklib
- Corundum::QuestionableContent
- Defined in:
- lib/corundum/questionable-content.rb
Constant Summary collapse
- 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.
{ "debug" => ["p", "debugger"], #ok "profanity" => ['fuck\w*', 'shit\w*'], #ok "ableism" => ["crazy", '\w*sanity', "dumb", 'idiot\w*', "lame", 'moron\w*', "retarded"], #ok "racism" => ["chink", "coon", "dago", "gook", 'gyp\w*', "k[yi]ke", 'nig\w*', "spic"], #ok "gender" => ["bitch", "cocksucker", "cunt", "dyke", "faggot", "tranny"], #ok "issues" => ["XXX", "TODO"], #ok }
- CANONICAL_WORD_SETS =
WORD_SETS.keys
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.all_sets(core) ⇒ Object
28 29 30 31 32 33 34 |
# 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 |
Instance Method Details
#default_configuration(core) ⇒ Object
45 46 47 48 49 50 |
# 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 ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# 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 ⇒ Object
52 53 54 55 56 57 58 59 |
# 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 |