Class: Inputs::RubocopJson

Inherits:
Object
  • Object
show all
Defined in:
lib/stash_pull_request_commenter/inputs/rubocop_json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = 'rubocop.json') ⇒ RubocopJson

Returns a new instance of RubocopJson.



8
9
10
11
12
# File 'lib/stash_pull_request_commenter/inputs/rubocop_json.rb', line 8

def initialize(filename = 'rubocop.json')
  self.filename = filename

  fail "#{filename} does not exist" unless File.exist?(filename)
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/stash_pull_request_commenter/inputs/rubocop_json.rb', line 6

def filename
  @filename
end

Instance Method Details

#commentsObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/stash_pull_request_commenter/inputs/rubocop_json.rb', line 14

def comments
  report['files'].map do |file|
    file['offenses'].map do |offense|
      Comment.new(
        file: file['path'],
        line: offense['location']['line'],
        text: offense['message']
      )
    end
  end.flatten
end