Class: Danger::MessageGroup
- Inherits:
-
Object
- Object
- Danger::MessageGroup
- Defined in:
- lib/danger/danger_core/message_group.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
-
#<<(message) ⇒ Object
Adds a message to the group.
-
#initialize(file: nil, line: nil) ⇒ MessageGroup
constructor
A new instance of MessageGroup.
- #markdowns ⇒ Object
-
#merge(other) ⇒ Object
Merges two ‘MessageGroup`s that represent the same line of code In future, perhaps `MessageGroup` will be able to represent a group of messages for multiple lines.
-
#messages ⇒ Object
The list of messages in this group.
-
#same_line?(other) ⇒ Boolean
Returns whether this ‘MessageGroup` is for the same line of code as `other`, taking which file they are in to account.
-
#stats ⇒ Object
:errors_count.
Constructor Details
#initialize(file: nil, line: nil) ⇒ MessageGroup
Returns a new instance of MessageGroup.
5 6 7 8 |
# File 'lib/danger/danger_core/message_group.rb', line 5 def initialize(file: nil, line: nil) @file = file @line = line end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
51 52 53 |
# File 'lib/danger/danger_core/message_group.rb', line 51 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
51 52 53 |
# File 'lib/danger/danger_core/message_group.rb', line 51 def line @line end |
Instance Method Details
#<<(message) ⇒ Object
Adds a message to the group.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/danger/danger_core/message_group.rb', line 29 def <<() # TODO: insertion sort return nil unless same_line?() inserted = false .each.with_index do |other, idx| if ( <=> other) == -1 inserted = true .insert(idx, ) break end end << unless inserted end |
#markdowns ⇒ Object
64 65 66 |
# File 'lib/danger/danger_core/message_group.rb', line 64 def markdowns .select { |x| x.type == :markdown } end |
#merge(other) ⇒ Object
Merges two ‘MessageGroup`s that represent the same line of code In future, perhaps `MessageGroup` will be able to represent a group of messages for multiple lines.
21 22 23 24 25 |
# File 'lib/danger/danger_core/message_group.rb', line 21 def merge(other) raise ArgumentError, "Cannot merge with MessageGroup for a different line" unless same_line?(other) @messages = ( + other.).uniq end |
#messages ⇒ Object
The list of messages in this group. This list will be sorted in decreasing order of severity (error, warning, message, markdown)
47 48 49 |
# File 'lib/danger/danger_core/message_group.rb', line 47 def @messages ||= [] end |
#same_line?(other) ⇒ Boolean
Returns whether this ‘MessageGroup` is for the same line of code as
`other`, taking which file they are in to account.
14 15 16 |
# File 'lib/danger/danger_core/message_group.rb', line 14 def same_line?(other) other.file == file && other.line == line end |
#stats ⇒ Object
:errors_count
55 56 57 58 59 60 61 62 |
# File 'lib/danger/danger_core/message_group.rb', line 55 def stats stats = { warnings_count: 0, errors_count: 0 } .each do |msg| stats[:warnings_count] += 1 if msg.type == :warning stats[:errors_count] += 1 if msg.type == :error end stats end |