Class: BuildTool::History::ModuleLog

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
StateHelper
Defined in:
lib/build-tool/model/module_log.rb

Overview

Represents a module event.

A module event is updating, compiling etc. a module.

Constant Summary

Constants included from StateHelper

StateHelper::CANCELED_BY_USER, StateHelper::FINISHED_SUCCESSFUL, StateHelper::FINISHED_WITH_ERRORS, StateHelper::STARTED

Instance Method Summary collapse

Methods included from StateHelper

included, #state_char, #state_str

Instance Method Details

#before_updateObject

Make sure a finished command has one of the accepted finished states.



51
52
53
54
55
56
# File 'lib/build-tool/model/module_log.rb', line 51

def before_update
    super
    if !self.finished_at.nil?
        raise StandardError, "Wrong state for finished Command" if ! [ FINISHED_SUCCESSFUL, FINISHED_WITH_ERRORS, CANCELED_BY_USER ].include? self.state
    end
end

#durationObject



26
27
28
29
30
31
32
33
# File 'lib/build-tool/model/module_log.rb', line 26

def duration
    if self.finished_at
        dur = self.finished_at - self.started_at
        "%02d:%02d" % [ dur.to_i / 60, (dur% 60 ).to_i ]
    else
        "-----"
    end
end

#finished(state) ⇒ Object

Call this if the command is finished. [:finished] will be set to Time.now,

:state

to the given value and the object is saved.



37
38
39
40
41
# File 'lib/build-tool/model/module_log.rb', line 37

def finished( state )
    self.finished_at = Time.now
    self.state = state
    save
end

#startedObject

Call this when the command is started. [:started] will be set to Time.now and the object is saved.



45
46
47
48
# File 'lib/build-tool/model/module_log.rb', line 45

def started
    self.started_at = Time.now
    save!
end