Module: Vanity::Metric::Definition

Defined in:
lib/vanity/metric/base.rb

Overview

These methods are available when defining a metric in a file loaded from the experiments/metrics directory.

For example:

$ cat experiments/metrics/yawn_sec
metric "Yawns/sec" do
  description "Most boring metric ever"
end

Since:

  • 1.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#playgroundObject (readonly)

Since:

  • 1.1.0



24
25
26
# File 'lib/vanity/metric/base.rb', line 24

def playground
  @playground
end

Instance Method Details

#metric(name, &block) ⇒ Object

Defines a new metric, using the class Vanity::Metric.

Since:

  • 1.1.0



27
28
29
30
31
32
# File 'lib/vanity/metric/base.rb', line 27

def metric(name, &block)
  fail "Metric #{@metric_id} already defined in playground" if playground.metrics[@metric_id]
  metric = Metric.new(playground, name.to_s, @metric_id)
  metric.instance_eval &block
  playground.metrics[@metric_id] = metric
end

#new_binding(playground, id) ⇒ Object

Since:

  • 1.1.0



34
35
36
37
# File 'lib/vanity/metric/base.rb', line 34

def new_binding(playground, id)
  @playground, @metric_id = playground, id
  binding
end