Class: Linterbot::CommentGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/linterbot/comment_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, commit, pull_request_file_patch) ⇒ CommentGenerator

Returns a new instance of CommentGenerator.



9
10
11
12
13
# File 'lib/linterbot/comment_generator.rb', line 9

def initialize(filename, commit, pull_request_file_patch)
  @filename = filename
  @commit = commit
  @pull_request_file_patch = Patch.new(pull_request_file_patch)
end

Instance Attribute Details

#commitObject

Returns the value of attribute commit.



6
7
8
# File 'lib/linterbot/comment_generator.rb', line 6

def commit
  @commit
end

#filenameObject

Returns the value of attribute filename.



5
6
7
# File 'lib/linterbot/comment_generator.rb', line 5

def filename
  @filename
end

#pull_request_file_patchObject

Returns the value of attribute pull_request_file_patch.



7
8
9
# File 'lib/linterbot/comment_generator.rb', line 7

def pull_request_file_patch
  @pull_request_file_patch
end

Instance Method Details

#fileObject



28
29
30
# File 'lib/linterbot/comment_generator.rb', line 28

def file
  @file ||= find_file
end

#generate_comment_for_hint(hint) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/linterbot/comment_generator.rb', line 20

def generate_comment_for_hint(hint)
  if new_file?
    generate_comment_for_new_file_and_hint(hint)
  elsif modified_file? && included_in_file_patch?(hint)
    generate_comment_for_modified_file_and_hint(hint)
  end
end

#generate_comments(hints) ⇒ Object



15
16
17
18
# File 'lib/linterbot/comment_generator.rb', line 15

def generate_comments(hints)
  hints.map { |hint| generate_comment_for_hint(hint) }
    .select { |comment| comment != nil }
end