Class: BuildTool::History::CommandLog
- Inherits:
-
Object
- Object
- BuildTool::History::CommandLog
- Includes:
- StateHelper
- Defined in:
- lib/build-tool/history.rb
Overview
Represents a log entry for a command.
Constant Summary
Constants included from StateHelper
StateHelper::CANCELED_BY_USER, StateHelper::FINISHED_SUCCESSFUL, StateHelper::FINISHED_WITH_ERRORS, StateHelper::STARTED
Class Method Summary collapse
-
.last(count = 50) ⇒ Array
Get the last :count issued commands.
-
.last_by_module(modname, count = 3) ⇒ Object
Get the last :count command entries containing module :modname.
-
.most_recent(offset = nil) ⇒ Object
Loads the most recents entry from the database.
-
.older_than ⇒ Object
Get all commands older than :days.
Instance Method Summary collapse
- #before_destroy ⇒ Object
-
#before_update ⇒ Object
Sequel Hook.
- #duration ⇒ Object
-
#finished(state) ⇒ Object
Call this if the command is finished.
-
#started ⇒ Object
Call this if the command is started.
Methods included from StateHelper
Class Method Details
.last(count = 50) ⇒ Array
Get the last :count issued commands
110 111 112 |
# File 'lib/build-tool/history.rb', line 110 def last( count = 50 ) order(:id.desc).limit(count).all end |
.last_by_module(modname, count = 3) ⇒ Object
Get the last :count command entries containing module :modname.
115 116 117 |
# File 'lib/build-tool/history.rb', line 115 def last_by_module( modname, count = 3 ) where( 'id in ( select distinct command_log_id from module_logs where module = ? )', modname ).order( :id.desc ).first( count ); end |
.most_recent(offset = nil) ⇒ Object
Loads the most recents entry from the database
98 99 100 101 102 103 104 |
# File 'lib/build-tool/history.rb', line 98 def most_recent( offset = nil ) if offset.nil? return where( "id = (SELECT MAX(id) FROM #{table_name})" ).first else return order( :id.desc ).limit( 1, offset ).first end end |
.older_than ⇒ Object
Get all commands older than :days
120 121 122 |
# File 'lib/build-tool/history.rb', line 120 def older_than where( 'finished_at < ?', Date.today - 10 ) end |
Instance Method Details
#before_destroy ⇒ Object
89 90 91 92 |
# File 'lib/build-tool/history.rb', line 89 def before_destroy self.module_logs_dataset.delete super end |
#before_update ⇒ Object
Sequel Hook
Make sure a finished command has one of the accepted finished states.
82 83 84 85 86 87 |
# File 'lib/build-tool/history.rb', line 82 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 |
#duration ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/build-tool/history.rb', line 55 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.
66 67 68 69 70 |
# File 'lib/build-tool/history.rb', line 66 def finished( state ) self.finished_at = Time.now self.state = state save end |
#started ⇒ Object
Call this if the command is started. [:started] will be set to Time.now, [:state] to STARTED and the object is saved.
74 75 76 77 |
# File 'lib/build-tool/history.rb', line 74 def started self.started_at = Time.now save end |