Class: Danger::Violation

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/danger_core/messages/violation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, sticky, file = nil, line = nil) ⇒ Violation

Returns a new instance of Violation.



5
6
7
8
9
10
# File 'lib/danger/danger_core/messages/violation.rb', line 5

def initialize(message, sticky, file = nil, line = nil)
  self.message = message
  self.sticky = sticky
  self.file = file
  self.line = line
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



3
4
5
# File 'lib/danger/danger_core/messages/violation.rb', line 3

def file
  @file
end

#lineObject

Returns the value of attribute line.



3
4
5
# File 'lib/danger/danger_core/messages/violation.rb', line 3

def line
  @line
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/danger/danger_core/messages/violation.rb', line 3

def message
  @message
end

#stickyObject

Returns the value of attribute sticky.



3
4
5
# File 'lib/danger/danger_core/messages/violation.rb', line 3

def sticky
  @sticky
end

Instance Method Details

#==(other) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/danger/danger_core/messages/violation.rb', line 12

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

  other.message == message &&
    other.sticky == sticky &&
    other.file == file &&
    other.line == line
end

#inline?Boolean

Returns true if is a file or line, false otherwise

Returns:

  • (Boolean)

    returns true if is a file or line, false otherwise



23
24
25
# File 'lib/danger/danger_core/messages/violation.rb', line 23

def inline?
  file || line
end

#to_sObject



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

def to_s
  extra = []
  extra << "sticky: #{sticky}"
  extra << "file: #{file}" if file
  extra << "line: #{line}" if line

  "Violation #{message} { #{extra.join ', '.freeze} }"
end