Class: Danger::Suggester::Hunk

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/suggester/hunk.rb

Instance Method Summary collapse

Constructor Details

#initialize(hunk) ⇒ Hunk

Returns a new instance of Hunk

Parameters:

  • hunk (GitDiff::Hunk)

8
9
10
# File 'lib/danger/suggester/hunk.rb', line 8

def initialize(hunk)
  @hunk = hunk
end

Instance Method Details

#changesArray<Danger::Suggester::Change>

Returns:


13
14
15
16
17
# File 'lib/danger/suggester/hunk.rb', line 13

def changes
  chunks_without_context.map do |chunk|
    ::Danger::Suggester::Change.new(chunk)
  end
end

#chunksArray<Array<GitDiff::Line::Context>>

Returns:

  • (Array<Array<GitDiff::Line::Context>>)

20
21
22
23
24
25
26
27
# File 'lib/danger/suggester/hunk.rb', line 20

def chunks
  @hunk.lines.chunk_while do |a, b|
    a.instance_of?(::GitDiff::Line::Context) && b.instance_of?(::GitDiff::Line::Context) ||
      a.instance_of?(::GitDiff::Line::Deletion) && b.instance_of?(::GitDiff::Line::Deletion) ||
      a.instance_of?(::GitDiff::Line::Deletion) && b.instance_of?(::GitDiff::Line::Addition) ||
      a.instance_of?(::GitDiff::Line::Addition) && b.instance_of?(::GitDiff::Line::Addition)
  end
end

#chunks_without_contextArray<Array<GitDiff::Line::Context>>

Returns:

  • (Array<Array<GitDiff::Line::Context>>)

30
31
32
33
34
# File 'lib/danger/suggester/hunk.rb', line 30

def chunks_without_context
  chunks.reject do |chunk|
    chunk.first.instance_of?(::GitDiff::Line::Context)
  end
end