Class: Aireview::DiffFetcher::Entry
- Inherits:
-
Object
- Object
- Aireview::DiffFetcher::Entry
- Defined in:
- lib/aireview/diff_fetcher.rb
Overview
One file from the GitLab answer: the header, the hunks and what can be done with it. kind:
:text there are hunks, the code can be checked;
:no_text_changes a rename, a mode change, an empty file: nothing to
check;
:unavailable GitLab did not return the diff (too_large, a binary,
an empty diff without a reason): the code exists,
but could not be checked.
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#hunks ⇒ Object
readonly
Returns the value of attribute hunks.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(change) ⇒ Entry
constructor
A new instance of Entry.
- #render ⇒ Object
- #text? ⇒ Boolean
- #unavailable? ⇒ Boolean
Constructor Details
#initialize(change) ⇒ Entry
Returns a new instance of Entry.
21 22 23 24 25 26 27 28 29 |
# File 'lib/aireview/diff_fetcher.rb', line 21 def initialize(change) old_path = change['old_path'] || change['new_path'] new_path = change['new_path'] || change['old_path'] @path = new_path @header = "diff --git a/#{old_path} b/#{new_path}\n--- a/#{old_path}\n+++ b/#{new_path}\n" diff = change['diff'].to_s @kind = classify(change, diff) @hunks = @kind == :text ? split_hunks(diff) : [] end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
19 20 21 |
# File 'lib/aireview/diff_fetcher.rb', line 19 def header @header end |
#hunks ⇒ Object (readonly)
Returns the value of attribute hunks.
19 20 21 |
# File 'lib/aireview/diff_fetcher.rb', line 19 def hunks @hunks end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
19 20 21 |
# File 'lib/aireview/diff_fetcher.rb', line 19 def kind @kind end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
19 20 21 |
# File 'lib/aireview/diff_fetcher.rb', line 19 def path @path end |
Instance Method Details
#body ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/aireview/diff_fetcher.rb', line 39 def body case kind when :text then hunks.join when :no_text_changes then "#{NO_TEXT_CHANGES}\n" else "#{DIFF_UNAVAILABLE}\n" end end |
#render ⇒ Object
47 48 49 |
# File 'lib/aireview/diff_fetcher.rb', line 47 def render header + body end |
#text? ⇒ Boolean
31 32 33 |
# File 'lib/aireview/diff_fetcher.rb', line 31 def text? kind == :text end |
#unavailable? ⇒ Boolean
35 36 37 |
# File 'lib/aireview/diff_fetcher.rb', line 35 def unavailable? kind == :unavailable end |