Class: Gitlab::Diff::Formatters::BaseFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/diff/formatters/base_formatter.rb

Direct Known Subclasses

ImageFormatter, TextFormatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ BaseFormatter

Returns a new instance of BaseFormatter.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 14

def initialize(attrs)
  if diff_file = attrs[:diff_file]
    attrs[:diff_refs] = diff_file.diff_refs
    attrs[:old_path] = diff_file.old_path
    attrs[:new_path] = diff_file.new_path
    attrs[:file_identifier_hash] = diff_file.file_identifier_hash
  end

  if diff_refs = attrs[:diff_refs]
    attrs[:base_sha] = diff_refs.base_sha
    attrs[:start_sha] = diff_refs.start_sha
    attrs[:head_sha]  = diff_refs.head_sha
  end

  @old_path = attrs[:old_path]
  @new_path = attrs[:new_path]
  @file_identifier_hash = attrs[:file_identifier_hash]
  @base_sha = attrs[:base_sha]
  @start_sha = attrs[:start_sha]
  @head_sha  = attrs[:head_sha]
end

Instance Attribute Details

#base_shaObject (readonly)

Returns the value of attribute base_sha


10
11
12
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 10

def base_sha
  @base_sha
end

#file_identifier_hashObject (readonly)

Returns the value of attribute file_identifier_hash


9
10
11
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 9

def file_identifier_hash
  @file_identifier_hash
end

#head_shaObject (readonly)

Returns the value of attribute head_sha


12
13
14
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 12

def head_sha
  @head_sha
end

#new_pathObject (readonly)

Returns the value of attribute new_path


8
9
10
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 8

def new_path
  @new_path
end

#old_pathObject (readonly)

Returns the value of attribute old_path


7
8
9
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 7

def old_path
  @old_path
end

#start_shaObject (readonly)

Returns the value of attribute start_sha


11
12
13
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 11

def start_sha
  @start_sha
end

Instance Method Details

#==(other) ⇒ Object

Raises:

  • (NotImplementedError)

61
62
63
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 61

def ==(other)
  raise NotImplementedError
end

#complete?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

65
66
67
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 65

def complete?
  raise NotImplementedError
end

#keyObject


36
37
38
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 36

def key
  [base_sha, start_sha, head_sha, Digest::SHA1.hexdigest(old_path || ""), Digest::SHA1.hexdigest(new_path || "")]
end

#position_typeObject

Raises:

  • (NotImplementedError)

57
58
59
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 57

def position_type
  raise NotImplementedError
end

#to_hObject


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 40

def to_h
  out = {
    base_sha: base_sha,
    start_sha: start_sha,
    head_sha: head_sha,
    old_path: old_path,
    new_path: new_path,
    position_type: position_type
  }

  if Feature.enabled?(:file_identifier_hash)
    out[:file_identifier_hash] = file_identifier_hash
  end

  out
end