Class: Gitlab::Experiment::TestBehaviors::TrackedStructure

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/gitlab/experiment/test_behaviors/trackable.rb

Class Method Summary collapse

Class Method Details

.dependenciesObject



43
44
45
# File 'lib/gitlab/experiment/test_behaviors/trackable.rb', line 43

def dependencies
  @flat
end

.hierarchyObject



39
40
41
# File 'lib/gitlab/experiment/test_behaviors/trackable.rb', line 39

def hierarchy
  @tree[:children]
end

.popObject



58
59
60
61
62
63
64
# File 'lib/gitlab/experiment/test_behaviors/trackable.rb', line 58

def pop
  # dependency tracking
  @stack.pop

  # structure tracking
  @node = @last
end

.push(instance) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/gitlab/experiment/test_behaviors/trackable.rb', line 47

def push(instance)
  # dependency tracking
  @flat[instance.name] = ((@flat[instance.name] || []) + @stack.map(&:name)).uniq
  @stack.push(instance)

  # structure tracking
  @last = @node
  @node = @node[:children][instance.name] ||= { name: instance.name, count: 0, children: {} }
  @node[:count] += 1
end

.reset!Object



29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/experiment/test_behaviors/trackable.rb', line 29

def reset!
  # dependency tracking
  @flat = {}
  @stack = []

  # structure tracking
  @tree = { name: nil, count: 0, children: {} }
  @node = @tree
end