Class: RSpectre::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/rspectre/tracker.rb

Instance Method Summary collapse

Constructor Details

#initializeTracker

Returns a new instance of Tracker.



7
8
9
# File 'lib/rspectre/tracker.rb', line 7

def initialize
  super(Hash.new { Set.new }, Hash.new { Set.new })
end

Instance Method Details

#correct_offensesObject



28
29
30
31
32
33
34
35
# File 'lib/rspectre/tracker.rb', line 28

def correct_offenses
  registry.flat_map { |type, locations| (locations - tracker[type]).to_a }
    .group_by(&:file)
    .transform_values { |nodes| nodes.map(&:node) }
    .each do |file, nodes|
      AutoCorrector.new(file, nodes).correct
    end
end

#offenses?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rspectre/tracker.rb', line 24

def offenses?
  offenses.any?
end

#record(type, node) ⇒ Object



15
16
17
# File 'lib/rspectre/tracker.rb', line 15

def record(type, node)
  tracker[type] <<= node
end

#register(type, node) ⇒ Object



11
12
13
# File 'lib/rspectre/tracker.rb', line 11

def register(type, node)
  registry[type] <<= node
end

#report_offensesObject



19
20
21
22
# File 'lib/rspectre/tracker.rb', line 19

def report_offenses
  offenses.each(&:warn)
  abort
end