Class: Debci::Status
- Inherits:
-
Object
- Object
- Debci::Status
- Defined in:
- lib/debci/status.rb
Overview
This class represents one test execution.
Instance Attribute Summary collapse
-
#architecture ⇒ Object
Returns the value of attribute architecture.
-
#blame ⇒ Object
Returns the value of attribute blame.
-
#date ⇒ Object
Returns the value of attribute date.
-
#duration_human ⇒ Object
Returns the value of attribute duration_human.
-
#duration_seconds ⇒ Object
Returns the value of attribute duration_seconds.
-
#message ⇒ Object
Returns the value of attribute message.
-
#package ⇒ Object
Returns the value of attribute package.
-
#previous_status ⇒ Object
Returns the value of attribute previous_status.
-
#run_id ⇒ Object
Returns the value of attribute run_id.
-
#status ⇒ Object
Returns the value of attribute status.
-
#suite ⇒ Object
Returns the value of attribute suite.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.from_data(data, suite, architecture) ⇒ Object
Populates an object by reading from a data hash.
-
.from_file(file, suite, architecture) ⇒ Object
Constructs a new object by reading the JSON status
file.
Instance Method Summary collapse
-
#description ⇒ Object
A longer version of the headline.
-
#headline ⇒ Object
Returns a headline for this status object, to be used as a short description of the event it represents.
- #inspect ⇒ Object
-
#newsworthy? ⇒ Boolean
Returns
trueif this status object represents an important event, such as a package that used to pass started failing, of vice versa. -
#time ⇒ Object
Returns the amount of time since the date for this status object.
- #title ⇒ Object
Instance Attribute Details
#architecture ⇒ Object
Returns the value of attribute architecture
11 12 13 |
# File 'lib/debci/status.rb', line 11 def architecture @architecture end |
#blame ⇒ Object
Returns the value of attribute blame
10 11 12 |
# File 'lib/debci/status.rb', line 10 def blame @blame end |
#date ⇒ Object
Returns the value of attribute date
11 12 13 |
# File 'lib/debci/status.rb', line 11 def date @date end |
#duration_human ⇒ Object
Returns the value of attribute duration_human
11 12 13 |
# File 'lib/debci/status.rb', line 11 def duration_human @duration_human end |
#duration_seconds ⇒ Object
Returns the value of attribute duration_seconds
11 12 13 |
# File 'lib/debci/status.rb', line 11 def duration_seconds @duration_seconds end |
#message ⇒ Object
Returns the value of attribute message
11 12 13 |
# File 'lib/debci/status.rb', line 11 def @message end |
#package ⇒ Object
Returns the value of attribute package
11 12 13 |
# File 'lib/debci/status.rb', line 11 def package @package end |
#previous_status ⇒ Object
Returns the value of attribute previous_status
11 12 13 |
# File 'lib/debci/status.rb', line 11 def previous_status @previous_status end |
#run_id ⇒ Object
Returns the value of attribute run_id
11 12 13 |
# File 'lib/debci/status.rb', line 11 def run_id @run_id end |
#status ⇒ Object
Returns the value of attribute status
11 12 13 |
# File 'lib/debci/status.rb', line 11 def status @status end |
#suite ⇒ Object
Returns the value of attribute suite
11 12 13 |
# File 'lib/debci/status.rb', line 11 def suite @suite end |
#version ⇒ Object
Returns the value of attribute version
11 12 13 |
# File 'lib/debci/status.rb', line 11 def version @version end |
Class Method Details
.from_data(data, suite, architecture) ⇒ Object
Populates an object by reading from a data hash
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/debci/status.rb', line 88 def self.from_data(data, suite, architecture) status = Debci::Status.new status.suite = suite status.architecture = architecture status.run_id = data['run_id'] || data['date'] status.package = data['package'] status.version = data['version'] status.date = begin Time.parse(data.fetch('date', 'unknown') + ' UTC') rescue ArgumentError nil end status.status = data.fetch('status', :unknown).to_sym status.previous_status = data.fetch('previous_status', :unknown).to_sym status.blame = data['blame'] status.duration_seconds = begin Integer(data.fetch('duration_seconds', 0)) rescue ArgumentError nil end status.duration_human = data['duration_human'] status. = data['message'] status end |
.from_file(file, suite, architecture) ⇒ Object
Constructs a new object by reading the JSON status file.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/debci/status.rb', line 62 def self.from_file(file, suite, architecture) status = new status.suite = suite status.architecture = architecture unless File.exists?(file) status.status = :no_test_data return status end data = nil begin File.open(file, 'r') do |f| data = JSON.load(f) end rescue JSON::ParserError true # nothing really end return status unless data from_data(data, suite, architecture) end |
Instance Method Details
#description ⇒ Object
A longer version of the headline
38 39 40 |
# File 'lib/debci/status.rb', line 38 def description "The tests for #{package} #{status.upcase}ED on #{suite}/#{architecture} but have previously #{previous_status.upcase}ED." end |
#headline ⇒ Object
Returns a headline for this status object, to be used as a short description of the event it represents
33 34 35 |
# File 'lib/debci/status.rb', line 33 def headline "#{package} tests #{status.upcase}ED on #{suite}/#{architecture}" end |
#inspect ⇒ Object
117 118 119 |
# File 'lib/debci/status.rb', line 117 def inspect "<#{suite}/#{architecture} #{status}>" end |
#newsworthy? ⇒ Boolean
Returns true if this status object represents an important
event, such as a package that used to pass started failing, of vice versa.
15 16 17 18 19 20 |
# File 'lib/debci/status.rb', line 15 def newsworthy? [ [:fail, :pass], [:pass, :fail], ].include?([status, previous_status]) end |
#time ⇒ Object
Returns the amount of time since the date for this status object
51 52 53 54 55 56 57 58 59 |
# File 'lib/debci/status.rb', line 51 def time days = (Time.now - date)/86400 if days >= 1 || days <= -1 "#{days.floor} day(s) ago" else "#{Time.at(Time.now - date).gmtime.strftime('%H')} hour(s) ago" end end |
#title ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/debci/status.rb', line 22 def title { :pass => "Pass", :fail => "Fail", :tmpfail => "Temporary failure", :no_test_data => "No test data", }.fetch(status, "Unknown") end |