Class: Gnurr::Processor

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/gnurr/processor.rb

Overview

Main class for execution

Constant Summary collapse

LINTERS =
{
  es: Gnurr::Linters::EsLinter,
  haml: Gnurr::Linters::HamlLinter,
  ruby: Gnurr::Linters::RubyLinter,
  scss: Gnurr::Linters::ScssLinter
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#array_to_ranges, #escaped_filename, #left_bump, #log_error, #severity_color

Constructor Details

#initialize(options = {}) ⇒ Processor

Returns a new instance of Processor.



20
21
22
23
24
25
26
27
28
29
# File 'lib/gnurr/processor.rb', line 20

def initialize(options = {})
  @options = options
  @violation_count = 0
  @files = []
  if @options[:linters] && options[:linters].any?
    @options[:linters] = LINTERS.keys & @options[:linters]
  else
    @options[:linters] = LINTERS.keys
  end
end

Instance Attribute Details

#violation_countObject (readonly)

Returns the value of attribute violation_count.



18
19
20
# File 'lib/gnurr/processor.rb', line 18

def violation_count
  @violation_count
end

Instance Method Details

#executeObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gnurr/processor.rb', line 31

def execute
  @lints ||= {}
  @violation_count = 0
  @options[:linters].each do |type|
    lint_type(type)
  end
  if @options[:stdout]
    print 'Total Violations: '.colorize(mode: :bold)
    puts @violation_count.to_s.colorize(mode: :bold, color: severity_color(@violation_count, @files.length))
  end
  @lints
end

#lint_type(type) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/gnurr/processor.rb', line 44

def lint_type(type)
  @lints[type] = LINTERS[type].new(@options)
  @lints[type].execute
  @violation_count += @lints[type].violation_count
  (@files += @lints[type].files.keys).uniq!
rescue => e
  log_error(e)
  @lints[type] = e
end

#lintsObject



54
55
56
# File 'lib/gnurr/processor.rb', line 54

def lints
  @lints ||= {}
end