Class: Fiveruns::Dash::Trace

Inherits:
Object
  • Object
show all
Defined in:
lib/fiveruns/dash/trace.rb

Defined Under Namespace

Classes: Step

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Trace

Returns a new instance of Trace.



6
7
8
9
10
# File 'lib/fiveruns/dash/trace.rb', line 6

def initialize(context)
  @context = context
  @stack = []
  validate!
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/fiveruns/dash/trace.rb', line 5

def context
  @context
end

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/fiveruns/dash/trace.rb', line 5

def data
  @data
end

#stackObject (readonly)

Returns the value of attribute stack.



5
6
7
# File 'lib/fiveruns/dash/trace.rb', line 5

def stack
  @stack
end

Instance Method Details

#add_data(metric, contexts, value) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/fiveruns/dash/trace.rb', line 22

def add_data(metric, contexts, value)
  unless @stack.empty?
    @stack.last.metrics.push(
      metric.key.merge({:value => value, :contexts => contexts})
    )
  end
end

#step(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/fiveruns/dash/trace.rb', line 12

def step(&block)
  s = Step.new
  @stack.last.children << s if !@stack.empty?
  @stack << s
  result = yield
  last_step = @stack.pop
  @data = last_step if @stack.empty?
  result
end

#to_fjsonObject



30
31
32
33
34
# File 'lib/fiveruns/dash/trace.rb', line 30

def to_fjson
  { :context => context,
    :data => (@data || {})
  }.to_fjson
end