Class: Gitlab::Diff::Rendered::Notebook::DiffFile
- Inherits:
-
File
- Object
- File
- Gitlab::Diff::Rendered::Notebook::DiffFile
show all
- Includes:
- DiffFileHelper, Utils::StrongMemoize
- Defined in:
- lib/gitlab/diff/rendered/notebook/diff_file.rb
Constant Summary
collapse
- RENDERED_TIMEOUT_BACKGROUND =
10.seconds
- BACKGROUND_EXECUTION =
'background'
- FOREGROUND_EXECUTION =
'foreground'
- LOG_IPYNBDIFF_GENERATED =
'IPYNB_DIFF_GENERATED'
- LOG_IPYNBDIFF_TIMEOUT =
'IPYNB_DIFF_TIMEOUT'
- LOG_IPYNBDIFF_INVALID =
'IPYNB_DIFF_INVALID'
- LOG_IPYNBDIFF_TRUNCATED =
'IPYNB_DIFF_TRUNCATED'
Gitlab::Diff::Rendered::Notebook::DiffFileHelper::EMBEDDED_IMAGE_PATTERN
Constants inherited
from File
File::RICH_VIEWERS, File::ROWS_CONTENT_VISIBILITY_THRESHOLD
Instance Attribute Summary collapse
Attributes inherited from File
#diff_refs, #fallback_diff_refs, #max_blob_size, #repository, #unique_identifier
Instance Method Summary
collapse
#image_as_rich_text, #line_positions_at_source_diff, #lines_in_source_diff, #source_line_from_block, #strip_diff_frontmatter
Methods inherited from File
#add_blobs_to_batch_loader, #added_lines, #ai_reviewable?, #alternate_viewer, #binary?, #binary_in_repo?, #blob, #code_review_id, #content_changed?, #content_sha, #diff_hunk, #diff_lines, #diff_lines_for_serializer, #diffable?, #diffable_text?, #different_type?, #empty?, #expand_to_full!, #external_storage, #external_storage_error?, #file_hash, #file_identifier, #file_identifier_hash, #file_path, #fully_expanded?, #highlight_loaded?, #highlighted_diff_lines=, #image_diff?, #ipynb?, #line_code, #line_code_for_position, #line_for_line_code, #line_for_position, #manually_expanded?, #modified_file?, #new_blob_lines_between, #new_content_sha, #new_sha, #next_line, #no_preview?, #old_content_sha, #old_sha, #parallel_diff_lines, #paths, #position, #position_for_line_code, #prev_line, #raw_diff, #raw_size, #removed_lines, #rendered_as_text?, #rich_viewer, #simple_viewer, #size, #stored_externally?, #text?, #text_in_repo?, #unfold_diff_lines, #unfolded?, #viewer, #viewer_hunks, #whitespace_only?
Constructor Details
#initialize(diff_file) ⇒ DiffFile
Returns a new instance of DiffFile.
23
24
25
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 23
def initialize(diff_file)
@source_diff = diff_file
end
|
Instance Attribute Details
#source_diff ⇒ Object
Returns the value of attribute source_diff.
18
19
20
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 18
def source_diff
@source_diff
end
|
Instance Method Details
#diff ⇒ Object
39
40
41
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 39
def diff
strong_memoize(:diff) { transformed_diff }
end
|
#diff_lines_with_match_tail ⇒ Object
67
68
69
70
71
72
73
74
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 67
def diff_lines_with_match_tail
lines = highlighted_diff_lines
return [] if lines.empty?
return [] if blob.nil?
lines
end
|
#has_renderable? ⇒ Boolean
43
44
45
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 43
def has_renderable?
!notebook_diff.nil? && diff.diff.present?
end
|
#highlighted_diff_lines ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 55
def highlighted_diff_lines
strong_memoize(:highlighted_diff_lines) do
lines = Gitlab::Diff::Highlight.new(self, repository: self.repository).highlight
lines_in_source = lines_in_source_diff(
source_diff.highlighted_diff_lines, source_diff.deleted_file?, source_diff.new_file?
)
lines.zip(line_positions_at_source_diff(lines, transformed_blocks))
.map { |line, positions| mutate_line(line, positions, lines_in_source) }
end
end
|
#new_blob ⇒ Object
33
34
35
36
37
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 33
def new_blob
return unless notebook_diff
strong_memoize(:new_blob) { ::Blobs::Notebook.decorate(source_diff.new_blob, notebook_diff.to.as_text) }
end
|
#old_blob ⇒ Object
27
28
29
30
31
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 27
def old_blob
return unless notebook_diff
strong_memoize(:old_blob) { ::Blobs::Notebook.decorate(source_diff.old_blob, notebook_diff.from.as_text) }
end
|
#rendered ⇒ Object
47
48
49
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 47
def rendered
self
end
|
#rendered? ⇒ Boolean
51
52
53
|
# File 'lib/gitlab/diff/rendered/notebook/diff_file.rb', line 51
def rendered?
true
end
|