Class: CC::Formatters::SnapshotFormatter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/formatters/snapshot_formatter.rb

Overview

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.

Direct Known Subclasses

Sample

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Base

Returns a new instance of Base.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

Instance Attribute Details

#alert_constants_payloadObject (readonly)

Returns the value of attribute alert_constants_payload.



42
43
44
# File 'lib/cc/formatters/snapshot_formatter.rb', line 42

def alert_constants_payload
  @alert_constants_payload
end

#compare_urlObject (readonly)

Returns the value of attribute compare_url.



42
43
44
# File 'lib/cc/formatters/snapshot_formatter.rb', line 42

def compare_url
  @compare_url
end

#details_urlObject (readonly)

Returns the value of attribute details_url.



42
43
44
# File 'lib/cc/formatters/snapshot_formatter.rb', line 42

def details_url
  @details_url
end

#improved_constants_payloadObject (readonly)

Returns the value of attribute improved_constants_payload.



42
43
44
# File 'lib/cc/formatters/snapshot_formatter.rb', line 42

def improved_constants_payload
  @improved_constants_payload
end