class Danger::MessageGroup
Attributes
file[R]
line[R]
Public Class Methods
new(file: nil, line: nil)
click to toggle source
# File lib/danger/danger_core/message_group.rb, line 5 def initialize(file: nil, line: nil) @file = file @line = line end
Public Instance Methods
<<(message)
click to toggle source
Adds a message to the group. @param message [Markdown, Violation] the message to add
# File lib/danger/danger_core/message_group.rb, line 29 def <<(message) # TODO: insertion sort return nil unless same_line?(message) inserted = false messages.each.with_index do |other, idx| if (message <=> other) == -1 inserted = true messages.insert(idx, message) break end end messages << message unless inserted messages end
markdowns()
click to toggle source
# File lib/danger/danger_core/message_group.rb, line 64 def markdowns messages.select { |x| x.type == :markdown } end
merge(other)
click to toggle source
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.
# 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 = (messages + other.messages).uniq end
messages()
click to toggle source
The list of messages in this group. This list will be sorted in decreasing order of severity (error, warning, message, markdown)
# File lib/danger/danger_core/message_group.rb, line 47 def messages @messages ||= [] end
same_line?(other)
click to toggle source
Returns whether this ‘MessageGroup` is for the same line of code as
`other`, taking which file they are in to account.
@param other [MessageGroup, Markdown
, Violation] @return [Boolean] whether this ‘MessageGroup` is for the same line of code
# File lib/danger/danger_core/message_group.rb, line 14 def same_line?(other) other.file == file && other.line == line end
stats()
click to toggle source
@return a hash of statistics. Currently only :warnings_count and :errors_count
# File lib/danger/danger_core/message_group.rb, line 55 def stats stats = { warnings_count: 0, errors_count: 0 } messages.each do |msg| stats[:warnings_count] += 1 if msg.type == :warning stats[:errors_count] += 1 if msg.type == :error end stats end