Class: Trailblazer::Developer::Trace::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/developer/trace/stack.rb

Overview

The stack is a linear one-dimensional array. Per traced task two Trace::Captured elements get pushed onto it (unless there’s an Exception).

The Stack object maintains the snapshots and the variable versions. It should probably be named “Trace” :D It is by design coupled to both Snapshot and Ctx::Versions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snapshots = [], variable_versions = Snapshot::Versions.new) ⇒ Stack

Returns a new instance of Stack.



11
12
13
14
# File 'lib/trailblazer/developer/trace/stack.rb', line 11

def initialize(snapshots = [], variable_versions = Snapshot::Versions.new)
  @snapshots          = snapshots
  @variable_versions  = variable_versions # DISCUSS: I dislike the coupling here to Stack, but introducting another object comprised of Stack and VariableVersions seems overkill.
end

Instance Attribute Details

#variable_versionsObject (readonly)

TODO: the accessor sucks. But I guess to_h is slower.



16
17
18
# File 'lib/trailblazer/developer/trace/stack.rb', line 16

def variable_versions
  @variable_versions
end

Instance Method Details

#add!(snapshot, new_variable_versions) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/trailblazer/developer/trace/stack.rb', line 18

def add!(snapshot, new_variable_versions)
  # variable_versions is mutated in the snapshooter, that's
  # why we don't have to re-set it here. I'm not a huge fan of mutating it
  # in a deeply nested scenario but everything else we played with added huge amounts
  # or runtime code.
  @variable_versions.add_changes!(new_variable_versions)

  @snapshots << snapshot
end

#to_aObject



28
29
30
# File 'lib/trailblazer/developer/trace/stack.rb', line 28

def to_a
  @snapshots
end