Sha256: c478a5a3f67112f3873755981e3f5c914ee96a53d9e48b7366c4ede96cfd5c8d

Contents?: true

Size: 1 KB

Versions: 15

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true
module Dynflow
  class ExecutionHistory
    include Algebrick::TypeCheck
    include Enumerable

    Event = Algebrick.type do
      fields! time:     Integer,
              name:     String,
              world_id: type { variants String, NilClass }
    end

    module Event
      def inspect
        ["#{Time.at(time).utc}: #{name}", world_id].compact.join(' @ ')
      end
    end

    attr_reader :events

    def initialize(events = [])
      @events = (events || []).each { |e| Type! e, Event }
    end

    def each(&block)
      @events.each(&block)
    end

    def add(name, world_id = nil)
      @events << Event[Time.now.to_i, name, world_id]
    end

    def to_hash
      @events.map(&:to_hash)
    end

    def inspect
      "ExecutionHistory: #{ @events.inspect }"
    end

    def self.new_from_hash(value)
      value ||= [] # for compatibility with tasks before the
      # introduction of execution history
      self.new(value.map { |hash| Event[hash] })
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
dynflow-1.8.2 lib/dynflow/execution_history.rb
dynflow-1.8.1 lib/dynflow/execution_history.rb
dynflow-1.8.0 lib/dynflow/execution_history.rb
dynflow-1.7.0 lib/dynflow/execution_history.rb
dynflow-1.6.11 lib/dynflow/execution_history.rb
dynflow-1.6.10 lib/dynflow/execution_history.rb
dynflow-1.6.8 lib/dynflow/execution_history.rb
dynflow-1.6.7 lib/dynflow/execution_history.rb
dynflow-1.6.6 lib/dynflow/execution_history.rb
dynflow-1.6.5 lib/dynflow/execution_history.rb
dynflow-1.6.4 lib/dynflow/execution_history.rb
dynflow-1.6.3 lib/dynflow/execution_history.rb
dynflow-1.6.2 lib/dynflow/execution_history.rb
dynflow-1.6.1 lib/dynflow/execution_history.rb
dynflow-1.5.0 lib/dynflow/execution_history.rb