Class: RuboBot::RuboCop::Offenses

Inherits:
Object
  • Object
show all
Defined in:
lib/rubobot/rubocop/offenses.rb

Overview

Offenses found by a RuboCop run

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ Offenses

Returns a new instance of Offenses.



10
11
12
13
14
15
16
17
# File 'lib/rubobot/rubocop/offenses.rb', line 10

def initialize(paths)
  formatter = 'RuboBot::RuboCop::Formatter::OffenseCountFormatter'
  options = { format: formatter,
              formatters: [[formatter]] }

  @paths = Array(paths)
  @runner = ::RuboCop::Runner.new(options, ::RuboCop::ConfigStore.new)
end

Instance Method Details

#==(other) ⇒ Object



29
30
31
# File 'lib/rubobot/rubocop/offenses.rb', line 29

def ==(other)
  to_h == other.to_h
end

#nextObject



19
20
21
22
23
# File 'lib/rubobot/rubocop/offenses.rb', line 19

def next
  Offense.new([offenses.shift].to_h)
rescue TypeError
  raise NoOffensesError
end

#sizeObject



25
26
27
# File 'lib/rubobot/rubocop/offenses.rb', line 25

def size
  offenses.size
end

#to_hObject



33
34
35
36
37
# File 'lib/rubobot/rubocop/offenses.rb', line 33

def to_h
  offenses.each_with_object({}) do |(cop, count), memo|
    memo[cop.name] = count
  end
end