Class: Travis::Surveillance::Job
- Inherits:
-
Object
- Object
- Travis::Surveillance::Job
- Defined in:
- lib/travis/surveillance/job.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- ATTRIBUTES =
[:build, :finished_at, :id, :number, :result, :started_at]
Instance Method Summary collapse
- #attributes=(attrs = {}) ⇒ Object
- #config ⇒ Object
- #duration ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(attrs = {}) ⇒ Job
constructor
A new instance of Job.
- #passed? ⇒ Boolean
- #running? ⇒ Boolean
- #runtime ⇒ Object
- #state ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Job
Returns a new instance of Job.
22 23 24 25 26 |
# File 'lib/travis/surveillance/job.rb', line 22 def initialize(attrs = {}) self.attributes = attrs populate end |
Instance Method Details
#attributes=(attrs = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/travis/surveillance/job.rb', line 28 def attributes=(attrs = {}) attrs.each do |key, value| next if value.nil? if key == 'config' config.attributes = value else send("#{key}=", (key[/_at$/] ? Time.parse(value) : value)) if ATTRIBUTES.include?(key.to_sym) end end end |
#config ⇒ Object
39 40 41 |
# File 'lib/travis/surveillance/job.rb', line 39 def config @config ||= Config.new end |
#duration ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/travis/surveillance/job.rb', line 43 def duration if started_at && finished_at finished_at - started_at elsif started_at Time.now - started_at else nil end end |
#failed? ⇒ Boolean
53 54 55 |
# File 'lib/travis/surveillance/job.rb', line 53 def failed? !result.nil? && !passed? end |
#passed? ⇒ Boolean
57 58 59 |
# File 'lib/travis/surveillance/job.rb', line 57 def passed? !result.nil? && result.zero? end |
#running? ⇒ Boolean
61 62 63 |
# File 'lib/travis/surveillance/job.rb', line 61 def running? result.nil? end |
#runtime ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/travis/surveillance/job.rb', line 65 def runtime return @runtime if @runtime @runtime = build.config.language.dup case @runtime when "ruby" @runtime << " #{config.rvm}" end @runtime end |
#state ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/travis/surveillance/job.rb', line 75 def state if running? 'running' elsif passed? 'passed' else 'failed' end end |