Class: Danger::BaseMessage
- Inherits:
-
Object
- Object
- Danger::BaseMessage
- Defined in:
- lib/danger/danger_core/messages/base.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#line ⇒ Object
Returns the value of attribute line.
-
#message ⇒ Object
Returns the value of attribute message.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#cmp_nils(a, b) ⇒ Object
compares a and b based entirely on whether one or the other is nil arguments are in the same order as ‘a <=> b` nil is sorted earlier - so cmp_nils(nil, 1) => -1.
- #compare_by_file_and_line(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(type:, message:, file: nil, line: nil) ⇒ BaseMessage
constructor
A new instance of BaseMessage.
-
#inline? ⇒ Boolean
Returns true if is a file or line, false otherwise.
Constructor Details
#initialize(type:, message:, file: nil, line: nil) ⇒ BaseMessage
Returns a new instance of BaseMessage.
5 6 7 8 9 10 |
# File 'lib/danger/danger_core/messages/base.rb', line 5 def initialize(type:, message:, file: nil, line: nil) @type = type @message = @file = file @line = line end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
3 4 5 |
# File 'lib/danger/danger_core/messages/base.rb', line 3 def file @file end |
#line ⇒ Object
Returns the value of attribute line.
3 4 5 |
# File 'lib/danger/danger_core/messages/base.rb', line 3 def line @line end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'lib/danger/danger_core/messages/base.rb', line 3 def @message end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/danger/danger_core/messages/base.rb', line 3 def type @type end |
Instance Method Details
#cmp_nils(a, b) ⇒ Object
compares a and b based entirely on whether one or the other is nil arguments are in the same order as ‘a <=> b` nil is sorted earlier - so cmp_nils(nil, 1) => -1
If neither are nil, rather than returning ‘a <=> b` which would seem like the obvious shortcut, `nil` is returned. This allows us to distinguish between cmp_nils returning 0 for a comparison of filenames, which means “a comparison on the lines is meaningless - you cannot have a line number for a nil file - so they should be sorted the same”, and a <=> b returning 0, which means “the files are the same, so compare on the lines”
38 39 40 41 42 43 44 45 46 |
# File 'lib/danger/danger_core/messages/base.rb', line 38 def cmp_nils(a, b) if a.nil? && b.nil? 0 elsif a.nil? -1 elsif b.nil? 1 end end |
#compare_by_file_and_line(other) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/danger/danger_core/messages/base.rb', line 12 def compare_by_file_and_line(other) order = cmp_nils(file, other.file) return order unless order.nil? order = file <=> other.file return order unless order.zero? order = cmp_nils(line, other.line) return order unless order.nil? line <=> other.line end |
#eql?(other) ⇒ Boolean
48 49 50 |
# File 'lib/danger/danger_core/messages/base.rb', line 48 def eql?(other) return self == other end |
#inline? ⇒ Boolean
Returns true if is a file or line, false otherwise
53 54 55 |
# File 'lib/danger/danger_core/messages/base.rb', line 53 def inline? file || line end |