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.



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

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.



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

def filename
  @filename
end

Instance Method Details

#commentsObject



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

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