Class: DiffNotePosition

Inherits:
ApplicationRecord show all
Defined in:
app/models/diff_note_position.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 Attribute Details

#line_rangeObject

Returns the value of attribute line_range.



5
6
7
# File 'app/models/diff_note_position.rb', line 5

def line_range
  @line_range
end

Class Method Details

.create_or_update_for(note, params) ⇒ Object



35
36
37
38
39
40
41
# File 'app/models/diff_note_position.rb', line 35

def self.create_or_update_for(note, params)
  attrs = position_to_attrs(params[:position])
  attrs.merge!(params.slice(:diff_type, :line_code))
  attrs[:note_id] = note.id

  upsert(attrs, unique_by: [:note_id, :diff_type])
end

.position_to_attrs(position) ⇒ Object



43
44
45
46
47
# File 'app/models/diff_note_position.rb', line 43

def self.position_to_attrs(position)
  position_attrs = position.to_h
  position_attrs[:diff_content_type] = position_attrs.delete(:position_type)
  position_attrs.except(:line_range, :ignore_whitespace_change)
end

Instance Method Details

#positionObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/diff_note_position.rb', line 16

def position
  Gitlab::Diff::Position.new(
    old_path: old_path,
    new_path: new_path,
    old_line: old_line,
    new_line: new_line,
    position_type: diff_content_type,
    diff_refs: Gitlab::Diff::DiffRefs.new(
      base_sha: base_sha,
      start_sha: start_sha,
      head_sha: head_sha
    )
  )
end

#position=(position) ⇒ Object



31
32
33
# File 'app/models/diff_note_position.rb', line 31

def position=(position)
  assign_attributes(self.class.position_to_attrs(position))
end