Class: Danger::Markdown

Inherits:
BaseMessage show all
Defined in:
lib/danger/danger_core/messages/markdown.rb

Constant Summary collapse

VALID_SIDES =
%w(LEFT RIGHT).freeze

Instance Attribute Summary

Attributes inherited from BaseMessage

#file, #line, #message, #side, #start_line, #start_side, #type

Instance Method Summary collapse

Methods inherited from BaseMessage

#cmp_nils, #compare_by_file_and_line, #eql?, #inline?

Constructor Details

#initialize(message, file = nil, line = nil, start_line: nil, side: nil, start_side: nil) ⇒ Markdown

Returns a new instance of Markdown.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/danger/danger_core/messages/markdown.rb', line 9

def initialize(message, file = nil, line = nil, start_line: nil, side: nil, start_side: nil)
  validate_side!(:side, side)
  validate_side!(:start_side, start_side)

  super(
    type: :markdown,
    message: message,
    file: file,
    line: line,
    start_line: start_line,
    side: side,
    start_side: start_side
  )
end

Instance Method Details

#<=>(other) ⇒ Object



57
58
59
60
61
# File 'lib/danger/danger_core/messages/markdown.rb', line 57

def <=>(other)
  return 1 if other.type != :markdown

  compare_by_file_and_line(other)
end

#==(other) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/danger/danger_core/messages/markdown.rb', line 24

def ==(other)
  return false if other.nil?
  return false unless other.kind_of? self.class

  other.message == message &&
    other.file == file &&
    other.line == line &&
    other.start_line == start_line &&
    other.side == side &&
    other.start_side == start_side
end

#hashObject



36
37
38
39
40
41
42
43
44
# File 'lib/danger/danger_core/messages/markdown.rb', line 36

def hash
  h = 1
  h = h * 31 + message.hash
  h = h * 17 + file.hash
  h = h * 17 + line.hash
  h = h * 17 + start_line.hash
  h = h * 17 + side.hash
  h * 17 + start_side.hash
end

#to_sObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/danger/danger_core/messages/markdown.rb', line 46

def to_s
  extra = []
  extra << "file: #{file}" if file
  extra << "line: #{line}" if line
  extra << "start_line: #{start_line}" if start_line
  extra << "side: #{side}" if side
  extra << "start_side: #{start_side}" if start_side

  "Markdown #{message} { #{extra.join ', '} }"
end