Class: Fiveruns::Dash::Trace
Defined Under Namespace
Classes: Step
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #add_data(metric, contexts, value) ⇒ Object
-
#initialize(context) ⇒ Trace
constructor
A new instance of Trace.
- #step(&block) ⇒ Object
- #to_fjson ⇒ Object
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
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/fiveruns/dash/trace.rb', line 5 def context @context end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/fiveruns/dash/trace.rb', line 5 def data @data end |
#stack ⇒ Object (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_fjson ⇒ Object
30 31 32 33 34 |
# File 'lib/fiveruns/dash/trace.rb', line 30 def to_fjson { :context => context, :data => (@data || {}) }.to_fjson end |