Class: Danger::Violation
- Inherits:
-
BaseMessage
- Object
- BaseMessage
- Danger::Violation
- Defined in:
- lib/danger/danger_core/messages/violation.rb
Constant Summary collapse
- VALID_TYPES =
%I[error warning message].freeze
Instance Attribute Summary collapse
-
#sticky ⇒ Object
Returns the value of attribute sticky.
Attributes inherited from BaseMessage
#file, #line, #message, #side, #start_line, #start_side, #type
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(message, sticky, file = nil, line = nil, type: :warning) ⇒ Violation
constructor
A new instance of Violation.
- #to_s ⇒ Object
Methods inherited from BaseMessage
#cmp_nils, #compare_by_file_and_line, #eql?, #inline?
Constructor Details
#initialize(message, sticky, file = nil, line = nil, type: :warning) ⇒ Violation
Returns a new instance of Violation.
10 11 12 13 14 15 |
# File 'lib/danger/danger_core/messages/violation.rb', line 10 def initialize(, sticky, file = nil, line = nil, type: :warning) raise ArgumentError unless VALID_TYPES.include?(type) super(type: type, message: , file: file, line: line) self.sticky = sticky end |
Instance Attribute Details
#sticky ⇒ Object
Returns the value of attribute sticky.
8 9 10 |
# File 'lib/danger/danger_core/messages/violation.rb', line 8 def sticky @sticky end |
Instance Method Details
#<=>(other) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/danger/danger_core/messages/violation.rb', line 35 def <=>(other) types = VALID_TYPES + [:markdown] order = types.index(type) <=> types.index(other.type) return order unless order.zero? compare_by_file_and_line(other) end |
#==(other) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/danger/danger_core/messages/violation.rb', line 17 def ==(other) return false if other.nil? return false unless other.kind_of? self.class other. == && other.sticky == sticky && other.file == file && other.line == line end |
#hash ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/danger/danger_core/messages/violation.rb', line 27 def hash h = 1 h = h * 31 + .hash h = h * 13 + sticky.hash h = h * 17 + file.hash h * 17 + line.hash end |
#to_s ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/danger/danger_core/messages/violation.rb', line 43 def to_s extra = [] extra << "sticky: #{sticky}" extra << "file: #{file}" if file extra << "line: #{line}" if line extra << "type: #{type}" "Violation #{} { #{extra.join ', '} }" end |