Class: LittleGhost::Assembly::Trajectory
- Inherits:
-
Object
- Object
- LittleGhost::Assembly::Trajectory
- Includes:
- Enumerable
- Defined in:
- lib/little_ghost/assembly_execution.rb
Overview
Immutable queries over the steps returned by one assembly invocation.
Instance Attribute Summary collapse
-
#steps ⇒ Object
readonly
Immutable steps in execution order.
Instance Method Summary collapse
-
#attempts_for(id) ⇒ Object
Returns attempts belonging to one step.
-
#children(id) ⇒ Object
Returns steps whose parent is
id. -
#concurrent?(first_id, second_id) ⇒ Boolean
Indicates whether attempts from two steps overlapped in time.
-
#each(&block) ⇒ Object
Iterates through steps in execution order.
-
#initialize(steps) ⇒ Trajectory
constructor
Builds query indexes for
steps. -
#step(id) ⇒ Object
Finds one step by its stable ID.
-
#transitions ⇒ Object
Returns declared predecessor-to-step ID pairs.
Constructor Details
#initialize(steps) ⇒ Trajectory
Builds query indexes for steps.
50 51 52 53 54 |
# File 'lib/little_ghost/assembly_execution.rb', line 50 def initialize(steps) @steps = Array(steps).freeze @by_id = @steps.to_h { |step| [step.id, step] }.freeze freeze end |
Instance Attribute Details
#steps ⇒ Object (readonly)
Immutable steps in execution order.
47 48 49 |
# File 'lib/little_ghost/assembly_execution.rb', line 47 def steps @steps end |
Instance Method Details
#attempts_for(id) ⇒ Object
Returns attempts belonging to one step.
63 |
# File 'lib/little_ghost/assembly_execution.rb', line 63 def attempts_for(id) = step(id)&.attempts || [].freeze |
#children(id) ⇒ Object
Returns steps whose parent is id.
61 62 |
# File 'lib/little_ghost/assembly_execution.rb', line 61 def children(id) = steps.select { |item| item.parent_id == id.to_s }.freeze # Returns attempts belonging to one step. |
#concurrent?(first_id, second_id) ⇒ Boolean
Indicates whether attempts from two steps overlapped in time.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/little_ghost/assembly_execution.rb', line 73 def concurrent?(first_id, second_id) first = step(first_id) second = step(second_id) return false unless first && second first.attempts.any? do |left| second.attempts.any? do |right| left.started_at < right.finished_at && right.started_at < left.finished_at end end end |
#each(&block) ⇒ Object
Iterates through steps in execution order.
57 58 |
# File 'lib/little_ghost/assembly_execution.rb', line 57 def each(&block) = steps.each(&block) # Finds one step by its stable ID. |
#step(id) ⇒ Object
Finds one step by its stable ID.
59 60 |
# File 'lib/little_ghost/assembly_execution.rb', line 59 def step(id) = @by_id[id.to_s] # Returns steps whose parent is +id+. |
#transitions ⇒ Object
Returns declared predecessor-to-step ID pairs.
66 67 68 69 70 |
# File 'lib/little_ghost/assembly_execution.rb', line 66 def transitions steps.flat_map do |item| item.predecessor_ids.map { |predecessor| [predecessor, item.id].freeze } end.freeze end |