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

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

Direct Known Subclasses

FileFormatter, 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
# 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
  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]
  @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.



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

def base_sha
  @base_sha
end

#head_shaObject (readonly)

Returns the value of attribute head_sha.



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

def head_sha
  @head_sha
end

#ignore_whitespace_changeObject (readonly)

Returns the value of attribute ignore_whitespace_change.



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

def ignore_whitespace_change
  @ignore_whitespace_change
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.



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

def start_sha
  @start_sha
end

Instance Method Details

#==(other) ⇒ Object

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 53

def ==(other)
  raise NotImplementedError
end

#complete?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

def complete?
  raise NotImplementedError
end

#keyObject



34
35
36
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 34

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

#position_typeObject

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 49

def position_type
  raise NotImplementedError
end

#to_hObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/diff/formatters/base_formatter.rb', line 38

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