Sha256: b156dc434e3a880957d2e7e9fc90716589328419e3f5c24d20c896559dfbb3b9

Contents?: true

Size: 1.87 KB

Versions: 12

Compression:

Stored size: 1.87 KB

Contents

# -*- coding: UTF-8 -*-

require 'active_record'
require 'build-tool/state_helper'

module BuildTool

    #
    # Provide method to add and retrieve entries from the history
    #
    module History

        # Represents a module event.
        #
        # A module event is updating, compiling etc. a module.
        class ModuleLog < ActiveRecord::Base

            include StateHelper

            # A module event belongs to a command
            belongs_to :command_log

            # A module event belongs to a module
            belongs_to :module, :foreign_key => :module, :primary_key => :name

            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

            # Call this if the command is finished. [:finished] will be set to Time.now,
            # [:state] to the given value and the object is saved.
            def finished( state )
                self.finished_at = Time.now
                self.state = state
                save
            end

            # Call this when the command is started. [:started] will be set to Time.now and
            # the object is saved.
            def started
                self.started_at = Time.now
                save!
            end

            # Make sure a finished command has one of the accepted finished states.
            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

            class << self

            end # class self

        end
    end
end # module BuildTool::History

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
build-tool-0.6.9 lib/build-tool/model/module_log.rb
build-tool-0.6.8 lib/build-tool/model/module_log.rb
build-tool-0.6.7 lib/build-tool/model/module_log.rb
build-tool-0.6.6 lib/build-tool/model/module_log.rb
build-tool-0.6.5 lib/build-tool/model/module_log.rb
build-tool-0.6.4 lib/build-tool/model/module_log.rb
build-tool-0.6.3 lib/build-tool/model/module_log.rb
build-tool-0.6.2 lib/build-tool/model/module_log.rb
build-tool-0.6.1 lib/build-tool/model/module_log.rb
build-tool-0.6.0 lib/build-tool/model/module_log.rb
build-tool-0.6.0.rc2 lib/build-tool/model/module_log.rb
build-tool-0.6.0.rc1 lib/build-tool/model/module_log.rb