Class: Umwelt::History::Trace
- Inherits:
-
Abstract::Interactor
- Object
- Abstract::Interactor
- Umwelt::History::Trace
- Defined in:
- lib/umwelt/history/trace.rb
Instance Method Summary collapse
- #call(history, phase_id) ⇒ Object
- #enqueue(phase) ⇒ Object
- #from_index(phase_id) ⇒ Object
-
#initialize ⇒ Trace
constructor
A new instance of Trace.
- #process(phase) ⇒ Object
- #to_index(phases) ⇒ Object
Methods inherited from Abstract::Interactor
Constructor Details
#initialize ⇒ Trace
Returns a new instance of Trace.
7 8 9 10 11 12 |
# File 'lib/umwelt/history/trace.rb', line 7 def initialize @queue = Queue.new # for phases @phases_index = {} @continuity = [] @timeline = {} end |
Instance Method Details
#call(history, phase_id) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/umwelt/history/trace.rb', line 14 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 |
#enqueue(phase) ⇒ Object
33 34 35 36 |
# File 'lib/umwelt/history/trace.rb', line 33 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 |
#from_index(phase_id) ⇒ Object
38 39 40 41 |
# File 'lib/umwelt/history/trace.rb', line 38 def from_index(phase_id) phase = @phases_index[phase_id] phase || error!("Phase with ID #{phase_id} not exist, but referenced") end |
#process(phase) ⇒ Object
28 29 30 31 |
# File 'lib/umwelt/history/trace.rb', line 28 def process(phase) @timeline[phase[:id]] = phase enqueue(phase) end |
#to_index(phases) ⇒ Object
43 44 45 46 47 |
# File 'lib/umwelt/history/trace.rb', line 43 def to_index(phases) phases.each do |phase| @phases_index[phase[:id]] = phase end end |