Sha256: 3ffd662caddd94281e2264e4e47c3fea7f9155f527173c4365b3ee8c71ca0eda
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true module Umwelt::History class Trace include Hanami::Interactor expose :continuity def initialize @queue = Queue.new # for phases @phases_index = {} @continuity = [] @timeline = {} end def call(history, phase_id) to_index(history.phases) @queue.push from_index(phase_id) loop do break if @queue.empty? process(@queue.pop) end @continuity = @timeline.values end def process(phase) @timeline[phase[:id]] = phase enqueue(phase) end def enqueue(phase) @queue.push from_index(phase.merge_id) unless phase.merge_id.nil? @queue.push from_index(phase.parent_id) unless phase.parent_id.nil? end def from_index(phase_id) phase = @phases_index[phase_id] phase || error!("Phase with ID #{phase_id} not exist, but referenced") end def to_index(phases) phases.each do |phase| @phases_index[phase[:id]] = phase end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
umwelt-0.1.1 | lib/umwelt/history/trace.rb |
umwelt-0.1.0 | lib/umwelt/history/trace.rb |