class CC::Formatters::SnapshotFormatter::Base
SnapshotFormatter::Base
takes the quality information from the payload and divides it between alerts and improvements.
The information in the payload must be a comparison in time between two quality reports, aka snapshot. This information is in the payload when the service receive a `receive_snapshot` and also when it receives a `receive_test`. In this latest case, the comparison is between today and seven days ago.
Attributes
alert_constants_payload[R]
compare_url[R]
details_url[R]
improved_constants_payload[R]
Public Class Methods
new(payload)
click to toggle source
# File lib/cc/formatters/snapshot_formatter.rb, line 44 def initialize(payload) new_constants = Array(payload["new_constants"]) changed_constants = Array(payload["changed_constants"]) alert_constants = new_constants.select(&new_constants_selector) alert_constants += changed_constants.select(&decreased_constants_selector) improved_constants = changed_constants.select(&improved_constants_selector) data = { "from" => { "commit_sha" => payload["previous_commit_sha"] }, "to" => { "commit_sha" => payload["commit_sha"] }, } @alert_constants_payload = data.merge("constants" => alert_constants) if alert_constants.any? @improved_constants_payload = data.merge("constants" => improved_constants) if improved_constants.any? end
Private Instance Methods
decreased_constants_selector()
click to toggle source
# File lib/cc/formatters/snapshot_formatter.rb, line 68 def decreased_constants_selector proc { |constant| from_rating(constant) > D && to_rating(constant) < C } end
from_rating(constant)
click to toggle source
# File lib/cc/formatters/snapshot_formatter.rb, line 80 def from_rating(constant) Rating.new(constant["from"]["rating"]) end
improved_constants_selector()
click to toggle source
# File lib/cc/formatters/snapshot_formatter.rb, line 72 def improved_constants_selector proc { |constant| from_rating(constant) < C && to_rating(constant) > from_rating(constant) } end
new_constants_selector()
click to toggle source
# File lib/cc/formatters/snapshot_formatter.rb, line 64 def new_constants_selector proc { |constant| to_rating(constant) < C } end
to_rating(constant)
click to toggle source
# File lib/cc/formatters/snapshot_formatter.rb, line 76 def to_rating(constant) Rating.new(constant["to"]["rating"]) end