Class: Suggestion
Constant Summary
Constants included
from Suggestible
Suggestible::MAX_LINES_CONTEXT
ApplicationRecord::MAX_PLUCK
ResetOnUnionError::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from Importable
#imported, #importing
Instance Method Summary
collapse
#diff_lines, #fetch_from_content, #from_line, #to_line
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#serializable_hash
Instance Method Details
#appliable?(cached: true) ⇒ Boolean
48
49
50
|
# File 'app/models/suggestion.rb', line 48
def appliable?(cached: true)
inapplicable_reason(cached: cached).nil?
end
|
#branch ⇒ Object
30
31
32
|
# File 'app/models/suggestion.rb', line 30
def branch
noteable.source_branch
end
|
#diff_file ⇒ Object
18
19
20
|
# File 'app/models/suggestion.rb', line 18
def diff_file
note.latest_diff_file
end
|
#file_path ⇒ Object
34
35
36
|
# File 'app/models/suggestion.rb', line 34
def file_path
position.file_path
end
|
#from_line_index ⇒ Object
‘from_line_index` and `to_line_index` represents diff/blob line numbers in index-like way (N-1).
40
41
42
|
# File 'app/models/suggestion.rb', line 40
def from_line_index
from_line - 1
end
|
#inapplicable_reason(cached: true) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/models/suggestion.rb', line 52
def inapplicable_reason(cached: true)
strong_memoize("inapplicable_reason_#{cached}") do
next _("Can't apply this suggestion.") if applied?
next _("This merge request was merged. To apply this suggestion, edit this file directly.") if noteable.merged?
next _("This merge request is closed. To apply this suggestion, edit this file directly.") if noteable.closed?
next _("Can't apply as the source branch was deleted.") unless noteable.source_branch_exists?
next outdated_reason if outdated?(cached: cached) || !note.active?
next _("This suggestion already matches its content.") unless different_content?
next _("This file was modified for readability, and can't accept suggestions. Edit it directly.") if file_path.end_with? "ipynb"
end
end
|
#outdated?(cached: true) ⇒ Boolean
Overwrites outdated column
65
66
67
68
69
70
|
# File 'app/models/suggestion.rb', line 65
def outdated?(cached: true)
return super() if cached
return true unless diff_file
from_content != fetch_from_content
end
|
#single_line? ⇒ Boolean
72
73
74
|
# File 'app/models/suggestion.rb', line 72
def single_line?
lines_above == 0 && lines_below == 0
end
|
#source_project ⇒ Object
22
23
24
|
# File 'app/models/suggestion.rb', line 22
def source_project
noteable.source_project
end
|
#target_line ⇒ Object
76
77
78
|
# File 'app/models/suggestion.rb', line 76
def target_line
position.new_line
end
|
#target_project ⇒ Object
26
27
28
|
# File 'app/models/suggestion.rb', line 26
def target_project
noteable.target_project
end
|
#to_line_index ⇒ Object
44
45
46
|
# File 'app/models/suggestion.rb', line 44
def to_line_index
to_line - 1
end
|