Class: Suggestion

Inherits:
ApplicationRecord show all
Includes:
IgnorableColumns, Importable, Suggestible
Defined in:
app/models/suggestion.rb

Constant Summary

Constants included from Suggestible

Suggestible::MAX_LINES_CONTEXT

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Instance Method Summary collapse

Methods included from Suggestible

#diff_lines, #fetch_from_content, #from_line, #to_line

Methods inherited from ApplicationRecord

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

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Method Details

#appliable?(cached: true) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/suggestion.rb', line 48

def appliable?(cached: true)
  inapplicable_reason(cached: cached).nil?
end

#branchObject



30
31
32
# File 'app/models/suggestion.rb', line 30

def branch
  noteable.source_branch
end

#diff_fileObject



18
19
20
# File 'app/models/suggestion.rb', line 18

def diff_file
  note.latest_diff_file
end

#file_pathObject



34
35
36
# File 'app/models/suggestion.rb', line 34

def file_path
  position.file_path
end

#from_line_indexObject

‘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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


72
73
74
# File 'app/models/suggestion.rb', line 72

def single_line?
  lines_above == 0 && lines_below == 0
end

#source_projectObject



22
23
24
# File 'app/models/suggestion.rb', line 22

def source_project
  noteable.source_project
end

#target_lineObject



76
77
78
# File 'app/models/suggestion.rb', line 76

def target_line
  position.new_line
end

#target_projectObject



26
27
28
# File 'app/models/suggestion.rb', line 26

def target_project
  noteable.target_project
end

#to_line_indexObject



44
45
46
# File 'app/models/suggestion.rb', line 44

def to_line_index
  to_line - 1
end